Extracted movement and turret into 'components' that entity get add to its self when defined

This commit is contained in:
2019-11-20 09:08:54 -06:00
parent 82db9dd14d
commit 2d70736753
8 changed files with 145 additions and 50 deletions

23
lib/component.rb Normal file
View File

@@ -0,0 +1,23 @@
class IMICRTS
class Component
@@components = {}
def self.get(name)
@@components.dig(name)
end
def self.inherited(klass)
name = klass.to_s.split("::").last.downcase.to_sym
if get(name)
raise "#{klass.inspect} is already defined!"
else
@@components[name] = klass
end
end
end
end
Dir.glob("#{IMICRTS::GAME_ROOT_PATH}/lib/components/**/*.rb").each do |component|
require_relative component
end