Module: FelECS::Components
- Defined in:
- lib/felecs.rb,
lib/felecs/component_manager.rb
Overview
Creates component managers and allows accessing them them under the Components namespace as Constants. You can use array methods directly on this class to access Component Managers.
To see how component managers are used please look at the ComponentManager documentation.
Class Method Summary collapse
-
.new(component_name, *attrs, **attrs_with_defaults) ⇒ ComponentManager
Creates a new component manager.
Class Method Details
.new(component_name, *attrs, **attrs_with_defaults) ⇒ ComponentManager
Creates a new component manager.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/felecs/component_manager.rb', line 20 def new(component_name, *attrs, **attrs_with_defaults) if FelECS::Components.const_defined?(component_name) raise(NameError.new, "Component Manager '#{component_name}' is already defined") end const_set(component_name, Class.new(FelECS::ComponentManager) {}) update_const_cache attrs.each do |attr| if FelECS::Components.const_get(component_name).method_defined?(attr.to_s) || FelECS::Components.const_get(component_name).method_defined?("#{attr}=") raise NameError, "The attribute name \"#{attr}\" is already a method" end FelECS::Components.const_get(component_name).attr_accessor attr end attrs_with_defaults.each do |attr, _default| attrs_with_defaults[attr] = _default.dup FelECS::Components.const_get(component_name).attr_reader attr FelECS::Components.const_get(component_name).define_method("#{attr}=") do |value| unless value.equal? send(attr) instance_variable_set("@#{attr}", value) attr_changed_trigger_systems(attr) end end end FelECS::Components.const_get(component_name).define_method(:set_defaults) do attrs_with_defaults.each do |attr, default| instance_variable_set("@#{attr}", default.dup) end end FelECS::Components.const_get(component_name) end |