diff options
Diffstat (limited to 'lib/felflame/stage_manager.rb')
| -rw-r--r-- | lib/felflame/stage_manager.rb | 43 |
1 files changed, 10 insertions, 33 deletions
diff --git a/lib/felflame/stage_manager.rb b/lib/felflame/stage_manager.rb index 87ee955..a192b67 100644 --- a/lib/felflame/stage_manager.rb +++ b/lib/felflame/stage_manager.rb @@ -1,19 +1,18 @@ -class FelFlame - class Stage - class <<self +# frozen_string_literal: true + +module FelFlame + module Stage + class << self # Allows clearing of scenes and systems. # Used internally by FelFlame and shouldn't need to be ever used by developers # @!visibility private - attr_writer :scenes, :systems + attr_writer :scenes # Add any number of Scenes to the Stage # @return [Boolean] +true+ def add(*scenes_to_add) self.scenes |= scenes_to_add - scenes_to_add.each do |scene| - self.systems |= scene.systems - end - systems.sort_by!(&:priority) + self.scenes = scenes.sort_by(&:priority) true end @@ -21,35 +20,20 @@ class FelFlame # @return [Boolean] +true+ def remove(*scenes_to_remove) self.scenes -= scenes_to_remove - update_systems_list - true - end - - # Updates the list of systems from the Scenes added to the Stage and make sure they are ordered correctly - # This is used internally by FelFlame and shouldn't need to be ever used by developers - # @return [Boolean] +true+ - # @!visibility private - def update_systems_list - systems.clear - scenes.each do |scene| - self.systems |= scene.systems - end - systems.sort_by!(&:priority) true end # Clears all Scenes that were added to the Stage # @return [Boolean] +true+ def clear - systems.clear - scenes.clear + self.scenes.clear true end - # Executes one frame of the game. This executes all the Systems in the Scenes added to the Stage. Systems that exist in two or more different Scenes will still only get executed once. + # Executes one frame of the game. This executes all the Scenes added to the Stage in order of their priority. # @return [Boolean] +true+ def call - systems.each(&:call) + self.scenes.each(&:call) true end @@ -58,13 +42,6 @@ class FelFlame def scenes @scenes ||= [] end - - # Stores systems in the order the stage manager needs to call them - # This method should generally only need to be used internally and not by a game developer - # @!visibility private - def systems - @systems ||= [] - end end end end |
