summaryrefslogtreecommitdiffhomepage
path: root/app/ECS/component_manager.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-05-14 05:48:50 -0400
committerrealtradam <[email protected]>2021-05-14 05:48:50 -0400
commit6a2996ceae968029be26ed7ebae8785dcfe877d2 (patch)
treef3d4d405f7e032fcabbb9711f75e266282d98295 /app/ECS/component_manager.rb
parent57bd7ec9da14b3e7e338184568a273ce602e1557 (diff)
downloadtypemon-code-6a2996ceae968029be26ed7ebae8785dcfe877d2.tar.gz
typemon-code-6a2996ceae968029be26ed7ebae8785dcfe877d2.zip
added ECS system
Diffstat (limited to 'app/ECS/component_manager.rb')
-rw-r--r--app/ECS/component_manager.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/ECS/component_manager.rb b/app/ECS/component_manager.rb
new file mode 100644
index 0000000..e64bc21
--- /dev/null
+++ b/app/ECS/component_manager.rb
@@ -0,0 +1,20 @@
+require_relative './base_component'
+Dir[File.join(__dir__, 'components', '*.rb')].sort.each { |file| require file }
+
+class ECS
+ class Components
+ class <<self
+ def entity_destroyed(entity_id)
+ constants.each do |component|
+ component.delete(entity_id) unless (component.id & ECS::Entity.signatures[entity_id]).zero?
+ end
+ end
+
+ def entity_created(entity_id)
+ constants.each do |component|
+ const_get(component.to_s).add(entity_id) unless (const_get(component.to_s).id & ECS::Entity.signatures[entity_id]).zero?
+ end
+ end
+ end
+ end
+end