Module: Gamefic::World::Callbacks

Included in:
Gamefic::World
Defined in:
lib/gamefic/world/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#before_player_update(&block) ⇒ Object

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

@yieldparam



41
42
43
# File 'lib/gamefic/world/callbacks.rb', line 41

def before_player_update &block
  before_player_update_procs.push block
end

#before_player_update_procsObject



75
76
77
# File 'lib/gamefic/world/callbacks.rb', line 75

def before_player_update_procs
  @before_player_update_procs ||= []
end

#on_player_conclude {|| ... } ⇒ Object

Add a block to be executed at the conclusion of the plot.

Yield Parameters:



55
56
57
# File 'lib/gamefic/world/callbacks.rb', line 55

def on_player_conclude &block
  player_conclude_procs.push block
end

#on_player_ready {|| ... } ⇒ Object

Add a block to be executed for each player at the beginning of a turn.

Examples:

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

Yield Parameters:



34
35
36
# File 'lib/gamefic/world/callbacks.rb', line 34

def on_player_ready &block
  player_ready_procs.push block
end

#on_player_update {|| ... } ⇒ Object

Add a block to be executed for each player at the end of a turn.

Yield Parameters:



48
49
50
# File 'lib/gamefic/world/callbacks.rb', line 48

def on_player_update &block
  player_update_procs.push block
end

#on_ready(&block) ⇒ Object

Add a block to be executed on preparation of every turn.

Examples:

Increment a turn counter

turn = 0
on_ready do
  turn += 1
end


12
13
14
# File 'lib/gamefic/world/callbacks.rb', line 12

def on_ready &block
  ready_procs.push block
end

#on_update(&block) ⇒ Object

Add a block to be executed after the Plot is finished updating a turn.



18
19
20
# File 'lib/gamefic/world/callbacks.rb', line 18

def on_update &block
  update_procs.push block
end

#player_conclude_procsObject



59
60
61
# File 'lib/gamefic/world/callbacks.rb', line 59

def player_conclude_procs
  @player_conclude_procs ||= []
end

#player_ready_procsObject



71
72
73
# File 'lib/gamefic/world/callbacks.rb', line 71

def player_ready_procs
  @player_ready_procs ||= []
end

#player_update_procsObject



79
80
81
# File 'lib/gamefic/world/callbacks.rb', line 79

def player_update_procs
  @player_update_procs ||= []
end

#ready_procsObject



63
64
65
# File 'lib/gamefic/world/callbacks.rb', line 63

def ready_procs
  @ready_procs ||= []
end

#update_procsObject



67
68
69
# File 'lib/gamefic/world/callbacks.rb', line 67

def update_procs
  @update_procs ||= []
end