Class: Ray::SceneList
- Inherits:
-
Object
- Object
- Ray::SceneList
- Includes:
- Enumerable, PP
- Defined in:
- lib/ray/scene_list.rb
Overview
Class used by games to manage their scene list. It needs a game object to find a scene from its name.
Instance Attribute Summary collapse
- #scenes ⇒ Array<Ray::Scene> (also: #to_a) readonly
Instance Method Summary collapse
-
#clear ⇒ Object
Clears the scene list.
-
#current ⇒ Ray::Scene?
The current scene.
- #each(&block) ⇒ Object
-
#empty? ⇒ true, false
True if the scene list contains no scene.
-
#exit_current ⇒ Object
Exits the current scene.
-
#initialize(game) ⇒ SceneList
constructor
A new instance of SceneList.
- #inspect ⇒ Object
-
#pop ⇒ Object
Pops the last scene.
- #pretty_print(q) ⇒ Object
- #push(scene_name, *args) ⇒ Object (also: #<<)
-
#run_current ⇒ Object
Rune the current scene.
Methods included from PP
Constructor Details
#initialize(game) ⇒ SceneList
Returns a new instance of SceneList.
9 10 11 12 13 |
# File 'lib/ray/scene_list.rb', line 9 def initialize(game) @game = game @scenes = [] @scene_args = [] end |
Instance Attribute Details
#scenes ⇒ Array<Ray::Scene> (readonly) Also known as: to_a
72 73 74 |
# File 'lib/ray/scene_list.rb', line 72 def scenes @scenes end |
Instance Method Details
#clear ⇒ Object
Clears the scene list
49 50 51 52 |
# File 'lib/ray/scene_list.rb', line 49 def clear @scenes.clear @scene_args.clear end |
#current ⇒ Ray::Scene?
Returns The current scene.
21 22 23 |
# File 'lib/ray/scene_list.rb', line 21 def current @scenes.last end |
#each(&block) ⇒ Object
67 68 69 |
# File 'lib/ray/scene_list.rb', line 67 def each(&block) @scenes.each(&block) end |
#empty? ⇒ true, false
Returns True if the scene list contains no scene.
16 17 18 |
# File 'lib/ray/scene_list.rb', line 16 def empty? @scenes.empty? end |
#exit_current ⇒ Object
Exits the current scene
37 38 39 40 |
# File 'lib/ray/scene_list.rb', line 37 def exit_current return if empty? current.exit end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/ray/scene_list.rb', line 75 def inspect "#{self.class}#{@scenes.inspect}" end |
#pop ⇒ Object
Pops the last scene
43 44 45 46 |
# File 'lib/ray/scene_list.rb', line 43 def pop @scenes.pop @scene_args.pop end |
#pretty_print(q) ⇒ Object
79 80 81 |
# File 'lib/ray/scene_list.rb', line 79 def pretty_print(q) pretty_print_attributes q, ["scenes"] end |
#push(scene_name, *args) ⇒ Object Also known as: <<
55 56 57 58 59 60 61 62 63 |
# File 'lib/ray/scene_list.rb', line 55 def push(scene_name, *args) scene = @game.registered_scene(scene_name) raise ArgumentError, "Unknown scene #{scene_name}" unless scene @scenes << scene @scene_args << args self end |
#run_current ⇒ Object
Rune the current scene
26 27 28 29 30 31 32 33 34 |
# File 'lib/ray/scene_list.rb', line 26 def run_current scene = @scenes.last scene.scene_arguments = @scene_args.last scene.setup(*@scene_args.last) scene.register_events scene.run end |