Module: Gamefic::Scriptable::Events

Included in:
Narrative, Gamefic::Scriptable
Defined in:
lib/gamefic/scriptable/events.rb

Overview

Scriptable methods related to creating event callbacks.

Instance Method Summary collapse

Instance Method Details

#on_conclude(&block) ⇒ Object



53
54
55
# File 'lib/gamefic/scriptable/events.rb', line 53

def on_conclude &block
  rulebook.events.on_conclude(Callback.new(self, block))
end

#on_player_conclude {|| ... } ⇒ Proc

Yield Parameters:

Returns:

  • (Proc)


59
60
61
# File 'lib/gamefic/scriptable/events.rb', line 59

def on_player_conclude &block
  rulebook.events.on_player_conclude(Callback.new(self, block))
end

#on_player_output {|, | ... } ⇒ Proc

Yield Parameters:

Returns:

  • (Proc)


66
67
68
# File 'lib/gamefic/scriptable/events.rb', line 66

def on_player_output &block
  rulebook.events.on_player_output Callback.new(self, 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] ||= 1
  player.tell "Turn #{player[:turns]}"
  player[:turns] += 1
end

Yield Parameters:



30
31
32
33
34
35
# File 'lib/gamefic/scriptable/events.rb', line 30

def on_player_ready &block
  wrapper = proc do
    players.each { |player| Stage.run(self, player, &block) }
  end
  on_ready &wrapper
end

#on_player_update {|| ... } ⇒ Object

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

Yield Parameters:



46
47
48
49
50
51
# File 'lib/gamefic/scriptable/events.rb', line 46

def on_player_update &block
  wrapper = proc do
    players.each { |player| Stage.run(self, player, &block) }
  end
  on_update &wrapper
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


16
17
18
# File 'lib/gamefic/scriptable/events.rb', line 16

def on_ready &block
  rulebook.events.on_ready(Callback.new(self, block))
end

#on_update(&block) ⇒ Object

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



39
40
41
# File 'lib/gamefic/scriptable/events.rb', line 39

def on_update &block
  rulebook.events.on_update(Callback.new(self, block))
end