summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/felecs.rb (renamed from lib/felflame.rb)58
-rw-r--r--lib/felecs/component_manager.rb (renamed from lib/felflame/component_manager.rb)42
-rw-r--r--lib/felecs/entity_manager.rb (renamed from lib/felflame/entity_manager.rb)12
-rw-r--r--lib/felecs/order.rb (renamed from lib/felflame/order.rb)2
-rw-r--r--lib/felecs/scene_manager.rb (renamed from lib/felflame/scene_manager.rb)8
-rw-r--r--lib/felecs/stage_manager.rb (renamed from lib/felflame/stage_manager.rb)4
-rw-r--r--lib/felecs/system_manager.rb (renamed from lib/felflame/system_manager.rb)74
-rw-r--r--lib/felecs/version.rb (renamed from lib/felflame/version.rb)4
8 files changed, 102 insertions, 102 deletions
diff --git a/lib/felflame.rb b/lib/felecs.rb
index 21a6eaf..e00c9d2 100644
--- a/lib/felflame.rb
+++ b/lib/felecs.rb
@@ -1,22 +1,22 @@
# frozen_string_literal: true
-require_relative 'felflame/entity_manager'
-require_relative 'felflame/component_manager'
-require_relative 'felflame/system_manager'
-require_relative 'felflame/scene_manager'
-require_relative 'felflame/stage_manager'
-require_relative 'felflame/order'
+require_relative 'felecs/entity_manager'
+require_relative 'felecs/component_manager'
+require_relative 'felecs/system_manager'
+require_relative 'felecs/scene_manager'
+require_relative 'felecs/stage_manager'
+require_relative 'felecs/order'
-require_relative 'felflame/version'
+require_relative 'felecs/version'
-# The FelFlame namespace where all its functionality resides under.
-module FelFlame
+# The FelECS namespace where all its functionality resides under.
+module FelECS
class << self
# :nocov:
- # An alias for {FelFlame::Stage.call}. It executes a single frame in the game.
+ # An alias for {FelECS::Stage.call}. It executes a single frame in the game.
def call
- FelFlame::Stage.call
+ FelECS::Stage.call
end
# :nocov:
end
@@ -25,17 +25,17 @@ module FelFlame
# You can use array methods directly on this class to access Entities.
class Entities; end
- # Creates component managers and allows accessing them them under the {FelFlame::Components} namespace as Constants.
+ # Creates component managers and allows accessing them them under the {FelECS::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 {FelFlame::ComponentManager} documentation.
+ # To see how component managers are used please look at the {FelECS::ComponentManager} documentation.
module Components; end
- # 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 {FelFlame::Systems} namespace as Constants.
+ # 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 {FelECS::Systems} namespace as Constants.
# You can use array methods directly on this class to access Systems.
class Systems; end
- # 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 {FelFlame::Scenes} namespace as Constants.
+ # 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 {FelECS::Scenes} namespace as Constants.
class Scenes; end
# 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.
@@ -45,23 +45,23 @@ module FelFlame
module Order; end
end
-# An alias for {FelFlame}
-FF = FelFlame
+# An alias for {FelECS}
+FECS = FelECS
-# An alias for {FelFlame::Entities}
-FF::Ent = FelFlame::Entities
+# An alias for {FelECS::Entities}
+FECS::Ent = FelECS::Entities
-# An alias for {FelFlame::Components}
-FF::Cmp = FelFlame::Components
+# An alias for {FelECS::Components}
+FECS::Cmp = FelECS::Components
-# An alias for {FelFlame::Systems}
-FF::Sys = FelFlame::Systems
+# An alias for {FelECS::Systems}
+FECS::Sys = FelECS::Systems
-# An alias for {FelFlame::Scenes}
-FF::Scn = FelFlame::Scenes
+# An alias for {FelECS::Scenes}
+FECS::Scn = FelECS::Scenes
-# An alias for {FelFlame::Stage}
-FF::Stg = FelFlame::Stage
+# An alias for {FelECS::Stage}
+FECS::Stg = FelECS::Stage
-# An alias for {FelFlame::
-FF::Odr = FelFlame::Order
+# An alias for {FelECS::
+FECS::Odr = FelECS::Order
diff --git a/lib/felflame/component_manager.rb b/lib/felecs/component_manager.rb
index 6ac7463..36916cb 100644
--- a/lib/felflame/component_manager.rb
+++ b/lib/felecs/component_manager.rb
@@ -1,55 +1,55 @@
# frozen_string_literal: true
-module FelFlame
+module FelECS
module Components
@component_map = []
class << self
- # Creates a new {FelFlame::ComponentManager component manager}.
+ # Creates a new {FelECS::ComponentManager component manager}.
#
# @example
# # 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')
+ # FelECS::Component.new('Health', :max, :current, color: 'red')
#
# @param component_name [String] Name of your new component manager. Must be stylized in the format of constants in Ruby
# @param attrs [:Symbols] New components made with this manager will include these symbols as accessors, the values of these accessors will default to nil
# @param attrs_with_defaults [Keyword: DefaultValue] New components made with this manager will include these keywords as accessors, their defaults set to the values given to the keywords
# @return [ComponentManager]
def new(component_name, *attrs, **attrs_with_defaults)
- if FelFlame::Components.const_defined?(component_name)
+ if FelECS::Components.const_defined?(component_name)
raise(NameError.new, "Component Manager '#{component_name}' is already defined")
end
- const_set(component_name, Class.new(FelFlame::ComponentManager) {})
+ const_set(component_name, Class.new(FelECS::ComponentManager) {})
update_const_cache
attrs.each do |attr|
- if FelFlame::Components.const_get(component_name).method_defined?(attr.to_s) || FelFlame::Components.const_get(component_name).method_defined?("#{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
- FelFlame::Components.const_get(component_name).attr_accessor attr
+ FelECS::Components.const_get(component_name).attr_accessor attr
end
attrs_with_defaults.each do |attr, _default|
attrs_with_defaults[attr] = _default.dup
- FelFlame::Components.const_get(component_name).attr_reader attr
- FelFlame::Components.const_get(component_name).define_method("#{attr}=") do |value|
+ FelECS::Components.const_get(component_name).attr_reader attr
+ FelECS::Components.const_get(component_name).define_method("#{attr}=") do |value|
attr_changed_trigger_systems(attr) unless value.equal? send(attr)
instance_variable_set("@#{attr}", value)
end
end
- FelFlame::Components.const_get(component_name).define_method(:set_defaults) do
+ 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
- FelFlame::Components.const_get(component_name)
+ FelECS::Components.const_get(component_name)
end
- # Stores the components managers in {FelFlame::Components}. This
- # is needed because calling `FelFlame::Components.constants`
+ # Stores the components managers in {FelECS::Components}. This
+ # is needed because calling `FelECS::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
@@ -60,7 +60,7 @@ module FelFlame
end
# Updates the array that stores the constants.
- # Used internally by FelFlame
+ # Used internally by FelECS
# @!visibility private
def update_const_cache
@const_cache = constants.map do |constant|
@@ -104,7 +104,7 @@ module FelFlame
# 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.
+ # Do not edit this array as it is managed by FelECS automatically.
# @return [Array<System>]
def addition_triggers
@addition_triggers ||= []
@@ -112,7 +112,7 @@ module FelFlame
# 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.
+ # Do not edit this array as it is managed by FelECS automatically.
# @return [Array<System>]
def removal_triggers
@removal_triggers ||= []
@@ -120,7 +120,7 @@ module FelFlame
# 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.
+ # Do not edit this hash as it is managed by FelECS automatically.
# @return [Hash<Symbol, Array<System>>]
def attr_triggers
@attr_triggers ||= {}
@@ -132,7 +132,7 @@ module FelFlame
def initialize(**attrs)
# Prepare the object
# (this is a function created with metaprogramming
- # in FelFlame::Components)
+ # in FelECS::Components)
set_defaults
# Fill params
@@ -175,7 +175,7 @@ module FelFlame
# 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.
+ # Do not edit this array as it is managed by FelECS automatically.
# @return [Array<System>]
def addition_triggers
@addition_triggers ||= []
@@ -183,7 +183,7 @@ module FelFlame
# 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.
+ # Do not edit this array as it is managed by FelECS automatically.
# @return [Array<System>]
def removal_triggers
@removal_triggers ||= []
@@ -191,7 +191,7 @@ module FelFlame
# 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.
+ # Do not edit this hash as it is managed by FelECS automatically.
# @return [Hash<Symbol, System>]
def attr_triggers
@attr_triggers ||= {}
diff --git a/lib/felflame/entity_manager.rb b/lib/felecs/entity_manager.rb
index ef70510..a457ed2 100644
--- a/lib/felflame/entity_manager.rb
+++ b/lib/felecs/entity_manager.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module FelFlame
+module FelECS
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.
@@ -25,8 +25,8 @@ module FelFlame
# @return [Component]
def component(manager = nil)
if manager.nil?
- FelFlame::Entities.component_redirect.entity = self
- FelFlame::Entities.component_redirect
+ FelECS::Entities.component_redirect.entity = self
+ FelECS::Entities.component_redirect
else
if components[manager].nil?
raise "This entity(#{self}) doesnt have any components of this type: #{manager}"
@@ -46,7 +46,7 @@ module FelFlame
component.entities.delete(self)
end
end
- FelFlame::Entities._data.delete self
+ FelECS::Entities._data.delete self
@components = {}
true
end
@@ -152,8 +152,8 @@ module FelFlame
# Creates a new entity using the data from a JSON string
# 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
+ # @param json_string [String] A string that was exported originally using the {FelECS::Entities#to_json to_json} function
+ # @param opts [Keywords] What values(its {FelECS::Entities#id ID} or the {FelECS::ComponentManager#id component IDs}) should be overwritten TODO: this might change
# def from_json(json_string, **opts) end
end
end
diff --git a/lib/felflame/order.rb b/lib/felecs/order.rb
index c11438d..3e9b656 100644
--- a/lib/felflame/order.rb
+++ b/lib/felecs/order.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module FelFlame
+module FelECS
module Order
# Sets the priority of all items passed into this method
# according to the order they were passed.
diff --git a/lib/felflame/scene_manager.rb b/lib/felecs/scene_manager.rb
index 0024815..af61b9c 100644
--- a/lib/felflame/scene_manager.rb
+++ b/lib/felecs/scene_manager.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module FelFlame
+module FelECS
class Scenes
# Allows overwriting the storage of systems, such as for clearing.
# This method should generally only need to be used internally and
@@ -13,7 +13,7 @@ module FelFlame
def priority=(priority)
@priority = priority
- FelFlame::Stage.scenes = FelFlame::Stage.scenes.sort_by(&:priority)
+ FelECS::Stage.scenes = FelECS::Stage.scenes.sort_by(&:priority)
priority
end
@@ -21,7 +21,7 @@ module FelFlame
# @param name [String] String format must follow requirements of a constant
def initialize(name, priority: 0)
self.priority = priority
- FelFlame::Scenes.const_set(name, self)
+ FelECS::Scenes.const_set(name, self)
end
# The list of Systems this Scene contains
@@ -62,7 +62,7 @@ module FelFlame
system.scenes.delete self
end
systems.clear
- # FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
+ # FelECS::Stage.update_systems_list if FelECS::Stage.scenes.include? self
true
end
end
diff --git a/lib/felflame/stage_manager.rb b/lib/felecs/stage_manager.rb
index a192b67..b2a5b7c 100644
--- a/lib/felflame/stage_manager.rb
+++ b/lib/felecs/stage_manager.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
-module FelFlame
+module FelECS
module Stage
class << self
# Allows clearing of scenes and systems.
- # Used internally by FelFlame and shouldn't need to be ever used by developers
+ # Used internally by FelECS and shouldn't need to be ever used by developers
# @!visibility private
attr_writer :scenes
diff --git a/lib/felflame/system_manager.rb b/lib/felecs/system_manager.rb
index 8982589..6cd260b 100644
--- a/lib/felflame/system_manager.rb
+++ b/lib/felecs/system_manager.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module FelFlame
+module FelECS
class Systems
# How early this System should be executed in a list of Systems
attr_accessor :priority
@@ -30,7 +30,7 @@ module FelFlame
# 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.
+ # Do not edit this hash as it is managed by FelECS automatically.
# @return [Array<Component>]
def addition_triggers
@addition_triggers ||= []
@@ -39,7 +39,7 @@ module FelFlame
# 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.
+ # Do not edit this hash as it is managed by FelECS automatically.
# @return [Array<Component>]
def removal_triggers
@removal_triggers ||= []
@@ -47,15 +47,15 @@ module FelFlame
# 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.
+ # Do not edit this hash as it is managed by FelECS automatically.
# @return [Hash<Symbol, Array<Symbol>>]
def attr_triggers
@attr_triggers ||= {}
end
class << self
- # Stores the systems in {FelFlame::Components}. This
- # is needed because calling `FelFlame::Components.constants`
+ # Stores the systems in {FelECS::Components}. This
+ # is needed because calling `FelECS::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
@@ -65,7 +65,7 @@ module FelFlame
end
# Updates the array that stores the constants.
- # Used internally by FelFlame
+ # Used internally by FelECS
# @!visibility private
def update_const_cache
@const_cache = constants.map do |constant|
@@ -97,12 +97,12 @@ module FelFlame
end
end
- # Creates a new System which can be accessed as a constant under the namespace {FelFlame::Systems}.
+ # Creates a new System which can be accessed as a constant under the namespace {FelECS::Systems}.
# The name given is what constant the system is assigned to
#
# @example
- # FelFlame::Systems.new('PassiveHeal', priority: -2) do
- # FelFlame::Components::Health.each do |component|
+ # FelECS::Systems.new('PassiveHeal', priority: -2) do
+ # FelECS::Components::Health.each do |component|
# component.hp += 5
# end
# end
@@ -113,8 +113,8 @@ module FelFlame
# @param priority [Integer] Which priority order this system should be executed in relative to other systems. Higher means executed earlier.
# @param block [Proc] The code you wish to be executed when the system is triggered. Can be defined by using a +do end+ block or using +{ }+ braces.
def initialize(name, priority: 0, &block)
- FelFlame::Systems.const_set(name, self)
- FelFlame::Systems.update_const_cache
+ FelECS::Systems.const_set(name, self)
+ FelECS::Systems.update_const_cache
@priority = priority
@block = block
@scenes = []
@@ -138,19 +138,19 @@ module FelFlame
# For attr_triggers
# @example
# # To clear all triggers that execute this system when a component is added:
- # FelFlame::Systems::ExampleSystem.clear_triggers :addition_triggers
+ # FelECS::Systems::ExampleSystem.clear_triggers :addition_triggers
# # Same as above but for when a component is removed instead
- # FelFlame::Systems::ExampleSystem.clear_triggers :removal_triggers
+ # FelECS::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
+ # FelECS::Systems::ExampleSystem.clear_triggers :attr_triggers
#
# # Clear a trigger from a specific component
- # FelFlame::Systems::ExampleSystem.clear_triggers :addition_triggers, FelFlame::Component::ExampleComponent[0]
+ # FelECS::Systems::ExampleSystem.clear_triggers :addition_triggers, FelECS::Component::ExampleComponent[0]
# # Clear a trigger from a specific component manager
- # FelFlame::Systems::ExampleSystem.clear_triggers :addition_triggers, FelFlame::Component::ExampleComponent
+ # FelECS::Systems::ExampleSystem.clear_triggers :addition_triggers, FelECS::Component::ExampleComponent
#
# # Clear the trigger that executes a system when the ':example_attr' is changes
- # FelFlame::Systems::ExampleSystem.clear_triggers :attr_triggers, :example_attr
+ # FelECS::Systems::ExampleSystem.clear_triggers :attr_triggers, :example_attr
# @param 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
# @param component_or_manager [Component or ComponentManager] The object to clear triggers from. Use Nil to clear triggers from all components associated with this system.
# @return [Boolean] +true+
@@ -159,28 +159,28 @@ module FelFlame
if trigger_types.include? :attr_triggers
if (trigger_types - %i[addition_triggers
- removal_triggers
- attr_triggers]).empty?
+ removal_triggers
+ attr_triggers]).empty?
- if component_or_manager.nil?
- # remove all attrs
- attr_triggers.each do |cmp_or_mgr, attrs|
- attrs.each do |attr|
- next if cmp_or_mgr.attr_triggers[attr].nil?
+ if component_or_manager.nil?
+ # remove all attrs
+ attr_triggers.each do |cmp_or_mgr, attrs|
+ attrs.each do |attr|
+ next if cmp_or_mgr.attr_triggers[attr].nil?
- cmp_or_mgr.attr_triggers[attr].delete self
+ cmp_or_mgr.attr_triggers[attr].delete self
+ end
+ self.attr_triggers = {}
end
- self.attr_triggers = {}
- end
- else
- # remove attrs relevant to comp_or_man
- unless attr_triggers[component_or_manager].nil?
- attr_triggers[component_or_manager].each do |attr|
- component_or_manager.attr_triggers[attr].delete self
+ else
+ # remove attrs relevant to comp_or_man
+ unless attr_triggers[component_or_manager].nil?
+ attr_triggers[component_or_manager].each do |attr|
+ component_or_manager.attr_triggers[attr].delete self
+ end
+ attr_triggers[component_or_manager] = []
end
- attr_triggers[component_or_manager] = []
end
- end
elsif component_or_manager.nil?
@@ -191,8 +191,8 @@ module FelFlame
end
end
attr_triggers.delete(trigger_types - %i[addition_triggers
- removal_triggers
- attr_triggers])
+ removal_triggers
+ attr_triggers])
else
# remove attr from component_or_manager
(trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr|
diff --git a/lib/felflame/version.rb b/lib/felecs/version.rb
index 9f7f09e..295b905 100644
--- a/lib/felflame/version.rb
+++ b/lib/felecs/version.rb
@@ -2,8 +2,8 @@
# :nocov:
# Keeps the version of the Gem
-module Felflame
+module FelECS
# The version of the Gem
- VERSION = '4.0.0'
+ VERSION = '5.0.0'
end
# :nocov: