summaryrefslogtreecommitdiff
path: root/src/engine/entities/Entity.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-02 01:07:55 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-02 01:07:55 -0700
commit1ec5a8d088f599d094f387abc6014f228607b605 (patch)
tree0d0e0271b6d5db354a56337c5de9df1a933e767b /src/engine/entities/Entity.ts
parenta333ce8845de4269d6a6f5523d2273da11fe271c (diff)
downloadthe-abstraction-engine-1ec5a8d088f599d094f387abc6014f228607b605.tar.gz
the-abstraction-engine-1ec5a8d088f599d094f387abc6014f228607b605.zip
add interactable component
Diffstat (limited to 'src/engine/entities/Entity.ts')
-rw-r--r--src/engine/entities/Entity.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/engine/entities/Entity.ts b/src/engine/entities/Entity.ts
index 2cc2ac3..d5a8e6e 100644
--- a/src/engine/entities/Entity.ts
+++ b/src/engine/entities/Entity.ts
@@ -7,14 +7,26 @@ export abstract class Entity {
public components: Map<string, Component>;
public name: string;
+ protected hooks: Map<string, { add: Function; remove: Function }>;
+
constructor(name: string, id: string = (Entity.Id++).toString()) {
this.name = name;
this.id = id;
this.components = new Map();
+ this.hooks = new Map();
}
public addComponent(component: Component) {
+ const hadBeforeSet = this.components.has(component.name);
this.components.set(component.name, component);
+ if (!hadBeforeSet) {
+ this.hooks.get(component.name)?.add();
+ }
+ }
+
+ public removeComponent(name: string) {
+ this.components.delete(name);
+ this.hooks.get(name)?.remove();
}
public getComponent<T extends Component>(name: string): T {