Class: Ray::SceneList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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 Method Summary collapse

Constructor Details

#initialize(game) ⇒ SceneList

Returns a new instance of SceneList.

Parameters:

  • game (Ray::Game)

    The game which will be used to find scenes.



8
9
10
11
12
# File 'lib/ray/scene_list.rb', line 8

def initialize(game)
  @game  = game
  @scenes     = []
  @scene_args = []
end

Instance Method Details

#clearObject

Clears the scene list



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

def clear
  @scenes.clear
  @scene_args.clear
end

#currentRay::Scene?

Returns The current scene.

Returns:



20
21
22
# File 'lib/ray/scene_list.rb', line 20

def current
  @scenes.last
end

#each(&block) ⇒ Object



66
67
68
# File 'lib/ray/scene_list.rb', line 66

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



15
16
17
# File 'lib/ray/scene_list.rb', line 15

def empty?
  @scenes.empty?
end

#exit_currentObject

Exits the current scene



36
37
38
39
# File 'lib/ray/scene_list.rb', line 36

def exit_current
  return if empty?
  current.exit
end

#inspectObject



70
71
72
# File 'lib/ray/scene_list.rb', line 70

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

#popObject

Pops the last scene



42
43
44
45
# File 'lib/ray/scene_list.rb', line 42

def pop
  @scenes.pop
  @scene_args.pop
end

#push(scene_name, *args) ⇒ Object Also known as: <<

Parameters:

  • scene (Symbol)

    Name of the scene

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
# File 'lib/ray/scene_list.rb', line 54

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



25
26
27
28
29
30
31
32
33
# File 'lib/ray/scene_list.rb', line 25

def run_current
  scene = @scenes.last

  scene.scene_arguments = @scene_args.last

  scene.setup(*@scene_args.last)
  scene.register_events
  scene.run
end