From 5ef652300e71b572ca58b061610d606840ce19a9 Mon Sep 17 00:00:00 2001 From: _Tradam Date: Thu, 30 Dec 2021 07:33:12 -0500 Subject: Major 4.0 update (#12) Check the changelog --- lib/felflame/component_manager.rb | 128 ++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 62 deletions(-) (limited to 'lib/felflame/component_manager.rb') diff --git a/lib/felflame/component_manager.rb b/lib/felflame/component_manager.rb index 43932d2..ca5be89 100644 --- a/lib/felflame/component_manager.rb +++ b/lib/felflame/component_manager.rb @@ -1,8 +1,7 @@ -class FelFlame - class Components +module FelFlame + module Components @component_map = [] class < 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 + # Update attribute values using a hash or keywords. # @return [Hash] Hash of updated attributes def update_attrs(**opts) @@ -206,25 +216,19 @@ class FelFlame systems_to_execute |= attr_triggers[attr] unless attr_triggers[attr].nil? - systems_to_execute.sort_by(&:priority).reverse.each(&:call) + systems_to_execute.sort_by(&:priority).reverse_each(&:call) true end - - # Removes this component from the list and purges all references to this Component from other Entities, as well as its {id ID} and data. + # Removes this component from the list and purges all references to this Component from other Entities, as well as its data. # @return [Boolean] +true+. def delete addition_triggers.each do |system| system.clear_triggers component_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.each do |entity| - #FelFlame::Entities[entity_id].remove self #unless FelFlame::Entities[entity_id].nil? + entities.reverse_each do |entity| entity.remove self end - self.class.data[id] = nil + self.class._data.delete self instance_variables.each do |var| instance_variable_set(var, nil) end @@ -232,7 +236,7 @@ class FelFlame end # @return [Hash] A hash, where all the keys are attributes linked to their respective values. - def attrs + def to_h return_hash = instance_variables.each_with_object({}) do |key, final| final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key) end -- cgit v1.2.3