Skip to content

Commit dbb8cc2

Browse files
committed
WIP on example
1 parent c4a5db4 commit dbb8cc2

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/example.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** This iw WIP, please ignore **/
2+
import World from "./World.ts";
3+
import Entity from "./Entity.ts";
4+
import ComponentRegistry from "./ComponentRegistry.ts";
5+
import { Attacking, Body, Idle, Keyboard, PositionOnScreen, Walking } from "./fixtures.ts";
6+
7+
const reg = ComponentRegistry.getInstance();
8+
reg.registerComponent(Body);
9+
reg.registerComponent(PositionOnScreen);
10+
reg.registerComponent(Keyboard);
11+
12+
// reg.registerGroup("mutuallyExclusiveComponents", [Idle, Walking, Attacking], { mutuallyExclusive: true });
13+
14+
const world = new World();
15+
16+
const entity1 = world.createEntity("entity1");
17+
entity1.addComponent(Body, { width: 10, height: 10 });
18+
entity1.addComponent(PositionOnScreen, { x: 1, y: 2 });
19+
20+
const entity2 = world.createEntity("entity2");
21+
entity2.addComponent(Keyboard, { up: "a", down: "b", left: "c", right: "d", action_1: "e" });

src/fixtures.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
import Component from "./Component.ts";
22

3+
export class Idle extends Component<Record<string, never>> {
4+
constructor(public properties: Record<string, never>) {
5+
super(properties);
6+
}
7+
}
8+
9+
export class Walking extends Component<Record<string, never>> {
10+
constructor(public properties: Record<string, never>) {
11+
super(properties);
12+
}
13+
}
14+
15+
export class Attacking extends Component<Record<string, never>> {
16+
constructor(public properties: Record<string, never>) {
17+
super(properties);
18+
}
19+
}
20+
321
export class Renderable extends Component<Record<string, never>> {
422
constructor(public properties: Record<string, never>) {
523
super(properties);

0 commit comments

Comments
 (0)