lib/felflame/scene_manager.rb in felflame-3.0.0 vs lib/felflame/scene_manager.rb in felflame-4.0.0
- old
+ new
@@ -1,21 +1,29 @@
-class FelFlame
- class Scenes
- # The Constant name assigned to this Scene
- attr_reader :const_name
+# frozen_string_literal: true
+module FelFlame
+ class Scenes
# Allows overwriting the storage of systems, such as for clearing.
# This method should generally only need to be used internally and
# not by a game developer/
# @!visibility private
attr_writer :systems
+ # How early this Scene should be executed in a list of Scenes
+ attr_accessor :priority
+
+ def priority=(priority)
+ @priority = priority
+ FelFlame::Stage.scenes = FelFlame::Stage.scenes.sort_by(&:priority)
+ priority
+ end
+
# Create a new Scene using the name given
# @param name [String] String format must follow requirements of a constant
- def initialize(name)
+ def initialize(name, priority: 0)
+ self.priority = priority
FelFlame::Scenes.const_set(name, self)
- @const_name = name
end
# The list of Systems this Scene contains
# @return [Array<System>]
def systems
@@ -31,28 +39,31 @@
# Adds any number of Systems to this Scene
# @return [Boolean] +true+
def add(*systems_to_add)
self.systems |= systems_to_add
- systems.sort_by!(&:priority)
- FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
+ self.systems = systems.sort_by(&:priority)
+ systems_to_add.each do |system|
+ system.scenes |= [self]
+ end
true
end
- # Removes any number of SystemS from this Scene
+ # Removes any number of Systems from this Scene
# @return [Boolean] +true+
def remove(*systems_to_remove)
self.systems -= systems_to_remove
- systems.sort_by!(&:priority)
- FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
true
end
# Removes all Systems from this Scene
# @return [Boolean] +true+
def clear
+ systems.each do |system|
+ 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
end