assassin-bug/framework/ecs/entity.js

24 lines
606 B
JavaScript
Raw Normal View History

2022-11-26 01:22:02 +00:00
export class BaseEntity {
constructor() {
this.components = new Map();
this.id = 0;
}
addComponent(component) {
let comp = new component();
comp.id = component.id;
this.components.set(component.id, comp);
}
removeComponent(component) {
this.components.delete(component.id);
}
getComponentIDs() {
return [...this.components.keys()];
}
getComponent(component) {
return this.components.get(component.id);
}
getComponentByID(id) {
return this.components.get(id);
}
}