felflame 3.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/.ruby-version +1 -0
- data/CHANGELOG.mdown +47 -27
- data/Gemfile +2 -3
- data/Gemfile.lock +1 -1
- data/README.mdown +116 -81
- data/Rakefile +29 -9
- data/bin/console +3 -3
- data/docs/FelFlame/ComponentManager.html +129 -519
- data/docs/FelFlame/Components.html +22 -120
- data/docs/FelFlame/Entities.html +117 -377
- data/docs/FelFlame/Order.html +251 -0
- data/docs/FelFlame/Scenes.html +68 -66
- data/docs/FelFlame/Stage.html +28 -54
- data/docs/FelFlame/Systems.html +206 -242
- data/docs/FelFlame.html +32 -30
- data/docs/Felflame_.html +2 -2
- data/docs/_index.html +19 -4
- data/docs/class_list.html +1 -1
- data/docs/file.README.html +125 -87
- data/docs/index.html +125 -87
- data/docs/method_list.html +37 -93
- data/docs/top-level-namespace.html +4 -6
- data/felflame.gemspec +21 -21
- data/lib/felflame/component_manager.rb +98 -71
- data/lib/felflame/entity_manager.rb +75 -49
- data/lib/felflame/order.rb +24 -0
- data/lib/felflame/scene_manager.rb +23 -12
- data/lib/felflame/stage_manager.rb +10 -33
- data/lib/felflame/system_manager.rb +92 -47
- data/lib/felflame/version.rb +1 -1
- data/lib/felflame.rb +22 -14
- metadata +32 -29
@@ -1,53 +1,53 @@
|
|
1
|
-
|
2
|
-
class Entities
|
3
|
-
# Holds the unique ID of this entity
|
4
|
-
# @return [Integer]
|
5
|
-
attr_reader :id
|
6
|
-
|
7
|
-
# A seperate attr_writer was made for documentation readability reasons.
|
8
|
-
# Yard will list attr_reader is readonly which is my intention.
|
9
|
-
# This value needs to be changable as it is set by other functions.
|
10
|
-
# @!visibility private
|
11
|
-
attr_writer :id
|
1
|
+
# frozen_string_literal: true
|
12
2
|
|
3
|
+
module FelFlame
|
4
|
+
class Entities
|
13
5
|
# Creating a new Entity
|
14
6
|
# @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.
|
15
7
|
# @return [Entity]
|
16
8
|
def initialize(*components)
|
17
|
-
# Assign new unique ID
|
18
|
-
new_id = self.class.data.find_index(&:nil?)
|
19
|
-
new_id = self.class.data.size if new_id.nil?
|
20
|
-
self.id = new_id
|
21
|
-
|
22
9
|
# Add each component
|
23
10
|
add(*components)
|
24
|
-
|
25
|
-
self.class.data[id] = self
|
11
|
+
self.class._data.push self
|
26
12
|
end
|
27
13
|
|
28
|
-
# A hash that uses component manager constant names as keys, and where the values of those keys are arrays that contain the
|
14
|
+
# 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.
|
29
15
|
# @return [Hash<Component_Manager, Array<Integer>>]
|
30
16
|
def components
|
31
17
|
@components ||= {}
|
32
18
|
end
|
33
19
|
|
34
|
-
#
|
35
|
-
# @
|
36
|
-
|
37
|
-
|
20
|
+
# 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.
|
21
|
+
# @example
|
22
|
+
# @entity.component[@component_manager] # array notation(the standard)
|
23
|
+
# @entity.component(@component_manager) # method notation
|
24
|
+
# @param manager [ComponentManager] If you pass nil you can then use array notation to access the same value.
|
25
|
+
# @return [Component]
|
26
|
+
def component(manager = nil)
|
27
|
+
if manager.nil?
|
28
|
+
FelFlame::Entities.component_redirect.entity = self
|
29
|
+
FelFlame::Entities.component_redirect
|
30
|
+
else
|
31
|
+
if components[manager].nil?
|
32
|
+
raise "This entity(#{self}) doesnt have any components of this type: #{manager}"
|
33
|
+
elsif components[manager].length > 1
|
34
|
+
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.")
|
35
|
+
end
|
36
|
+
|
37
|
+
components[manager].first
|
38
|
+
end
|
38
39
|
end
|
39
40
|
|
40
|
-
# Removes this Entity from the list and purges all references to this Entity from other Components, as well as its
|
41
|
+
# Removes this Entity from the list and purges all references to this Entity from other Components, as well as its data.
|
41
42
|
# @return [Boolean] +true+
|
42
43
|
def delete
|
43
|
-
components.each do |
|
44
|
-
component_array.
|
44
|
+
components.each do |_component_manager, component_array|
|
45
|
+
component_array.reverse_each do |component|
|
45
46
|
component.entities.delete(self)
|
46
47
|
end
|
47
48
|
end
|
48
|
-
FelFlame::Entities.
|
49
|
+
FelFlame::Entities._data.delete self
|
49
50
|
@components = {}
|
50
|
-
@id = nil
|
51
51
|
true
|
52
52
|
end
|
53
53
|
|
@@ -89,6 +89,7 @@ class FelFlame
|
|
89
89
|
check_systems component, :removal_triggers if component.entities.include? self
|
90
90
|
component.entities.delete self
|
91
91
|
components[component.class].delete component
|
92
|
+
components.delete component.class if components[component.class].empty?
|
92
93
|
end
|
93
94
|
true
|
94
95
|
end
|
@@ -96,39 +97,64 @@ class FelFlame
|
|
96
97
|
# Export all data into a JSON String which can then be saved into a file
|
97
98
|
# TODO: This function is not yet complete
|
98
99
|
# @return [String] A JSON formatted String
|
99
|
-
#def to_json() end
|
100
|
+
# def to_json() end
|
100
101
|
|
101
|
-
class <<self
|
102
|
-
|
103
|
-
#
|
102
|
+
class << self
|
103
|
+
# Makes component managers behave like arrays with additional
|
104
|
+
# methods for managing the array
|
104
105
|
# @!visibility private
|
105
|
-
def
|
106
|
-
|
106
|
+
def respond_to_missing?(method, *)
|
107
|
+
if _data.respond_to? method
|
108
|
+
true
|
109
|
+
else
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Makes component managers behave like arrays with additional
|
115
|
+
# methods for managing the array
|
116
|
+
# @!visibility private
|
117
|
+
def method_missing(method, *args, **kwargs, &block)
|
118
|
+
if _data.respond_to? method
|
119
|
+
_data.send(method, *args, **kwargs, &block)
|
120
|
+
else
|
121
|
+
super
|
122
|
+
end
|
107
123
|
end
|
108
124
|
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
125
|
+
# Fancy method redirection for when the `component` method is called
|
126
|
+
# in an Entity
|
127
|
+
# WARNING: This method will not correctly work with multithreading
|
128
|
+
# @!visibility private
|
129
|
+
def component_redirect
|
130
|
+
if @component_redirect
|
131
|
+
else
|
132
|
+
@component_redirect = Object.new
|
133
|
+
@component_redirect.instance_variable_set(:@entity, nil)
|
134
|
+
@component_redirect.define_singleton_method(:entity) do
|
135
|
+
instance_variable_get(:@entity)
|
136
|
+
end
|
137
|
+
@component_redirect.define_singleton_method(:entity=) do |value|
|
138
|
+
instance_variable_set(:@entity, value)
|
139
|
+
end
|
140
|
+
@component_redirect.define_singleton_method(:[]) do |component_manager|
|
141
|
+
entity.component(component_manager)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
@component_redirect
|
118
145
|
end
|
119
146
|
|
120
|
-
#
|
121
|
-
#
|
122
|
-
|
123
|
-
|
124
|
-
data.compact.each(&block)
|
147
|
+
# @return [Array<Entity>] Array of all Entities that exist
|
148
|
+
# @!visibility private
|
149
|
+
def _data
|
150
|
+
@data ||= []
|
125
151
|
end
|
126
152
|
|
127
153
|
# Creates a new entity using the data from a JSON string
|
128
154
|
# TODO: This function is not yet complete
|
129
155
|
# @param json_string [String] A string that was exported originally using the {FelFlame::Entities#to_json to_json} function
|
130
156
|
# @param opts [Keywords] What values(its {FelFlame::Entities#id ID} or the {FelFlame::ComponentManager#id component IDs}) should be overwritten TODO: this might change
|
131
|
-
#def from_json(json_string, **opts) end
|
157
|
+
# def from_json(json_string, **opts) end
|
132
158
|
end
|
133
159
|
end
|
134
160
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FelFlame
|
4
|
+
module Order
|
5
|
+
# Sets the priority of all items passed into this method
|
6
|
+
# according to the order they were passed.
|
7
|
+
# If an array is one of the elements then it will give all
|
8
|
+
# of those elements in the array the same priority.
|
9
|
+
# @param sortables [(Systems and Array<Systems>) or (Scenes and Array<Scenes>)]
|
10
|
+
# @return [Boolean] +true+.
|
11
|
+
def self.sort(*sortables)
|
12
|
+
sortables.each_with_index do |sorted, index|
|
13
|
+
if sorted.respond_to? :priority
|
14
|
+
sorted.priority = index
|
15
|
+
else
|
16
|
+
sorted.each do |item|
|
17
|
+
item.priority = index
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,19 +1,27 @@
|
|
1
|
-
|
2
|
-
class Scenes
|
3
|
-
# The Constant name assigned to this Scene
|
4
|
-
attr_reader :const_name
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
3
|
+
module FelFlame
|
4
|
+
class Scenes
|
6
5
|
# Allows overwriting the storage of systems, such as for clearing.
|
7
6
|
# This method should generally only need to be used internally and
|
8
7
|
# not by a game developer/
|
9
8
|
# @!visibility private
|
10
9
|
attr_writer :systems
|
11
10
|
|
11
|
+
# How early this Scene should be executed in a list of Scenes
|
12
|
+
attr_accessor :priority
|
13
|
+
|
14
|
+
def priority=(priority)
|
15
|
+
@priority = priority
|
16
|
+
FelFlame::Stage.scenes = FelFlame::Stage.scenes.sort_by(&:priority)
|
17
|
+
priority
|
18
|
+
end
|
19
|
+
|
12
20
|
# Create a new Scene using the name given
|
13
21
|
# @param name [String] String format must follow requirements of a constant
|
14
|
-
def initialize(name)
|
22
|
+
def initialize(name, priority: 0)
|
23
|
+
self.priority = priority
|
15
24
|
FelFlame::Scenes.const_set(name, self)
|
16
|
-
@const_name = name
|
17
25
|
end
|
18
26
|
|
19
27
|
# The list of Systems this Scene contains
|
@@ -33,25 +41,28 @@ class FelFlame
|
|
33
41
|
# @return [Boolean] +true+
|
34
42
|
def add(*systems_to_add)
|
35
43
|
self.systems |= systems_to_add
|
36
|
-
systems.sort_by
|
37
|
-
|
44
|
+
self.systems = systems.sort_by(&:priority)
|
45
|
+
systems_to_add.each do |system|
|
46
|
+
system.scenes |= [self]
|
47
|
+
end
|
38
48
|
true
|
39
49
|
end
|
40
50
|
|
41
|
-
# Removes any number of
|
51
|
+
# Removes any number of Systems from this Scene
|
42
52
|
# @return [Boolean] +true+
|
43
53
|
def remove(*systems_to_remove)
|
44
54
|
self.systems -= systems_to_remove
|
45
|
-
systems.sort_by!(&:priority)
|
46
|
-
FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
|
47
55
|
true
|
48
56
|
end
|
49
57
|
|
50
58
|
# Removes all Systems from this Scene
|
51
59
|
# @return [Boolean] +true+
|
52
60
|
def clear
|
61
|
+
systems.each do |system|
|
62
|
+
system.scenes.delete self
|
63
|
+
end
|
53
64
|
systems.clear
|
54
|
-
FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
|
65
|
+
# FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
|
55
66
|
true
|
56
67
|
end
|
57
68
|
end
|
@@ -1,19 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FelFlame
|
4
|
+
module Stage
|
5
|
+
class << self
|
4
6
|
# Allows clearing of scenes and systems.
|
5
7
|
# Used internally by FelFlame and shouldn't need to be ever used by developers
|
6
8
|
# @!visibility private
|
7
|
-
attr_writer :scenes
|
9
|
+
attr_writer :scenes
|
8
10
|
|
9
11
|
# Add any number of Scenes to the Stage
|
10
12
|
# @return [Boolean] +true+
|
11
13
|
def add(*scenes_to_add)
|
12
14
|
self.scenes |= scenes_to_add
|
13
|
-
|
14
|
-
self.systems |= scene.systems
|
15
|
-
end
|
16
|
-
systems.sort_by!(&:priority)
|
15
|
+
self.scenes = scenes.sort_by(&:priority)
|
17
16
|
true
|
18
17
|
end
|
19
18
|
|
@@ -21,35 +20,20 @@ class FelFlame
|
|
21
20
|
# @return [Boolean] +true+
|
22
21
|
def remove(*scenes_to_remove)
|
23
22
|
self.scenes -= scenes_to_remove
|
24
|
-
update_systems_list
|
25
|
-
true
|
26
|
-
end
|
27
|
-
|
28
|
-
# Updates the list of systems from the Scenes added to the Stage and make sure they are ordered correctly
|
29
|
-
# This is used internally by FelFlame and shouldn't need to be ever used by developers
|
30
|
-
# @return [Boolean] +true+
|
31
|
-
# @!visibility private
|
32
|
-
def update_systems_list
|
33
|
-
systems.clear
|
34
|
-
scenes.each do |scene|
|
35
|
-
self.systems |= scene.systems
|
36
|
-
end
|
37
|
-
systems.sort_by!(&:priority)
|
38
23
|
true
|
39
24
|
end
|
40
25
|
|
41
26
|
# Clears all Scenes that were added to the Stage
|
42
27
|
# @return [Boolean] +true+
|
43
28
|
def clear
|
44
|
-
|
45
|
-
scenes.clear
|
29
|
+
self.scenes.clear
|
46
30
|
true
|
47
31
|
end
|
48
32
|
|
49
|
-
# Executes one frame of the game. This executes all the
|
33
|
+
# Executes one frame of the game. This executes all the Scenes added to the Stage in order of their priority.
|
50
34
|
# @return [Boolean] +true+
|
51
35
|
def call
|
52
|
-
|
36
|
+
self.scenes.each(&:call)
|
53
37
|
true
|
54
38
|
end
|
55
39
|
|
@@ -58,13 +42,6 @@ class FelFlame
|
|
58
42
|
def scenes
|
59
43
|
@scenes ||= []
|
60
44
|
end
|
61
|
-
|
62
|
-
# Stores systems in the order the stage manager needs to call them
|
63
|
-
# This method should generally only need to be used internally and not by a game developer
|
64
|
-
# @!visibility private
|
65
|
-
def systems
|
66
|
-
@systems ||= []
|
67
|
-
end
|
68
45
|
end
|
69
46
|
end
|
70
47
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FelFlame
|
2
4
|
class Systems
|
3
5
|
# How early this System should be executed in a list of Systems
|
4
6
|
attr_accessor :priority
|
5
7
|
|
6
8
|
# The Constant name assigned to this System
|
7
|
-
attr_reader :const_name
|
8
9
|
|
9
10
|
# Allows overwriting the storage of triggers, such as for clearing.
|
10
11
|
# This method should generally only need to be used internally and
|
@@ -12,10 +13,20 @@ class FelFlame
|
|
12
13
|
# @!visibility private
|
13
14
|
attr_writer :addition_triggers, :removal_triggers, :attr_triggers
|
14
15
|
|
16
|
+
# Stores all the scenes this system is a part of.
|
17
|
+
attr_writer :scenes
|
18
|
+
|
19
|
+
def scenes
|
20
|
+
@scenes ||= []
|
21
|
+
end
|
22
|
+
|
15
23
|
def priority=(priority)
|
16
24
|
@priority = priority
|
17
|
-
|
25
|
+
scenes.each do |scene|
|
26
|
+
scene.systems = scene.systems.sort_by(&:priority)
|
27
|
+
end
|
18
28
|
end
|
29
|
+
|
19
30
|
# Stores references to components or their managers that trigger
|
20
31
|
# this component when a component or component from that manager
|
21
32
|
# is added to an entity.
|
@@ -34,7 +45,6 @@ class FelFlame
|
|
34
45
|
@removal_triggers ||= []
|
35
46
|
end
|
36
47
|
|
37
|
-
|
38
48
|
# Stores references to systems that should be triggered when an
|
39
49
|
# attribute from this manager is changed
|
40
50
|
# Do not edit this hash as it is managed by FelFlame automatically.
|
@@ -43,13 +53,47 @@ class FelFlame
|
|
43
53
|
@attr_triggers ||= {}
|
44
54
|
end
|
45
55
|
|
46
|
-
class <<self
|
47
|
-
|
56
|
+
class << self
|
57
|
+
# Stores the systems in {FelFlame::Components}. This
|
58
|
+
# is needed because calling `FelFlame::Components.constants`
|
59
|
+
# will not let you iterate over the value of the constants
|
60
|
+
# but will instead give you an array of symbols. This caches
|
61
|
+
# the convertion of those symbols to the actual value of the
|
62
|
+
# constants
|
63
|
+
def const_cache
|
64
|
+
@const_cache || update_const_cache
|
65
|
+
end
|
48
66
|
|
49
|
-
#
|
50
|
-
#
|
51
|
-
|
52
|
-
|
67
|
+
# Updates the array that stores the constants.
|
68
|
+
# Used internally by FelFlame
|
69
|
+
# @!visibility private
|
70
|
+
def update_const_cache
|
71
|
+
@const_cache = constants.map do |constant|
|
72
|
+
const_get constant
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Forwards undefined methods to the array of constants
|
77
|
+
# if the array can handle the request. Otherwise tells
|
78
|
+
# the programmer their code errored
|
79
|
+
# @!visibility private
|
80
|
+
def respond_to_missing?(method, *)
|
81
|
+
if const_cache.respond_to? method
|
82
|
+
true
|
83
|
+
else
|
84
|
+
super
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Makes system module behave like arrays with additional
|
89
|
+
# methods for managing the array
|
90
|
+
# @!visibility private
|
91
|
+
def method_missing(method, *args, **kwargs, &block)
|
92
|
+
if const_cache.respond_to? method
|
93
|
+
const_cache.send(method, *args, **kwargs, &block)
|
94
|
+
else
|
95
|
+
super
|
96
|
+
end
|
53
97
|
end
|
54
98
|
end
|
55
99
|
|
@@ -70,15 +114,17 @@ class FelFlame
|
|
70
114
|
# @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.
|
71
115
|
def initialize(name, priority: 0, &block)
|
72
116
|
FelFlame::Systems.const_set(name, self)
|
73
|
-
|
117
|
+
FelFlame::Systems.update_const_cache
|
74
118
|
@priority = priority
|
75
119
|
@block = block
|
120
|
+
@scenes = []
|
76
121
|
end
|
77
122
|
|
78
123
|
# Manually execute the system a single time
|
79
124
|
def call
|
80
125
|
@block.call
|
81
126
|
end
|
127
|
+
|
82
128
|
# Redefine what code is executed by this System when it is called upon.
|
83
129
|
# @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.
|
84
130
|
def redefine(&block)
|
@@ -109,16 +155,16 @@ class FelFlame
|
|
109
155
|
# @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.
|
110
156
|
# @return [Boolean] +true+
|
111
157
|
def clear_triggers(*trigger_types, component_or_manager: nil)
|
112
|
-
trigger_types = [
|
158
|
+
trigger_types = %i[addition_triggers removal_triggers attr_triggers] if trigger_types.empty?
|
113
159
|
|
114
160
|
if trigger_types.include? :attr_triggers
|
115
|
-
if (trigger_types - [
|
116
|
-
|
117
|
-
|
161
|
+
if (trigger_types - %i[addition_triggers
|
162
|
+
removal_triggers
|
163
|
+
attr_triggers]).empty?
|
118
164
|
|
119
165
|
if component_or_manager.nil?
|
120
|
-
#remove all attrs
|
121
|
-
|
166
|
+
# remove all attrs
|
167
|
+
attr_triggers.each do |cmp_or_mgr, attrs|
|
122
168
|
attrs.each do |attr|
|
123
169
|
next if cmp_or_mgr.attr_triggers[attr].nil?
|
124
170
|
|
@@ -127,49 +173,48 @@ class FelFlame
|
|
127
173
|
self.attr_triggers = {}
|
128
174
|
end
|
129
175
|
else
|
130
|
-
#remove attrs relevant to comp_or_man
|
131
|
-
unless
|
132
|
-
|
176
|
+
# remove attrs relevant to comp_or_man
|
177
|
+
unless attr_triggers[component_or_manager].nil?
|
178
|
+
attr_triggers[component_or_manager].each do |attr|
|
133
179
|
component_or_manager.attr_triggers[attr].delete self
|
134
180
|
end
|
135
|
-
|
181
|
+
attr_triggers[component_or_manager] = []
|
136
182
|
end
|
137
183
|
end
|
138
184
|
|
139
|
-
|
185
|
+
elsif component_or_manager.nil?
|
140
186
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
cmp_or_mgr.attr_triggers[attr].delete self
|
146
|
-
end
|
147
|
-
end
|
148
|
-
self.attr_triggers.delete (trigger_types - [:addition_triggers,
|
149
|
-
:removal_triggers,
|
150
|
-
:attr_triggers])
|
151
|
-
else
|
152
|
-
#remove attr from component_or_manager
|
153
|
-
(trigger_types - [:addition_triggers, :removal_triggers, :attr_triggers]).each do |attr|
|
154
|
-
next if component_or_manager.attr_triggers[attr].nil?
|
155
|
-
component_or_manager.attr_triggers[attr].delete self
|
187
|
+
(trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr|
|
188
|
+
# remove attr
|
189
|
+
attr_triggers.each do |cmp_or_mgr, _attrs|
|
190
|
+
cmp_or_mgr.attr_triggers[attr].delete self
|
156
191
|
end
|
157
|
-
self.attr_triggers[component_or_manager] -= trigger_types unless self.attr_triggers[component_or_manager].nil?
|
158
192
|
end
|
193
|
+
attr_triggers.delete(trigger_types - %i[addition_triggers
|
194
|
+
removal_triggers
|
195
|
+
attr_triggers])
|
196
|
+
else
|
197
|
+
# remove attr from component_or_manager
|
198
|
+
(trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr|
|
199
|
+
next if component_or_manager.attr_triggers[attr].nil?
|
200
|
+
|
201
|
+
component_or_manager.attr_triggers[attr].delete self
|
202
|
+
end
|
203
|
+
attr_triggers[component_or_manager] -= trigger_types unless attr_triggers[component_or_manager].nil?
|
159
204
|
|
160
205
|
end
|
161
206
|
end
|
162
207
|
|
163
|
-
(trigger_types & [
|
208
|
+
(trigger_types & %i[removal_triggers addition_triggers] - [:attr_triggers]).each do |trigger_type|
|
164
209
|
if component_or_manager.nil?
|
165
|
-
#remove all removal triggers
|
166
|
-
|
210
|
+
# remove all removal triggers
|
211
|
+
send(trigger_type).each do |trigger|
|
167
212
|
trigger.send(trigger_type).delete self
|
168
213
|
end
|
169
|
-
|
214
|
+
send("#{trigger_type}=", [])
|
170
215
|
else
|
171
|
-
#remove removal trigger relevant to comp/man
|
172
|
-
|
216
|
+
# remove removal trigger relevant to comp/man
|
217
|
+
send(trigger_type).delete component_or_manager
|
173
218
|
component_or_manager.send(trigger_type).delete self
|
174
219
|
end
|
175
220
|
end
|
@@ -202,10 +247,10 @@ class FelFlame
|
|
202
247
|
else
|
203
248
|
component_or_manager.attr_triggers[attr] |= [self]
|
204
249
|
end
|
205
|
-
if
|
206
|
-
|
250
|
+
if attr_triggers[component_or_manager].nil?
|
251
|
+
attr_triggers[component_or_manager] = [attr]
|
207
252
|
else
|
208
|
-
|
253
|
+
attr_triggers[component_or_manager] |= [attr]
|
209
254
|
end
|
210
255
|
true
|
211
256
|
end
|
data/lib/felflame/version.rb
CHANGED
data/lib/felflame.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'felflame/entity_manager'
|
2
4
|
require_relative 'felflame/component_manager'
|
3
5
|
require_relative 'felflame/system_manager'
|
4
6
|
require_relative 'felflame/scene_manager'
|
5
7
|
require_relative 'felflame/stage_manager'
|
8
|
+
require_relative 'felflame/order'
|
6
9
|
|
7
|
-
require_relative
|
10
|
+
require_relative 'felflame/version'
|
8
11
|
|
9
12
|
# The FelFlame namespace where all its functionality resides under.
|
10
|
-
|
11
|
-
class <<self
|
13
|
+
module FelFlame
|
14
|
+
class << self
|
12
15
|
# :nocov:
|
13
16
|
|
14
17
|
# An alias for {FelFlame::Stage.call}. It executes a single frame in the game.
|
@@ -18,26 +21,28 @@ class FelFlame
|
|
18
21
|
# :nocov:
|
19
22
|
end
|
20
23
|
|
21
|
-
# Creates and manages Entities.
|
24
|
+
# Creates and manages Entities. Entities are just collections of Components.
|
25
|
+
# You can use array methods directly on this class to access Entities.
|
22
26
|
class Entities; end
|
23
27
|
|
24
|
-
# Creates component managers and allows accessing them them under the {FelFlame::Components} namespace as Constants
|
28
|
+
# Creates component managers and allows accessing them them under the {FelFlame::Components} namespace as Constants.
|
29
|
+
# You can use array methods directly on this class to access Component Managers.
|
25
30
|
#
|
26
31
|
# To see how component managers are used please look at the {FelFlame::ComponentManager} documentation.
|
27
|
-
|
32
|
+
module Components; end
|
28
33
|
|
29
|
-
# Creates
|
30
|
-
#
|
31
|
-
# TODO: Improve Systems overview
|
34
|
+
# 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.
|
35
|
+
# You can use array methods directly on this class to access Systems.
|
32
36
|
class Systems; end
|
33
37
|
|
34
|
-
# Creates and manages Scenes. Scenes are collections of Systems, and execute all the Systems when called upon.
|
35
|
-
#
|
36
|
-
# TODO: Improve Scenes overview
|
38
|
+
# 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.
|
37
39
|
class Scenes; end
|
38
40
|
|
39
|
-
# Stores Scenes 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.
|
40
|
-
|
41
|
+
# 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.
|
42
|
+
module Stage; end
|
43
|
+
|
44
|
+
# Sets the priority of a list of Systems or Scenes for you in the order you pass them to this class.
|
45
|
+
module Order; end
|
41
46
|
end
|
42
47
|
|
43
48
|
# An alias for {FelFlame}
|
@@ -57,3 +62,6 @@ FF::Scn = FelFlame::Scenes
|
|
57
62
|
|
58
63
|
# An alias for {FelFlame::Stage}
|
59
64
|
FF::Stg = FelFlame::Stage
|
65
|
+
|
66
|
+
# An alias for {FelFlame::
|
67
|
+
FF::Odr = FelFlame::Order
|