module Gamefic::World::Callbacks
Public Instance Methods
Add a block to be executed for each player before an update.
# File lib/gamefic/world/callbacks.rb, line 41 def before_player_update &block before_player_update_procs.push block end
# File lib/gamefic/world/callbacks.rb, line 75 def before_player_update_procs @before_player_update_procs ||= [] end
Add a block to be executed at the conclusion of the plot.
@yieldparam [Gamefic::Actor]
# File lib/gamefic/world/callbacks.rb, line 55 def on_player_conclude &block player_conclude_procs.push block end
Add a block to be executed for each player at the beginning of a turn.
@example Tell the player how many turns they've played.
on_player_ready do |player| player[:turns] ||= 0 if player[:turns] > 0 player.tell "Turn #{player[:turns]}" end player[:turns] += 1 end
@yieldparam [Gamefic::Actor]
# File lib/gamefic/world/callbacks.rb, line 34 def on_player_ready &block player_ready_procs.push block end
Add a block to be executed for each player at the end of a turn.
@yieldparam [Gamefic::Actor]
# File lib/gamefic/world/callbacks.rb, line 48 def on_player_update &block player_update_procs.push block end
Add a block to be executed on preparation of every turn.
@example Increment a turn counter
turn = 0 on_ready do turn += 1 end
# File lib/gamefic/world/callbacks.rb, line 12 def on_ready &block ready_procs.push block end
Add a block to be executed after the Plot
is finished updating a turn.
# File lib/gamefic/world/callbacks.rb, line 18 def on_update &block update_procs.push block end
# File lib/gamefic/world/callbacks.rb, line 59 def player_conclude_procs @player_conclude_procs ||= [] end
# File lib/gamefic/world/callbacks.rb, line 71 def player_ready_procs @player_ready_procs ||= [] end
# File lib/gamefic/world/callbacks.rb, line 79 def player_update_procs @player_update_procs ||= [] end
# File lib/gamefic/world/callbacks.rb, line 63 def ready_procs @ready_procs ||= [] end
# File lib/gamefic/world/callbacks.rb, line 67 def update_procs @update_procs ||= [] end
Private Instance Methods
Execute the before_player_update
blocks for each player. This method is typically called by the Plot
while updating a turn, immediately before processing player input.
# File lib/gamefic/world/callbacks.rb, line 103 def call_before_player_update players.each { |player| player.flush before_player_update_procs.each { |block| block.call player } } end
Execute the on_player_ready
blocks for each player. This method is typically called by the Plot
while beginning a turn, immediately after the on_ready
blocks.
# File lib/gamefic/world/callbacks.rb, line 114 def call_player_ready players.each { |player| unless player.next_scene.nil? || !player.scene.finished? player.cue player.next_scene, **player.next_options end player.cue default_scene if player.scene.nil? player_ready_procs.each { |block| block.call player } } end
Execute the on_player_update
blocks for each player. This method is typically called by the Plot
while ending a turn, immediately before the on_ready
blocks.
# File lib/gamefic/world/callbacks.rb, line 128 def call_player_update players.each { |player| player_update_procs.each { |block| block.call player } } end