From 03832564403a4c91e18bfa4d3809464878ddd4c7 Mon Sep 17 00:00:00 2001 From: Ruggero Visintin Date: Tue, 5 Dec 2023 00:57:57 +0100 Subject: [PATCH] refactor(rendering): check primitive type --- src/renderer/RenderCommand.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/renderer/RenderCommand.ts b/src/renderer/RenderCommand.ts index 2963ab6f..445bf029 100644 --- a/src/renderer/RenderCommand.ts +++ b/src/renderer/RenderCommand.ts @@ -13,9 +13,19 @@ export interface RenderCommand { execute(ctx: CanvasRenderingContext2D, device: CanvasDevice): void; } +/** + * Draws a primitive (Rectangle) + */ export class DrawPrimitiveCommand implements RenderCommand { public readonly renderCommandID: RenderCommandID = RenderCommandID.RC_DrawPrimitive; + /** + * @param primitiveType - the type of the Primitive + * @param position - the position of the Primitive (x, y) + * @param size - the size of the Primitive (width, height) + * @param fill - if the Primitive should be filled. Default is true + * @param color - the color of the primitive. Default is #d16cd8 + */ constructor( public readonly primitiveType: PrimitiveType, public readonly position: [number, number], @@ -25,7 +35,8 @@ export class DrawPrimitiveCommand implements RenderCommand { ) { } public execute(ctx: CanvasRenderingContext2D, device: CanvasDevice): void { - device.drawRect(ctx, this.position[0], this.position[1], this.size[0], this.size[1]); + this.primitiveType === PrimitiveType.Rectangle + && device.drawRect(ctx, this.position[0], this.position[1], this.size[0], this.size[1]); if (this.fill) { device.fill(ctx, this.color);