felflame 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,22 +44,6 @@
44
44
  <ul id="full_list" class="method">
45
45
 
46
46
 
47
- <li class="odd ">
48
- <div class="item">
49
- <span class='object_link'><a href="FelFlame/Entities.html#[]-class_method" title="FelFlame::Entities.[] (method)">[]</a></span>
50
- <small>FelFlame::Entities</small>
51
- </div>
52
- </li>
53
-
54
-
55
- <li class="even ">
56
- <div class="item">
57
- <span class='object_link'><a href="FelFlame/ComponentManager.html#[]-class_method" title="FelFlame::ComponentManager.[] (method)">[]</a></span>
58
- <small>FelFlame::ComponentManager</small>
59
- </div>
60
- </li>
61
-
62
-
63
47
  <li class="odd ">
64
48
  <div class="item">
65
49
  <span class='object_link'><a href="FelFlame/Scenes.html#add-instance_method" title="FelFlame::Scenes#add (method)">#add</a></span>
@@ -109,14 +93,6 @@
109
93
 
110
94
 
111
95
  <li class="odd ">
112
- <div class="item">
113
- <span class='object_link'><a href="FelFlame/ComponentManager.html#attr_changed_trigger_systems-instance_method" title="FelFlame::ComponentManager#attr_changed_trigger_systems (method)">#attr_changed_trigger_systems</a></span>
114
- <small>FelFlame::ComponentManager</small>
115
- </div>
116
- </li>
117
-
118
-
119
- <li class="even ">
120
96
  <div class="item">
121
97
  <span class='object_link'><a href="FelFlame/Systems.html#attr_triggers-instance_method" title="FelFlame::Systems#attr_triggers (method)">#attr_triggers</a></span>
122
98
  <small>FelFlame::Systems</small>
@@ -124,17 +100,9 @@
124
100
  </li>
125
101
 
126
102
 
127
- <li class="odd ">
128
- <div class="item">
129
- <span class='object_link'><a href="FelFlame/ComponentManager.html#attr_triggers-instance_method" title="FelFlame::ComponentManager#attr_triggers (method)">#attr_triggers</a></span>
130
- <small>FelFlame::ComponentManager</small>
131
- </div>
132
- </li>
133
-
134
-
135
103
  <li class="even ">
136
104
  <div class="item">
137
- <span class='object_link'><a href="FelFlame/ComponentManager.html#attr_triggers-class_method" title="FelFlame::ComponentManager.attr_triggers (method)">attr_triggers</a></span>
105
+ <span class='object_link'><a href="FelFlame/ComponentManager.html#attr_triggers-instance_method" title="FelFlame::ComponentManager#attr_triggers (method)">#attr_triggers</a></span>
138
106
  <small>FelFlame::ComponentManager</small>
139
107
  </div>
140
108
  </li>
@@ -142,7 +110,7 @@
142
110
 
143
111
  <li class="odd ">
144
112
  <div class="item">
145
- <span class='object_link'><a href="FelFlame/ComponentManager.html#attrs-instance_method" title="FelFlame::ComponentManager#attrs (method)">#attrs</a></span>
113
+ <span class='object_link'><a href="FelFlame/ComponentManager.html#attr_triggers-class_method" title="FelFlame::ComponentManager.attr_triggers (method)">attr_triggers</a></span>
146
114
  <small>FelFlame::ComponentManager</small>
147
115
  </div>
148
116
  </li>
@@ -206,7 +174,7 @@
206
174
 
207
175
  <li class="odd ">
208
176
  <div class="item">
209
- <span class='object_link'><a href="FelFlame/Entities.html#components-instance_method" title="FelFlame::Entities#components (method)">#components</a></span>
177
+ <span class='object_link'><a href="FelFlame/Entities.html#component-instance_method" title="FelFlame::Entities#component (method)">#component</a></span>
210
178
  <small>FelFlame::Entities</small>
211
179
  </div>
212
180
  </li>
@@ -214,15 +182,15 @@
214
182
 
215
183
  <li class="even ">
216
184
  <div class="item">
217
- <span class='object_link'><a href="FelFlame/Scenes.html#const_name-instance_method" title="FelFlame::Scenes#const_name (method)">#const_name</a></span>
218
- <small>FelFlame::Scenes</small>
185
+ <span class='object_link'><a href="FelFlame/Entities.html#components-instance_method" title="FelFlame::Entities#components (method)">#components</a></span>
186
+ <small>FelFlame::Entities</small>
219
187
  </div>
220
188
  </li>
221
189
 
222
190
 
223
191
  <li class="odd ">
224
192
  <div class="item">
225
- <span class='object_link'><a href="FelFlame/Systems.html#const_name-instance_method" title="FelFlame::Systems#const_name (method)">#const_name</a></span>
193
+ <span class='object_link'><a href="FelFlame/Systems.html#const_cache-class_method" title="FelFlame::Systems.const_cache (method)">const_cache</a></span>
226
194
  <small>FelFlame::Systems</small>
227
195
  </div>
228
196
  </li>
@@ -244,38 +212,6 @@
244
212
  </li>
245
213
 
246
214
 
247
- <li class="even ">
248
- <div class="item">
249
- <span class='object_link'><a href="FelFlame/Entities.html#each-class_method" title="FelFlame::Entities.each (method)">each</a></span>
250
- <small>FelFlame::Entities</small>
251
- </div>
252
- </li>
253
-
254
-
255
- <li class="odd ">
256
- <div class="item">
257
- <span class='object_link'><a href="FelFlame/Systems.html#each-class_method" title="FelFlame::Systems.each (method)">each</a></span>
258
- <small>FelFlame::Systems</small>
259
- </div>
260
- </li>
261
-
262
-
263
- <li class="even ">
264
- <div class="item">
265
- <span class='object_link'><a href="FelFlame/Components.html#each-class_method" title="FelFlame::Components.each (method)">each</a></span>
266
- <small>FelFlame::Components</small>
267
- </div>
268
- </li>
269
-
270
-
271
- <li class="odd ">
272
- <div class="item">
273
- <span class='object_link'><a href="FelFlame/ComponentManager.html#each-class_method" title="FelFlame::ComponentManager.each (method)">each</a></span>
274
- <small>FelFlame::ComponentManager</small>
275
- </div>
276
- </li>
277
-
278
-
279
215
  <li class="even ">
280
216
  <div class="item">
281
217
  <span class='object_link'><a href="FelFlame/ComponentManager.html#entities-instance_method" title="FelFlame::ComponentManager#entities (method)">#entities</a></span>
@@ -286,21 +222,13 @@
286
222
 
287
223
  <li class="odd ">
288
224
  <div class="item">
289
- <span class='object_link'><a href="FelFlame/Entities.html#id-instance_method" title="FelFlame::Entities#id (method)">#id</a></span>
290
- <small>FelFlame::Entities</small>
291
- </div>
292
- </li>
293
-
294
-
295
- <li class="even ">
296
- <div class="item">
297
- <span class='object_link'><a href="FelFlame/ComponentManager.html#id-instance_method" title="FelFlame::ComponentManager#id (method)">#id</a></span>
225
+ <span class='object_link'><a href="FelFlame/ComponentManager.html#entity-instance_method" title="FelFlame::ComponentManager#entity (method)">#entity</a></span>
298
226
  <small>FelFlame::ComponentManager</small>
299
227
  </div>
300
228
  </li>
301
229
 
302
230
 
303
- <li class="odd ">
231
+ <li class="even ">
304
232
  <div class="item">
305
233
  <span class='object_link'><a href="FelFlame/Scenes.html#initialize-instance_method" title="FelFlame::Scenes#initialize (method)">#initialize</a></span>
306
234
  <small>FelFlame::Scenes</small>
@@ -308,7 +236,7 @@
308
236
  </li>
309
237
 
310
238
 
311
- <li class="even ">
239
+ <li class="odd ">
312
240
  <div class="item">
313
241
  <span class='object_link'><a href="FelFlame/Entities.html#initialize-instance_method" title="FelFlame::Entities#initialize (method)">#initialize</a></span>
314
242
  <small>FelFlame::Entities</small>
@@ -316,7 +244,7 @@
316
244
  </li>
317
245
 
318
246
 
319
- <li class="odd ">
247
+ <li class="even ">
320
248
  <div class="item">
321
249
  <span class='object_link'><a href="FelFlame/Systems.html#initialize-instance_method" title="FelFlame::Systems#initialize (method)">#initialize</a></span>
322
250
  <small>FelFlame::Systems</small>
@@ -324,7 +252,7 @@
324
252
  </li>
325
253
 
326
254
 
327
- <li class="even ">
255
+ <li class="odd ">
328
256
  <div class="item">
329
257
  <span class='object_link'><a href="FelFlame/ComponentManager.html#initialize-instance_method" title="FelFlame::ComponentManager#initialize (method)">#initialize</a></span>
330
258
  <small>FelFlame::ComponentManager</small>
@@ -332,7 +260,7 @@
332
260
  </li>
333
261
 
334
262
 
335
- <li class="odd ">
263
+ <li class="even ">
336
264
  <div class="item">
337
265
  <span class='object_link'><a href="FelFlame/Components.html#new-class_method" title="FelFlame::Components.new (method)">new</a></span>
338
266
  <small>FelFlame::Components</small>
@@ -340,6 +268,14 @@
340
268
  </li>
341
269
 
342
270
 
271
+ <li class="odd ">
272
+ <div class="item">
273
+ <span class='object_link'><a href="FelFlame/Scenes.html#priority-instance_method" title="FelFlame::Scenes#priority (method)">#priority</a></span>
274
+ <small>FelFlame::Scenes</small>
275
+ </div>
276
+ </li>
277
+
278
+
343
279
  <li class="even ">
344
280
  <div class="item">
345
281
  <span class='object_link'><a href="FelFlame/Systems.html#priority-instance_method" title="FelFlame::Systems#priority (method)">#priority</a></span>
@@ -414,29 +350,37 @@
414
350
 
415
351
  <li class="odd ">
416
352
  <div class="item">
417
- <span class='object_link'><a href="FelFlame/Scenes.html#systems-instance_method" title="FelFlame::Scenes#systems (method)">#systems</a></span>
418
- <small>FelFlame::Scenes</small>
353
+ <span class='object_link'><a href="FelFlame/Systems.html#scenes-instance_method" title="FelFlame::Systems#scenes (method)">#scenes</a></span>
354
+ <small>FelFlame::Systems</small>
419
355
  </div>
420
356
  </li>
421
357
 
422
358
 
423
359
  <li class="even ">
424
360
  <div class="item">
425
- <span class='object_link'><a href="FelFlame/Entities.html#to_i-instance_method" title="FelFlame::Entities#to_i (method)">#to_i</a></span>
426
- <small>FelFlame::Entities</small>
361
+ <span class='object_link'><a href="FelFlame/Order.html#sort-class_method" title="FelFlame::Order.sort (method)">sort</a></span>
362
+ <small>FelFlame::Order</small>
427
363
  </div>
428
364
  </li>
429
365
 
430
366
 
431
367
  <li class="odd ">
432
368
  <div class="item">
433
- <span class='object_link'><a href="FelFlame/ComponentManager.html#to_i-instance_method" title="FelFlame::ComponentManager#to_i (method)">#to_i</a></span>
434
- <small>FelFlame::ComponentManager</small>
369
+ <span class='object_link'><a href="FelFlame/Scenes.html#systems-instance_method" title="FelFlame::Scenes#systems (method)">#systems</a></span>
370
+ <small>FelFlame::Scenes</small>
435
371
  </div>
436
372
  </li>
437
373
 
438
374
 
439
375
  <li class="even ">
376
+ <div class="item">
377
+ <span class='object_link'><a href="FelFlame/ComponentManager.html#to_h-instance_method" title="FelFlame::ComponentManager#to_h (method)">#to_h</a></span>
378
+ <small>FelFlame::ComponentManager</small>
379
+ </div>
380
+ </li>
381
+
382
+
383
+ <li class="odd ">
440
384
  <div class="item">
441
385
  <span class='object_link'><a href="FelFlame/Systems.html#trigger_when_added-instance_method" title="FelFlame::Systems#trigger_when_added (method)">#trigger_when_added</a></span>
442
386
  <small>FelFlame::Systems</small>
@@ -444,7 +388,7 @@
444
388
  </li>
445
389
 
446
390
 
447
- <li class="odd ">
391
+ <li class="even ">
448
392
  <div class="item">
449
393
  <span class='object_link'><a href="FelFlame/Systems.html#trigger_when_is_changed-instance_method" title="FelFlame::Systems#trigger_when_is_changed (method)">#trigger_when_is_changed</a></span>
450
394
  <small>FelFlame::Systems</small>
@@ -452,7 +396,7 @@
452
396
  </li>
453
397
 
454
398
 
455
- <li class="even ">
399
+ <li class="odd ">
456
400
  <div class="item">
457
401
  <span class='object_link'><a href="FelFlame/Systems.html#trigger_when_removed-instance_method" title="FelFlame::Systems#trigger_when_removed (method)">#trigger_when_removed</a></span>
458
402
  <small>FelFlame::Systems</small>
@@ -460,7 +404,7 @@
460
404
  </li>
461
405
 
462
406
 
463
- <li class="odd ">
407
+ <li class="even ">
464
408
  <div class="item">
465
409
  <span class='object_link'><a href="FelFlame/ComponentManager.html#update_attrs-instance_method" title="FelFlame::ComponentManager#update_attrs (method)">#update_attrs</a></span>
466
410
  <small>FelFlame::ComponentManager</small>
@@ -82,12 +82,10 @@
82
82
  <p class="children">
83
83
 
84
84
 
85
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="Felflame_.html" title="Felflame (module)">Felflame</a></span>
85
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="FelFlame.html" title="FelFlame (module)">FelFlame</a></span>, <span class='object_link'><a href="Felflame_.html" title="Felflame (module)">Felflame</a></span>
86
86
 
87
87
 
88
88
 
89
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span>
90
-
91
89
 
92
90
  </p>
93
91
 
@@ -103,7 +101,7 @@
103
101
  <div class="docstring">
104
102
  <div class="discussion">
105
103
 
106
- <p>An alias for <span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></p>
104
+ <p>An alias for <span class='object_link'><a href="FelFlame.html" title="FelFlame (module)">FelFlame</a></span></p>
107
105
 
108
106
 
109
107
  </div>
@@ -113,7 +111,7 @@
113
111
 
114
112
  </div>
115
113
  </dt>
116
- <dd><pre class="code"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span></pre></dd>
114
+ <dd><pre class="code"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (module)">FelFlame</a></span></span></pre></dd>
117
115
 
118
116
  </dl>
119
117
 
@@ -129,7 +127,7 @@
129
127
  </div>
130
128
 
131
129
  <div id="footer">
132
- Generated on Mon Jul 12 18:28:27 2021 by
130
+ Generated on Mon Jan 3 08:23:04 2022 by
133
131
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
134
132
  0.9.26 (ruby-2.7.3).
135
133
  </div>
data/felflame.gemspec CHANGED
@@ -1,44 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/felflame/version"
3
+ require_relative 'lib/felflame/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "felflame"
6
+ spec.name = 'felflame'
7
7
  spec.version = Felflame::VERSION
8
- spec.authors = ["Tradam"]
9
- spec.email = ["felflame@tradam.dev"]
8
+ spec.authors = ['Tradam']
9
+ spec.email = ['felflame@tradam.dev']
10
10
 
11
- spec.summary = "The Engine Agnostic ECS Ruby Framework"
12
- #spec.description = "TODO: Write a longer description or delete this line."
13
- spec.homepage = "https://felflame.tradam.fyi"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.4.0"
11
+ spec.summary = 'The Engine Agnostic ECS Ruby Framework'
12
+ # spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = 'https://felflame.tradam.fyi'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.4.0'
16
16
 
17
- #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
18
 
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/realtradam/FelFlame"
21
- #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/realtradam/FelFlame'
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
25
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|deprecated|codeclimate|logos)/}) }
27
27
  end
28
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
31
31
 
32
32
  # Uncomment to register a new dependency of your gem
33
33
  # spec.add_dependency "example-gem", "~> 1.0"
34
- spec.add_development_dependency 'minitest-reporters', '~> 1.4', '>= 1.4.3'#, require: false
34
+ spec.add_development_dependency 'minitest-reporters', '~> 1.4', '>= 1.4.3' # , require: false
35
+ spec.add_development_dependency 'redcarpet', '~> 3.5', '>= 3.5.1' # , require: false
35
36
  spec.add_development_dependency 'rspec', '~> 3.10'
36
- spec.add_development_dependency 'simplecov', '~> 0.21.2'#, require: false
37
- spec.add_development_dependency 'simplecov-console', '~> 0.9.1'
38
- spec.add_development_dependency 'simplecov_json_formatter', '~> 0.1.3'#, require: false
39
- spec.add_development_dependency 'redcarpet', '~> 3.5', '>= 3.5.1'#, require: false
40
- spec.add_development_dependency 'yard', '~> 0.9.26'#, require: false
41
37
  spec.add_development_dependency 'rubocop', '~> 1.7'
38
+ spec.add_development_dependency 'simplecov', '~> 0.21.2' # , require: false
39
+ spec.add_development_dependency 'simplecov-console', '~> 0.9.1'
40
+ spec.add_development_dependency 'simplecov_json_formatter', '~> 0.1.3' # , require: false
41
+ spec.add_development_dependency 'yard', '~> 0.9.26' # , require: false
42
42
 
43
43
  # For more information and examples about making a new gem, checkout our
44
44
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,8 +1,9 @@
1
- class FelFlame
2
- class Components
1
+ # frozen_string_literal: true
2
+
3
+ module FelFlame
4
+ module Components
3
5
  @component_map = []
4
- class <<self
5
- include Enumerable
6
+ class << self
6
7
  # Creates a new {FelFlame::ComponentManager component manager}.
7
8
  #
8
9
  # @example
@@ -21,13 +22,14 @@ class FelFlame
21
22
  raise(NameError.new, "Component Manager '#{component_name}' is already defined")
22
23
  end
23
24
 
24
-
25
25
  const_set(component_name, Class.new(FelFlame::ComponentManager) {})
26
+ update_const_cache
26
27
 
27
28
  attrs.each do |attr|
28
- if FelFlame::Components.const_get(component_name).method_defined?("#{attr}") || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=")
29
- raise NameError.new "The attribute name \"#{attr}\" is already a method"
29
+ if FelFlame::Components.const_get(component_name).method_defined?(attr.to_s) || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=")
30
+ raise NameError, "The attribute name \"#{attr}\" is already a method"
30
31
  end
32
+
31
33
  FelFlame::Components.const_get(component_name).attr_accessor attr
32
34
  end
33
35
  attrs_with_defaults.each do |attr, _default|
@@ -46,28 +48,54 @@ class FelFlame
46
48
  FelFlame::Components.const_get(component_name)
47
49
  end
48
50
 
49
- # Iterate over all existing component managers. You also call other enumerable methods instead of each, such as +each_with_index+ or +select+
50
- # @return [Enumerator]
51
- def each(&block)
52
- constants.each(&block)
51
+ # Stores the components managers in {FelFlame::Components}. This
52
+ # is needed because calling `FelFlame::Components.constants`
53
+ # will not let you iterate over the value of the constants
54
+ # but will instead give you an array of symbols. This caches
55
+ # the convertion of those symbols to the actual value of the
56
+ # constants
57
+ # @!visibility private
58
+ def const_cache
59
+ @const_cache || update_const_cache
60
+ end
61
+
62
+ # Updates the array that stores the constants.
63
+ # Used internally by FelFlame
64
+ # @!visibility private
65
+ def update_const_cache
66
+ @const_cache = constants.map do |constant|
67
+ const_get constant
68
+ end
69
+ end
70
+
71
+ # Forwards undefined methods to the array of constants
72
+ # if the array can handle the request. Otherwise tells
73
+ # the programmer their code errored
74
+ # @!visibility private
75
+ def respond_to_missing?(method, *)
76
+ if const_cache.respond_to? method
77
+ true
78
+ else
79
+ super
80
+ end
81
+ end
82
+
83
+ # Makes component module behave like arrays with additional
84
+ # methods for managing the array
85
+ # @!visibility private
86
+ def method_missing(method, *args, **kwargs, &block)
87
+ if const_cache.respond_to? method
88
+ const_cache.send(method, *args, **kwargs, &block)
89
+ else
90
+ super
91
+ end
53
92
  end
54
93
  end
55
94
  end
56
95
 
57
96
  # Component Managers are what is used to create individual components which can be attached to entities.
58
- # 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.
97
+ # 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.
59
98
  class ComponentManager
60
-
61
- # Holds the {id unique ID} of a component. The {id ID} is only unique within the scope of the component manager it was created from.
62
- # @return [Integer]
63
- attr_reader :id
64
-
65
- # A seperate attr_writer was made for documentation readability reasons.
66
- # Yard will list attr_reader is readonly which is my intention.
67
- # This value needs to be changable as it is set by other functions.
68
- # @!visibility private
69
- attr_writer :id
70
-
71
99
  # Allows overwriting the storage of triggers, such as for clearing.
72
100
  # This method should generally only need to be used internally and
73
101
  # not by a game developer.
@@ -104,24 +132,40 @@ class FelFlame
104
132
  def initialize(**attrs)
105
133
  # Prepare the object
106
134
  # (this is a function created with metaprogramming
107
- # in FelFlame::Components
135
+ # in FelFlame::Components)
108
136
  set_defaults
109
137
 
110
- # Generate ID
111
- new_id = self.class.data.find_index { |i| i.nil? }
112
- new_id = self.class.data.size if new_id.nil?
113
- @id = new_id
114
-
115
138
  # Fill params
116
139
  attrs.each do |key, value|
117
140
  send "#{key}=", value
118
141
  end
119
142
 
120
143
  # Save Component
121
- self.class.data[new_id] = self
144
+ self.class.push self
122
145
  end
123
146
 
124
- class <<self
147
+ class << self
148
+ # Makes component managers behave like arrays with additional
149
+ # methods for managing the array
150
+ # @!visibility private
151
+ def respond_to_missing?(method, *)
152
+ if _data.respond_to? method
153
+ true
154
+ else
155
+ super
156
+ end
157
+ end
158
+
159
+ # Makes component managers behave like arrays with additional
160
+ # methods for managing the array
161
+ # @!visibility private
162
+ def method_missing(method, *args, **kwargs, &block)
163
+ if _data.respond_to? method
164
+ _data.send(method, *args, **kwargs, &block)
165
+ else
166
+ super
167
+ end
168
+ end
125
169
 
126
170
  # Allows overwriting the storage of triggers, such as for clearing.
127
171
  # This method should generally only need to be used internally and
@@ -155,41 +199,28 @@ class FelFlame
155
199
 
156
200
  # @return [Array<Component>] Array of all Components that belong to a given component manager
157
201
  # @!visibility private
158
- def data
202
+ def _data
159
203
  @data ||= []
160
204
  end
161
-
162
- # Gets a Component from the given {id unique ID}. Usage is simular to how an Array lookup works.
163
- #
164
- # @example
165
- # # this gets the 'Health' Component with ID 7
166
- # FelFlame::Components::Health[7]
167
- # @param component_id [Integer]
168
- # @return [Component] Returns the Component that uses the given unique {id ID}, nil if there is no Component associated with the given {id ID}
169
- def [](component_id)
170
- data[component_id]
171
- end
172
-
173
- # Iterates over all components within the component manager.
174
- # Special Enumerable methods like +map+ or +each_with_index+ are not implemented
175
- # @return [Enumerator]
176
- def each(&block)
177
- data.compact.each(&block)
178
- end
179
- end
180
-
181
- # An alias for the {id ID Reader}
182
- # @return [Integer]
183
- def to_i
184
- id
185
205
  end
186
206
 
187
- # A list of entity ids that are linked to the component
188
- # @return [Array<Integer>]
207
+ # Entities that have this component
208
+ # @return [Array<Component>]
189
209
  def entities
190
210
  @entities ||= []
191
211
  end
192
212
 
213
+ # A single entity. Use this if you expect the component to only belong to one entity and you want to access it.
214
+ # @return [Component]
215
+ def entity
216
+ if entities.empty?
217
+ 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.")
218
+ elsif entities.length > 1
219
+ 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.")
220
+ end
221
+ entities.first
222
+ end
223
+
193
224
  # Update attribute values using a hash or keywords.
194
225
  # @return [Hash<Symbol, Value>] Hash of updated attributes
195
226
  def update_attrs(**opts)
@@ -200,39 +231,35 @@ class FelFlame
200
231
 
201
232
  # Execute systems that have been added to execute on variable change
202
233
  # @return [Boolean] +true+
234
+ # @!visibility private
203
235
  def attr_changed_trigger_systems(attr)
204
236
  systems_to_execute = self.class.attr_triggers[attr]
205
237
  systems_to_execute = [] if systems_to_execute.nil?
206
238
 
207
239
  systems_to_execute |= attr_triggers[attr] unless attr_triggers[attr].nil?
208
240
 
209
- systems_to_execute.sort_by(&:priority).reverse.each(&:call)
241
+ systems_to_execute.sort_by(&:priority).reverse_each(&:call)
210
242
  true
211
243
  end
212
244
 
213
- # Removes this component from the list and purges all references to this Component from other Entities, as well as its {id ID} and data.
245
+ # Removes this component from the list and purges all references to this Component from other Entities, as well as its data.
214
246
  # @return [Boolean] +true+.
215
247
  def delete
216
248
  addition_triggers.each do |system|
217
249
  system.clear_triggers component_or_manager: self
218
250
  end
219
- # This needs to be cloned because indices get deleted as
220
- # the remove command is called, breaking the loop if it
221
- # wasn't referencing a clone(will get Nil errors)
222
- iter = entities.map(&:clone)
223
- iter.each do |entity|
224
- #FelFlame::Entities[entity_id].remove self #unless FelFlame::Entities[entity_id].nil?
251
+ entities.reverse_each do |entity|
225
252
  entity.remove self
226
253
  end
227
- self.class.data[id] = nil
254
+ self.class._data.delete self
228
255
  instance_variables.each do |var|
229
256
  instance_variable_set(var, nil)
230
257
  end
231
258
  true
232
259
  end
233
260
 
234
- # @return [Hash<Symbol, Value>] A hash, where all the keys are attributes linked to their respective values.
235
- def attrs
261
+ # @return [Hash<Symbol, Value>] A hash, where all the keys are attributes storing their respective values.
262
+ def to_h
236
263
  return_hash = instance_variables.each_with_object({}) do |key, final|
237
264
  final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key)
238
265
  end
@@ -243,8 +270,8 @@ class FelFlame
243
270
  # Export all data into a JSON String, which could then later be loaded or saved to a file
244
271
  # TODO: This function is not yet complete
245
272
  # @return [String] a JSON formatted String
246
- #def to_json
273
+ # def to_json
247
274
  # # should return a json or hash of all data in this component
248
- #end
275
+ # end
249
276
  end
250
277
  end