Class: Gamefic::Rulebook::Scenes
- Inherits:
-
Object
- Object
- Gamefic::Rulebook::Scenes
- Defined in:
- lib/gamefic/rulebook/scenes.rb
Overview
The scene manager for rulebooks.
Instance Attribute Summary collapse
-
#introductions ⇒ Object
readonly
Returns the value of attribute introductions.
Instance Method Summary collapse
- #[](name) ⇒ Scene?
-
#add(scene) ⇒ Object
Add a scene to the scenebook.
- #all ⇒ Array<Scene>
- #empty? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize ⇒ Scenes
constructor
A new instance of Scenes.
- #introduction(scene) ⇒ Object
- #maybe_add(name, klass, narrative) ⇒ Object
- #names ⇒ Array<Symbol>
- #scene?(name) ⇒ Boolean
- #with_defaults(narrative) ⇒ Object
Constructor Details
#initialize ⇒ Scenes
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
#introductions ⇒ Object (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?
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.
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 |
#all ⇒ Array<Scene>
46 47 48 |
# File 'lib/gamefic/rulebook/scenes.rb', line 46 def all @scene_map.values end |
#empty? ⇒ Boolean
63 64 65 |
# File 'lib/gamefic/rulebook/scenes.rb', line 63 def empty? @scene_map.empty? && introductions.empty? end |
#freeze ⇒ Object
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 |
#names ⇒ Array<Symbol>
41 42 43 |
# File 'lib/gamefic/rulebook/scenes.rb', line 41 def names @scene_map.keys end |
#scene?(name) ⇒ 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 |