Component Managers are what is used to create individual components which can be attached to entities. When a Component is created from a Component Manager that has accessors given to it, you can set or get the values of those accessors using standard ruby message sending (e.g @component.var = 5), or by using the #to_h and #update_attrs methods instead.
# File 'lib/felflame/component_manager.rb', line 132
-
-definitialize(**attrs)
- # Prepare the object
-# (this is a function created with metaprogramming
-# in FelFlame::Components)
-set_defaults
-
- # Fill params
-attrs.eachdo|key,value|
- send"#{key}=",value
- end
-
- # Save Component
-self.class.pushself
-end
Stores references to systems that should be triggered when this component is added to an enitity. Do not edit this array as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-180
-181
-182
-
-
-
# File 'lib/felflame/component_manager.rb', line 180
-
-defaddition_triggers
- @addition_triggers||=[]
-end
Stores references to systems that should be triggered when an attribute from this component changed. Do not edit this hash as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Hash<Symbol, System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-196
-197
-198
-
-
-
# File 'lib/felflame/component_manager.rb', line 196
-
-defattr_triggers
- @attr_triggers||={}
-end
-
-
-
-
-
-
-
-
-
-
- .removal_triggers ⇒ Array<System>
-
-
-
-
-
-
-
-
-
Stores references to systems that should be triggered when this component is removed from an enitity. Do not edit this array as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-188
-189
-190
-
-
-
# File 'lib/felflame/component_manager.rb', line 188
-
-defremoval_triggers
- @removal_triggers||=[]
-end
Stores references to systems that should be triggered when a component from this manager is added. Do not edit this array as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-109
-110
-111
-
-
-
# File 'lib/felflame/component_manager.rb', line 109
-
-defaddition_triggers
- @addition_triggers||=[]
-end
Stores references to systems that should be triggered when an attribute from this manager is changed. Do not edit this hash as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Hash<Symbol, Array<System>>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-125
-126
-127
-
-
-
# File 'lib/felflame/component_manager.rb', line 125
-
-defattr_triggers
- @attr_triggers||={}
-end
-
-
-
-
-
-
-
-
-
-
- #removal_triggers ⇒ Array<System>
-
-
-
-
-
-
-
-
-
Stores references to systems that should be triggered when a component from this manager is removed. Do not edit this array as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-117
-118
-119
-
-
-
# File 'lib/felflame/component_manager.rb', line 117
-
-defremoval_triggers
- @removal_triggers||=[]
-end
-
-
-
-
-
-
-
-
-
-
Instance Method Details
-
-
-
-
-
- #delete ⇒ Boolean
-
-
-
-
-
-
-
-
-
Removes this component from the list and purges all references to this Component from other Entities, as well as its data.
# File 'lib/felflame/component_manager.rb', line 247
-
-defdelete
- addition_triggers.eachdo|system|
- system.clear_triggerscomponent_or_manager:self
- end
- entities.reverse_eachdo|entity|
- entity.removeself
- end
- self.class._data.deleteself
- instance_variables.eachdo|var|
- instance_variable_set(var,nil)
- end
- true
-end
-
-
-
-
-
-
-
-
- #entities ⇒ Array<Component>
-
-
-
-
-
-
-
-
-
Entities that have this component
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<Component>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-209
-210
-211
-
-
-
# File 'lib/felflame/component_manager.rb', line 209
-
-defentities
- @entities||=[]
-end
-
-
-
-
-
-
-
-
- #entity ⇒ Component
-
-
-
-
-
-
-
-
-
A single entity. Use this if you expect the component to only belong to one entity and you want to access it.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Component)
-
-
-
-
-
-
-
-
-
-
-
-
-
-215
-216
-217
-218
-219
-220
-221
-222
-
-
-
# File 'lib/felflame/component_manager.rb', line 215
-
-defentity
- ifentities.empty?
- Warning.warn("This component belongs to NO entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
- elsifentities.length>1
- Warning.warn("This component belongs to MANY entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
- end
- entities.first
-end
-
-
-
-
-
-
-
-
- #to_h ⇒ Hash<Symbol, Value>
-
-
-
-
-
-
-
-
-
Returns A hash, where all the keys are attributes storing their respective values.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Hash<Symbol, Value>)
-
-
-
- —
-
-
A hash, where all the keys are attributes storing their respective values.
-
-
-
-
-
-
-
-
-
-
-
-
-262
-263
-264
-265
-266
-267
-268
-
-
-
# File 'lib/felflame/component_manager.rb', line 262
-
-defto_h
- return_hash=instance_variables.each_with_object({})do|key,final|
- final[key.to_s.delete_prefix('@').to_sym]=instance_variable_get(key)
- end
- return_hash.delete(:attr_triggers)
- return_hash
-end
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.
# Here color is set to default to red
-# while max and current are nil until set.
-# When you make a new component using this component manager
-# these are the values and accessors it will have.
-FelFlame::Component.new('Health',:max,:current,color:'red')
-
-
-
Parameters:
-
-
-
-
- component_name
-
-
- (String)
-
-
-
- —
-
-
Name of your new component manager. Must be stylized in the format of constants in Ruby
-
-
-
-
-
-
- attrs
-
-
- (:Symbols)
-
-
-
- —
-
-
New components made with this manager will include these symbols as accessors, the values of these accessors will default to nil
A hash that uses component manager constant names as keys, and where the values of those keys are arrays that contain the the components attached to this entity.
Can be any number of components, identical duplicates will be automatically purged however different components from the same component manager are allowed.
-
-
-
-
-
-
-
-
-
-
-
-
-
-8
-9
-10
-11
-12
-
-
-
# File 'lib/felflame/entity_manager.rb', line 8
-
-definitialize(*components)
- # Add each component
-add(*components)
- self.class._data.pushself
-end
A single component from a component manager. Use this if you expect the component to only belong to one entity and you want to access it. Access the component using either parameter notation or array notation. Array notation is conventional for better readablility.
# File 'lib/felflame/entity_manager.rb', line 26
-
-defcomponent(manager=nil)
- ifmanager.nil?
- FelFlame::Entities.component_redirect.entity=self
- FelFlame::Entities.component_redirect
- else
- ifcomponents[manager].nil?
- raise"This entity(#{self}) doesnt have any components of this type: #{manager}"
- elsifcomponents[manager].length>1
- Warning.warn("This entity has MANY of this component but you called the method that is intended for having a single of this component type.\nYou may have a bug in your logic.")
- end
-
- components[manager].first
- end
-end
A hash that uses component manager constant names as keys, and where the values of those keys are arrays that contain the the components attached to this entity.
Component Managers are what is used to create individual components which can be attached to entities. When a Component is created from a Component Manager that has accessors given to it, you can set or get the values of those accessors using standard ruby message sending (e.g @component.var = 5), or by using the #attrs and #update_attrs methods instead.
# File 'component_manager.rb', line 104
-
-definitialize(**attrs)
- # Prepare the object
-# (this is a function created with metaprogramming
-# in FelFlame::Components
-set_defaults
-
- # Generate ID
-new_id=self.class.data.find_index{|i|i.nil?}
- new_id=self.class.data.sizeifnew_id.nil?
- @id=new_id
-
- # Fill params
-attrs.eachdo|key,value|
- send"#{key}=",value
- end
-
- # Save Component
-self.class.data[new_id]=self
-end
Stores references to systems that should be triggered when this component is added to an enitity. Do not edit this array as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-136
-137
-138
-
-
-
# File 'component_manager.rb', line 136
-
-defaddition_triggers
- @addition_triggers||=[]
-end
Stores references to systems that should be triggered when an attribute from this component changed. Do not edit this hash as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Hash<Symbol, System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-152
-153
-154
-
-
-
# File 'component_manager.rb', line 152
-
-defattr_triggers
- @attr_triggers||={}
-end
-
-
-
-
-
-
-
-
-
-
- .removal_triggers ⇒ Array<System>
-
-
-
-
-
-
-
-
-
Stores references to systems that should be triggered when this component is removed from an enitity. Do not edit this array as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-144
-145
-146
-
-
-
# File 'component_manager.rb', line 144
-
-defremoval_triggers
- @removal_triggers||=[]
-end
Stores references to systems that should be triggered when a component from this manager is added. Do not edit this array as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-81
-82
-83
-
-
-
# File 'component_manager.rb', line 81
-
-defaddition_triggers
- @addition_triggers||=[]
-end
Stores references to systems that should be triggered when an attribute from this manager is changed. Do not edit this hash as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Hash<Symbol, Array<System>>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-97
-98
-99
-
-
-
# File 'component_manager.rb', line 97
-
-defattr_triggers
- @attr_triggers||={}
-end
-
-
-
-
-
-
-
-
-
-
- #id ⇒ Integer
-
-
-
-
-
-
-
-
-
Holds the unique ID of a component. The ID is only unique within the scope of the component manager it was created from.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Integer)
-
-
-
-
-
-
-
-
-
-
-
-
-
-63
-64
-65
-
-
-
# File 'component_manager.rb', line 63
-
-defid
- @id
-end
-
-
-
-
-
-
-
-
-
-
- #removal_triggers ⇒ Array<System>
-
-
-
-
-
-
-
-
-
Stores references to systems that should be triggered when a component from this manager is removed. Do not edit this array as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<System>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-89
-90
-91
-
-
-
# File 'component_manager.rb', line 89
-
-defremoval_triggers
- @removal_triggers||=[]
-end
-
-
-
-
-
-
-
-
-
-
Class Method Details
-
-
-
-
-
- .[](component_id) ⇒ Component
-
-
-
-
-
-
-
-
-
Gets a Component from the given unique ID. Usage is simular to how an Array lookup works.
-
-
-
-
-
-
-
-
Examples:
-
-
-
# this gets the 'Health' Component with ID 7
-FelFlame::Components::Health[7]
-
-
-
Parameters:
-
-
-
-
- component_id
-
-
- (Integer)
-
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Component)
-
-
-
- —
-
-
Returns the Component that uses the given unique ID, nil if there is no Component associated with the given ID
-
-
-
-
-
-
-
-
-
-
-
-
-169
-170
-171
-
-
-
# File 'component_manager.rb', line 169
-
-def[](component_id)
- data[component_id]
-end
-
-
-
-
-
-
-
-
- .each(&block) ⇒ Enumerator
-
-
-
-
-
-
-
-
-
Iterates over all components within the component manager. Special Enumerable methods like map or each_with_index are not implemented
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Enumerator)
-
-
-
-
-
-
-
-
-
-
-
-
-
-176
-177
-178
-
-
-
# File 'component_manager.rb', line 176
-
-defeach(&block)
- data.compact.each(&block)
-end
# File 'component_manager.rb', line 215
-
-defdelete
- addition_triggers.eachdo|system|
- system.clear_triggerscomponent_or_manager:self
- end
- # This needs to be cloned because indices get deleted as
-# the remove command is called, breaking the loop if it
-# wasn't referencing a clone(will get Nil errors)
-iter=entities.map(&:clone)
- iter.eachdo|entity_id|
- FelFlame::Entities[entity_id].removeself#unless FelFlame::Entities[entity_id].nil?
-end
- self.class.data[id]=nil
- instance_variables.eachdo|var|
- instance_variable_set(var,nil)
- end
- true
-end
-
-
-
-
-
-
-
-
- #entities ⇒ Array<Integer>
-
-
-
-
-
-
-
-
-
A list of entity ids that are linked to the component
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<Integer>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-189
-190
-191
-
-
-
# File 'component_manager.rb', line 189
-
-defentities
- @entities||=[]
-end
Sets the priority of all items passed into this method according to the order they were passed.
-
-
-
-
-
-
-
-
-
-
-
-
Class Method Details
-
-
-
-
-
- .sort(*sortables) ⇒ Boolean
-
-
-
-
-
-
-
-
-
Sets the priority of all items passed into this method according to the order they were passed. If an array is one of the elements then it will give all of those elements in the array the same priority.
Creates and manages Scenes. Scenes are collections of Systems, and execute all the Systems when called upon. Any scenes you create are accessable under the Scenes namespace as Constants.
Stores Scenes you add to it which you want to execute on each frame. When called upon will execute all Systems in the Scenes in the Stage and will execute them according to their priority order.
Creates and manages Systems. Systems are the logic of the game and do not contain any data within them. Any systems you create are accessable under the Systems namespace as Constants. You can use array methods directly on this class to access Systems.
Stores references to systems that should be triggered when an attribute from this manager is changed Do not edit this hash as it is managed by FelFlame automatically.
Stores references to components or their managers that trigger this component when a component or component from that manager is removed from an entity.
Add a component or component manager so that it triggers this system when the component or a component from the component manager is added to an entity.
Add a component or component manager so that it triggers this system when the component or a component from the component manager is removed from an entity.
Creates a new System which can be accessed as a constant under the namespace FelFlame::Systems. The name given is what constant the system is assigned to
-
-
-
-
-
-
-
-
Examples:
-
-
-
FelFlame::Systems.new('PassiveHeal',priority:-2)do
- FelFlame::Components::Health.eachdo|component|
- component.hp+=5
- end
-end
-# Give it a low priority so other systems such as a
-# Poison system would kill the player first
-
-
-
Parameters:
-
-
-
-
- name
-
-
- (String)
-
-
-
- —
-
-
The name this system will use. Needs to to be in the Ruby Constant format.
Stores references to components or their managers that trigger this component when a component or component from that manager is added to an entity. Do not edit this hash as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<Component>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-35
-36
-37
-
-
-
# File 'lib/felflame/system_manager.rb', line 35
-
-defaddition_triggers
- @addition_triggers||=[]
-end
Stores references to systems that should be triggered when an attribute from this manager is changed Do not edit this hash as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Hash<Symbol, Array<Symbol>>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-52
-53
-54
-
-
-
# File 'lib/felflame/system_manager.rb', line 52
-
-defattr_triggers
- @attr_triggers||={}
-end
-
-
-
-
-
-
-
-
-
-
- #priority ⇒ Object
-
-
-
-
-
-
-
-
-
How early this System should be executed in a list of Systems
-
-
-
-
-
-
-
-
-
-
-
-
-
-6
-7
-8
-
-
-
# File 'lib/felflame/system_manager.rb', line 6
-
-defpriority
- @priority
-end
Stores references to components or their managers that trigger this component when a component or component from that manager is removed from an entity. Do not edit this hash as it is managed by FelFlame automatically.
-
-
-
-
-
-
-
Returns:
-
-
-
-
-
- (Array<Component>)
-
-
-
-
-
-
-
-
-
-
-
-
-
-44
-45
-46
-
-
-
# File 'lib/felflame/system_manager.rb', line 44
-
-defremoval_triggers
- @removal_triggers||=[]
-end
-
-
-
-
-
-
-
-
-
-
- #scenes ⇒ Object
-
-
-
-
-
-
-
-
-
-
-
-19
-20
-21
-
-
-
# File 'lib/felflame/system_manager.rb', line 19
-
-defscenes
- @scenes||=[]
-end
-
-
-
-
-
-
-
-
-
-
Class Method Details
-
-
-
-
-
- .const_cache ⇒ Object
-
-
-
-
-
-
-
-
-
Stores the systems in Components. This is needed because calling `FelFlame::Components.constants` will not let you iterate over the value of the constants but will instead give you an array of symbols. This caches the convertion of those symbols to the actual value of the constants
-
-
-
-
-
-
-
-
-
-
-
-
-
-63
-64
-65
-
-
-
# File 'lib/felflame/system_manager.rb', line 63
-
-defconst_cache
- @const_cache||update_const_cache
-end
-
-
-
-
-
-
-
-
-
Instance Method Details
-
-
-
-
-
- #call ⇒ Object
-
-
-
-
-
-
-
-
-
Manually execute the system a single time
-
-
-
-
-
-
-
-
-
-
-
-
-
-124
-125
-126
-
-
-
# File 'lib/felflame/system_manager.rb', line 124
-
-defcall
- @block.call
-end
Removes triggers from this system. This function is fairly flexible so it can accept a few different inputs For addition and removal triggers, you can optionally pass in a component, or a manager to clear specifically the relevant triggers for that one component or manager. If you do not pass a component or manager then it will clear triggers for all components and managers. For attr_triggers
-
-
-
-
-
-
-
-
Examples:
-
-
-
# To clear all triggers that execute this system when a component is added:
-FelFlame::Systems::ExampleSystem.clear_triggers:addition_triggers
-# Same as above but for when a component is removed instead
-FelFlame::Systems::ExampleSystem.clear_triggers:removal_triggers
-# Same as above but for when a component has a certain attribute changed
-FelFlame::Systems::ExampleSystem.clear_triggers:attr_triggers
-
-# Clear a trigger from a specific component
-FelFlame::Systems::ExampleSystem.clear_triggers:addition_triggers,FelFlame::Component::ExampleComponent[0]
-# Clear a trigger from a specific component manager
-FelFlame::Systems::ExampleSystem.clear_triggers:addition_triggers,FelFlame::Component::ExampleComponent
-
-# Clear the trigger that executes a system when the ':example_attr' is changes
-FelFlame::Systems::ExampleSystem.clear_triggers:attr_triggers,:example_attr
-
-
-
Parameters:
-
-
-
-
- trigger_types
-
-
- (:Symbols)
-
-
-
- —
-
-
One or more of the following trigger types: :addition_triggers, :removal_triggers, or :attr_triggers. If attr_triggers is used then you may pass attributes you wish to be cleared as symbols in this parameter as well
-
-
-
-
-
-
- component_or_manager
-
-
- (Component or ComponentManager)
-
-
- (defaults to: nil)
-
-
- —
-
-
The object to clear triggers from. Use Nil to clear triggers from all components associated with this system.
Add a component or component manager so that it triggers this system when the component or a component from the component manager is added to an entity
Add a component or component manager so that it triggers this system when the component or a component from the component manager is removed from an entity