module Gamefic::World::Callbacks

Public Instance Methods

before_player_update(&block) click to toggle source

Add a block to be executed for each player before an update.

@yieldparam

# File lib/gamefic/world/callbacks.rb, line 41
def before_player_update &block
  before_player_update_procs.push block
end
before_player_update_procs() click to toggle source
# File lib/gamefic/world/callbacks.rb, line 75
def before_player_update_procs
  @before_player_update_procs ||= []
end
on_player_conclude(&block) click to toggle source

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
on_player_ready(&block) click to toggle source

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
on_player_update(&block) click to toggle source

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
on_ready(&block) click to toggle source

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
on_update(&block) click to toggle source

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
player_conclude_procs() click to toggle source
# File lib/gamefic/world/callbacks.rb, line 59
def player_conclude_procs
  @player_conclude_procs ||= []
end
player_ready_procs() click to toggle source
# File lib/gamefic/world/callbacks.rb, line 71
def player_ready_procs
  @player_ready_procs ||= []
end
player_update_procs() click to toggle source
# File lib/gamefic/world/callbacks.rb, line 79
def player_update_procs
  @player_update_procs ||= []
end
ready_procs() click to toggle source
# File lib/gamefic/world/callbacks.rb, line 63
def ready_procs
  @ready_procs ||= []
end
update_procs() click to toggle source
# File lib/gamefic/world/callbacks.rb, line 67
def update_procs
  @update_procs ||= []
end

Private Instance Methods

call_before_player_update() click to toggle source

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
call_player_ready() click to toggle source

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
call_player_update() click to toggle source

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
call_ready() click to toggle source

Execute the on_ready blocks. This method is typically called by the Plot while beginning a turn.

# File lib/gamefic/world/callbacks.rb, line 88
def call_ready
  ready_procs.each { |p| p.call }
end
call_update() click to toggle source

Execute the on_update blocks. This method is typically called by the Plot while ending a turn.

# File lib/gamefic/world/callbacks.rb, line 95
def call_update
  update_procs.each { |p| p.call }
end