From 55f1db30e7a609cebd2fab27c55ece1da45be232 Mon Sep 17 00:00:00 2001 From: realtradam Date: Mon, 3 Jan 2022 07:34:38 -0500 Subject: . --- lib/felflame.rb | 15 +++---- lib/felflame/component_manager.rb | 46 +++++++++++----------- lib/felflame/entity_manager.rb | 34 +++++++--------- lib/felflame/order.rb | 6 +++ lib/felflame/scene_manager.rb | 4 +- lib/felflame/stage_manager.rb | 6 ++- lib/felflame/system_manager.rb | 83 +++++++++++++++++++-------------------- lib/felflame/version.rb | 2 +- 8 files changed, 100 insertions(+), 96 deletions(-) create mode 100644 lib/felflame/order.rb (limited to 'lib') diff --git a/lib/felflame.rb b/lib/felflame.rb index 54084bf..b7a386a 100644 --- a/lib/felflame.rb +++ b/lib/felflame.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'felflame/entity_manager' require_relative 'felflame/component_manager' require_relative 'felflame/system_manager' @@ -8,7 +10,7 @@ require_relative 'felflame/version' # The FelFlame namespace where all its functionality resides under. module FelFlame - class <] A hash, where all the keys are attributes linked to their respective values. + # @return [Hash] A hash, where all the keys are attributes storing their respective values. 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) @@ -294,8 +292,8 @@ module FelFlame # Export all data into a JSON String, which could then later be loaded or saved to a file # TODO: This function is not yet complete # @return [String] a JSON formatted String - #def to_json + # def to_json # # should return a json or hash of all data in this component - #end + # end end end diff --git a/lib/felflame/entity_manager.rb b/lib/felflame/entity_manager.rb index 2ae0849..ef70510 100644 --- a/lib/felflame/entity_manager.rb +++ b/lib/felflame/entity_manager.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + module FelFlame class Entities - # Creating a new Entity # @param components [Components] Can be any number of components, identical duplicates will be automatically purged however different components from the same component manager are allowed. # @return [Entity] @@ -16,9 +17,9 @@ module FelFlame @components ||= {} 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. + # 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. # @example - # @entity.component[@component_manager] # array notation + # @entity.component[@component_manager] # array notation(the standard) # @entity.component(@component_manager) # method notation # @param manager [ComponentManager] If you pass nil you can then use array notation to access the same value. # @return [Component] @@ -32,15 +33,15 @@ module FelFlame elsif components[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 - # Removes this Entity from the list and purges all references to this Entity from other Components, as well as its data. # @return [Boolean] +true+ def delete - components.each do |component_manager, component_array| + components.each do |_component_manager, component_array| component_array.reverse_each do |component| component.entities.delete(self) end @@ -88,9 +89,7 @@ module FelFlame check_systems component, :removal_triggers if component.entities.include? self component.entities.delete self components[component.class].delete component - if components[component.class].empty? - components.delete component.class - end + components.delete component.class if components[component.class].empty? end true end @@ -98,14 +97,14 @@ module FelFlame # Export all data into a JSON String which can then be saved into a file # TODO: This function is not yet complete # @return [String] A JSON formatted String - #def to_json() end + # def to_json() end - class <] Array of all Entities that exist # @!visibility private def _data @@ -158,7 +154,7 @@ module FelFlame # TODO: This function is not yet complete # @param json_string [String] A string that was exported originally using the {FelFlame::Entities#to_json to_json} function # @param opts [Keywords] What values(its {FelFlame::Entities#id ID} or the {FelFlame::ComponentManager#id component IDs}) should be overwritten TODO: this might change - #def from_json(json_string, **opts) end + # def from_json(json_string, **opts) end end end end diff --git a/lib/felflame/order.rb b/lib/felflame/order.rb new file mode 100644 index 0000000..0bed66b --- /dev/null +++ b/lib/felflame/order.rb @@ -0,0 +1,6 @@ +module FelFlame + module Order + def sort(*sortables) + end + end +end diff --git a/lib/felflame/scene_manager.rb b/lib/felflame/scene_manager.rb index 9ac7924..0024815 100644 --- a/lib/felflame/scene_manager.rb +++ b/lib/felflame/scene_manager.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module FelFlame class Scenes # Allows overwriting the storage of systems, such as for clearing. @@ -60,7 +62,7 @@ module FelFlame system.scenes.delete self end systems.clear - #FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self + # FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self true end end diff --git a/lib/felflame/stage_manager.rb b/lib/felflame/stage_manager.rb index 50dad5f..a192b67 100644 --- a/lib/felflame/stage_manager.rb +++ b/lib/felflame/stage_manager.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module FelFlame module Stage - class <