Class: Ray::SceneList

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from PP

#pretty_print_attributes

Constructor Details

#initialize(game) ⇒ SceneList

Returns a new instance of SceneList.

Parameters:

  • game (Ray::Game)

    The game which will be used to find scenes.



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

#scenesArray<Ray::Scene> (readonly) Also known as: to_a

Returns:



72
73
74
# File 'lib/ray/scene_list.rb', line 72

def scenes
  @scenes
end

Instance Method Details

#clearObject

Clears the scene list



49
50
51
52
# File 'lib/ray/scene_list.rb', line 49

def clear
  @scenes.clear
  @scene_args.clear
end

#currentRay::Scene?

Returns The current scene.

Returns:



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.

Returns:

  • (true, false)

    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_currentObject

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

#inspectObject



75
76
77
# File 'lib/ray/scene_list.rb', line 75

def inspect
  "#{self.class}#{@scenes.inspect}"
end

#popObject

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: <<

Parameters:

  • scene (Symbol)

    Name of the scene

Raises:

  • (ArgumentError)


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_currentObject

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