Module: Gamefic::Scriptable::Hooks
- Included in:
- Gamefic::Scriptable
- Defined in:
- lib/gamefic/scriptable/hooks.rb
Overview
Scriptable hook methods are class methods that define procs to be executed in response to various game events.
Instance Method Summary collapse
-
#after_command(*verbs) {|, | ... } ⇒ Object
Define a callback to be executed after a command is processed.
- #after_commands ⇒ Array<Proc>
-
#before_command(*verbs) {|, | ... } ⇒ Object
Define a callback to be executed before a command is processed.
- #before_commands ⇒ Array<Proc>
- #conclude_blocks ⇒ Array<Proc>
-
#on_conclude(&block) ⇒ Object
Define a callback that gets executed when a narrative reaches a conclusion.
-
#on_player_conclude {|| ... } ⇒ Object
Define a callback that gets executed when a player reaches a conclusion.
-
#on_player_output {|, | ... } ⇒ Object
Define a callback that modifies the output sent to the player at the beginning of a game turn.
-
#on_player_ready {|| ... } ⇒ Object
Define a callback to be executed for each participating player after a scene starts.
-
#on_player_update {|| ... } ⇒ Object
Define a callback to be executed for each participating player after a scene finishes.
-
#on_ready(&block) ⇒ Object
Define a callback to be executed after a scene starts.
-
#on_update(&block) ⇒ Object
Define a callback to be executed after a scene finishes.
- #player_conclude_blocks ⇒ Array<Proc>
- #player_output_blocks ⇒ Array<Proc>
- #ready_blocks ⇒ Array<Proc>
- #update_blocks ⇒ Array<Proc>
Instance Method Details
#after_command(*verbs) {|, | ... } ⇒ Object
Define a callback to be executed after a command is processed. The callback accepts two parameters, the Actor and the Command.
The optional verbs parameter can be used to restrict the callback to commands that use one of the specified verbs. If no verbs are provided, the callback will be executed after every command.
47 48 49 50 51 |
# File 'lib/gamefic/scriptable/hooks.rb', line 47 def after_command(*verbs, &block) after_commands.push(proc do |actor, command| instance_exec(actor, command, &block) if verbs.empty? || verbs.include?(command.verb) end) end |
#after_commands ⇒ Array<Proc>
131 132 133 |
# File 'lib/gamefic/scriptable/hooks.rb', line 131 def after_commands @after_commands ||= [] end |
#before_command(*verbs) {|, | ... } ⇒ Object
Define a callback to be executed before a command is processed. The callback accepts two parameters, the Actor and the Command.
The optional verbs parameter can be used to restrict the callback to commands that use one of the specified verbs. If no verbs are provided, the callback will be executed before every command.
Calling Command#cancel will prevent the command from being performed.
30 31 32 33 34 |
# File 'lib/gamefic/scriptable/hooks.rb', line 30 def before_command(*verbs, &block) before_commands.push(proc do |actor, command| instance_exec(actor, command, &block) if verbs.empty? || verbs.include?(command.verb) end) end |
#before_commands ⇒ Array<Proc>
126 127 128 |
# File 'lib/gamefic/scriptable/hooks.rb', line 126 def before_commands @before_commands ||= [] end |
#conclude_blocks ⇒ Array<Proc>
151 152 153 |
# File 'lib/gamefic/scriptable/hooks.rb', line 151 def conclude_blocks @conclude_blocks ||= [] end |
#on_conclude(&block) ⇒ Object
Define a callback that gets executed when a narrative reaches a conclusion.
109 110 111 |
# File 'lib/gamefic/scriptable/hooks.rb', line 109 def on_conclude(&block) conclude_blocks.push(block) end |
#on_player_conclude {|| ... } ⇒ Object
A player can conclude participation in a narrative without the narrative itself concluding.
Define a callback that gets executed when a player reaches a conclusion.
121 122 123 |
# File 'lib/gamefic/scriptable/hooks.rb', line 121 def on_player_conclude(&block) player_conclude_blocks.push(block) end |
#on_player_output {|, | ... } ⇒ Object
Define a callback that modifies the output sent to the player at the beginning of a game turn. The callback accepts two parameters, the Actor and the Props::Output.
Narrators execute player_output blocks after starting a scene and executing ready blocks. The output gets sent to players’ game clients as JSON objects to be rendered before prompting the player for input.
101 102 103 |
# File 'lib/gamefic/scriptable/hooks.rb', line 101 def on_player_output(&block) player_output_blocks.push(block) end |
#on_player_ready {|| ... } ⇒ Object
Define a callback to be executed for each participating player after a scene starts.
65 66 67 |
# File 'lib/gamefic/scriptable/hooks.rb', line 65 def on_player_ready(&block) ready_blocks.push(proc { players.each { |player| instance_exec(player, &block) } }) end |
#on_player_update {|| ... } ⇒ Object
Define a callback to be executed for each participating player after a scene finishes.
81 82 83 |
# File 'lib/gamefic/scriptable/hooks.rb', line 81 def on_player_update(&block) update_blocks.push(proc { players.each { |player| instance_exec(player, &block) } }) end |
#on_ready(&block) ⇒ Object
Define a callback to be executed after a scene starts.
56 57 58 |
# File 'lib/gamefic/scriptable/hooks.rb', line 56 def on_ready(&block) ready_blocks.push block end |
#on_update(&block) ⇒ Object
Define a callback to be executed after a scene finishes.
72 73 74 |
# File 'lib/gamefic/scriptable/hooks.rb', line 72 def on_update(&block) update_blocks.push block end |
#player_conclude_blocks ⇒ Array<Proc>
156 157 158 |
# File 'lib/gamefic/scriptable/hooks.rb', line 156 def player_conclude_blocks @player_conclude_blocks ||= [] end |
#player_output_blocks ⇒ Array<Proc>
146 147 148 |
# File 'lib/gamefic/scriptable/hooks.rb', line 146 def player_output_blocks @player_output_blocks ||= [] end |
#ready_blocks ⇒ Array<Proc>
136 137 138 |
# File 'lib/gamefic/scriptable/hooks.rb', line 136 def ready_blocks @ready_blocks ||= [] end |
#update_blocks ⇒ Array<Proc>
141 142 143 |
# File 'lib/gamefic/scriptable/hooks.rb', line 141 def update_blocks @update_blocks ||= [] end |