summaryrefslogtreecommitdiff
path: root/Homework/cs5410/bbiy/src/entities/entity.js
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
commit6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch)
treeed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs5410/bbiy/src/entities/entity.js
downloadmisc-undergrad-main.tar.gz
misc-undergrad-main.zip
Diffstat (limited to 'Homework/cs5410/bbiy/src/entities/entity.js')
-rw-r--r--Homework/cs5410/bbiy/src/entities/entity.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/Homework/cs5410/bbiy/src/entities/entity.js b/Homework/cs5410/bbiy/src/entities/entity.js
new file mode 100644
index 0000000..3da032c
--- /dev/null
+++ b/Homework/cs5410/bbiy/src/entities/entity.js
@@ -0,0 +1,23 @@
+game.nextId = 0;
+
+game.Entity = (id=game.nextId++) => {
+ const components = {};
+
+ const addComponent = (component) => {
+ components[component.name] = component;
+ };
+ const hasComponent = (componentName) => components[componentName] !== undefined;
+ const removeComponent = (componentName) => {
+ if (hasComponent(componentName)) {
+ delete components[componentName];
+ }
+ };
+
+ return {
+ id,
+ components,
+ addComponent,
+ removeComponent,
+ hasComponent
+ };
+} \ No newline at end of file