summaryrefslogtreecommitdiff
path: root/src/entities/entity.js
blob: 33d10312fdea1fa2bf5e0b6d3c35346de7e9efa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
game.nextId = 0;

game.Entity = (id=game.nextId++) => {
  const components = {};

  const addComponent = (component) => {
    components[component.name] = component;
  }
  const removeComponent = (component) => {
    delete components[component.name];
  }
  const hasComponent = (component) => {
    components[component.name] !== undefined;
  }

  return {
    id,
    components,
    addComponent,
    removeComponent,
    hasComponent
  };
}