Skip to content

Commit

Permalink
Refactored Components
Browse files Browse the repository at this point in the history
WIP: adding systems for different actions
  • Loading branch information
serbanghita committed Jan 30, 2025
1 parent 76084c2 commit fd0c85f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/ecs/src/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class Component {
init(properties: NonNullable<object>) {
this.properties = properties;
}

// Use this when saving the state.
serialize(): NonNullable<object> {
throw new Error(`You need to implement this for ${this.constructor.name}`);
}
}

export default Component;
export default Component;
3 changes: 3 additions & 0 deletions packages/ecs/src/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export default class Entity {
}

public hasComponent(declaration: typeof Component): boolean {
if (typeof declaration.prototype.bitmask === "undefined") {
throw new Error(`Please register the component ${declaration.name} in the ComponentRegistry.`);
}
return hasBit(this.componentsBitmask, declaration.prototype.bitmask);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/src/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function dot(ctx: CanvasRenderingContext2D, x: number, y: number, fillCol
ctx.restore();
}

export function rectangle(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, strokeColor: string = "black", fillColor?: string): void {
export function rectangle(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, strokeColor: string = "rgb(0,0,0)", fillColor?: string): void {
//ctx.save();
ctx.beginPath();
ctx.lineWidth = 1;
Expand Down

0 comments on commit fd0c85f

Please sign in to comment.