Class: Gamefic::Rulebook::Scenes

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/rulebook/scenes.rb

Overview

The scene manager for rulebooks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScenes

Returns a new instance of Scenes.



10
11
12
13
# File 'lib/gamefic/rulebook/scenes.rb', line 10

def initialize
  @scene_map = {}
  @introductions = []
end

Instance Attribute Details

#introductionsObject (readonly)

Returns the value of attribute introductions.



8
9
10
# File 'lib/gamefic/rulebook/scenes.rb', line 8

def introductions
  @introductions
end

Instance Method Details

#[](name) ⇒ Scene?

Returns:



36
37
38
# File 'lib/gamefic/rulebook/scenes.rb', line 36

def [](name)
  @scene_map[name]
end

#add(scene) ⇒ Object

Add a scene to the scenebook.

Parameters:

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'lib/gamefic/rulebook/scenes.rb', line 25

def add scene
  raise ArgumentError, "A scene named `#{scene.name} already exists" if @scene_map.key?(scene.name)

  @scene_map[scene.name] = scene
end

#allArray<Scene>

Returns:



46
47
48
# File 'lib/gamefic/rulebook/scenes.rb', line 46

def all
  @scene_map.values
end

#empty?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/gamefic/rulebook/scenes.rb', line 63

def empty?
  @scene_map.empty? && introductions.empty?
end

#freezeObject



15
16
17
18
19
20
# File 'lib/gamefic/rulebook/scenes.rb', line 15

def freeze
  super
  @scene_map.freeze
  @introductions.freeze
  self
end

#introduction(scene) ⇒ Object



50
51
52
# File 'lib/gamefic/rulebook/scenes.rb', line 50

def introduction scene
  introductions.push scene
end

#maybe_add(name, klass, narrative) ⇒ Object



59
60
61
# File 'lib/gamefic/rulebook/scenes.rb', line 59

def maybe_add name, klass, narrative
  add klass.new(name, narrative) unless names.include?(name)
end

#namesArray<Symbol>

Returns:



41
42
43
# File 'lib/gamefic/rulebook/scenes.rb', line 41

def names
  @scene_map.keys
end

#scene?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/gamefic/rulebook/scenes.rb', line 31

def scene? name
  @scene_map.key? name
end

#with_defaults(narrative) ⇒ Object



54
55
56
57
# File 'lib/gamefic/rulebook/scenes.rb', line 54

def with_defaults narrative
  maybe_add :default_scene, Scene::Activity, narrative
  maybe_add :default_conclusion, Scene::Conclusion, narrative
end