Module: Gamefic::Scriptable::Scenes
- Included in:
- Narrative, Gamefic::Scriptable
- Defined in:
- lib/gamefic/scriptable/scenes.rb
Overview
Scriptable methods related to creating scenes.
Instance Method Summary collapse
-
#block(name, klass = Scene::Default, on_start: nil, on_finish: nil) {|| ... } ⇒ Symbol
Block a new scene.
-
#conclusion(name) {|| ... } ⇒ Symbol
Create a conclusion.
-
#introduction {|, | ... } ⇒ Symbol
Add a block to be executed when a player is added to the game.
-
#multiple_choice(name, choices = [], prompt = 'What is your choice?') {|, | ... } ⇒ Symbol
Create a multiple-choice scene.
-
#pause(name, prompt: 'Press enter to continue...') {|| ... } ⇒ Symbol
Create a scene that pauses the game.
- #preface(name, klass = Scene::Activity, &start) ⇒ Object (also: #precursor)
- #scene(name) ⇒ Scene::Default?
- #scenes ⇒ Array<Symbol>
-
#yes_or_no(name, prompt = 'Answer:') {|, | ... } ⇒ Symbol
Create a yes-or-no scene.
Instance Method Details
#block(name, klass = Scene::Default, on_start: nil, on_finish: nil) {|| ... } ⇒ Symbol
Block a new scene.
35 36 37 38 |
# File 'lib/gamefic/scriptable/scenes.rb', line 35 def block name, klass = Scene::Default, on_start: nil, on_finish: nil, &blk rulebook.scenes.add klass.new(name, self, on_start: on_start, on_finish: on_finish, &blk) name end |
#conclusion(name) {|| ... } ⇒ Symbol
Create a conclusion. The game (or the character’s participation in it) will end after this scene is complete.
156 157 158 159 160 |
# File 'lib/gamefic/scriptable/scenes.rb', line 156 def conclusion name, &start block name, Scene::Conclusion, on_start: start end |
#introduction {|, | ... } ⇒ Symbol
Add a block to be executed when a player is added to the game. Each Plot should only have one introduction.
59 60 61 62 63 64 |
# File 'lib/gamefic/scriptable/scenes.rb', line 59 def introduction(&start) rulebook.scenes .introduction Scene::Default.new nil, self, on_start: proc { |actor, _props| Stage.run(self, actor, &start) } end |
#multiple_choice(name, choices = [], prompt = 'What is your choice?') {|, | ... } ⇒ Symbol
Create a multiple-choice scene. The user will be required to make a choice to continue. The scene will restart if the user input is not a valid choice.
85 86 87 88 89 90 91 92 93 |
# File 'lib/gamefic/scriptable/scenes.rb', line 85 def multiple_choice name, choices = [], prompt = 'What is your choice?', &blk block name, Scene::MultipleChoice, on_start: proc { |_actor, props| props.prompt = prompt props..concat choices }, on_finish: blk end |
#pause(name, prompt: 'Press enter to continue...') {|| ... } ⇒ Symbol
Create a scene that pauses the game. This scene will execute the specified block and wait for input from the the user (e.g., pressing Enter) to continue.
135 136 137 138 139 140 141 142 |
# File 'lib/gamefic/scriptable/scenes.rb', line 135 def pause name, prompt: 'Press enter to continue...', &start block name, Scene::Pause, on_start: proc { |actor, props| props.prompt = prompt if prompt instance_exec(actor, props, &start) } end |
#preface(name, klass = Scene::Activity, &start) ⇒ Object Also known as: precursor
40 41 42 43 |
# File 'lib/gamefic/scriptable/scenes.rb', line 40 def preface name, klass = Scene::Activity, &start rulebook.scenes.add klass.new(name, self, on_start: start) name end |
#scene(name) ⇒ Scene::Default?
169 170 171 |
# File 'lib/gamefic/scriptable/scenes.rb', line 169 def scene(name) rulebook.scenes[name] end |
#scenes ⇒ Array<Symbol>
163 164 165 |
# File 'lib/gamefic/scriptable/scenes.rb', line 163 def scenes rulebook.scenes.names end |
#yes_or_no(name, prompt = 'Answer:') {|, | ... } ⇒ Symbol
Create a yes-or-no scene. The user will be required to answer Yes or No to continue. The scene will restart if the user input is not a valid choice.
113 114 115 116 117 118 119 120 |
# File 'lib/gamefic/scriptable/scenes.rb', line 113 def yes_or_no name, prompt = 'Answer:', &blk block name, Scene::YesOrNo, on_start: proc { |_actor, props| props.prompt = prompt }, on_finish: blk end |