Skip to content

Commit fd0c85f

Browse files
committed
Refactored Components
WIP: adding systems for different actions
1 parent 76084c2 commit fd0c85f

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

packages/ecs/src/Component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class Component {
1414
init(properties: NonNullable<object>) {
1515
this.properties = properties;
1616
}
17+
18+
// Use this when saving the state.
19+
serialize(): NonNullable<object> {
20+
throw new Error(`You need to implement this for ${this.constructor.name}`);
21+
}
1722
}
1823

19-
export default Component;
24+
export default Component;

packages/ecs/src/Entity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export default class Entity {
6666
}
6767

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

packages/renderer/src/canvas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function dot(ctx: CanvasRenderingContext2D, x: number, y: number, fillCol
127127
ctx.restore();
128128
}
129129

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

0 commit comments

Comments
 (0)