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



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

def on_conclude &block
  rulebook.events.on_conclude(&block)
end

#on_player_conclude {|| ... } ⇒ Proc

Yield Parameters:

Returns:

  • (Proc)


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

def on_player_conclude &block
  rulebook.events.on_player_conclude(&block)
end

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

Yield Parameters:

Returns:

  • (Proc)


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

def on_player_output &block
  rulebook.events.on_player_output(&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
# File 'lib/gamefic/scriptable/events.rb', line 30

def on_player_ready &block
  rulebook.events.on_player_ready(&block)
end

#on_player_update {|| ... } ⇒ Object

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

Yield Parameters:



43
44
45
# File 'lib/gamefic/scriptable/events.rb', line 43

def on_player_update &block
  rulebook.events.on_player_update(&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


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

def on_ready &block
  rulebook.events.on_ready(&block)
end

#on_update(&block) ⇒ Object

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



36
37
38
# File 'lib/gamefic/scriptable/events.rb', line 36

def on_update &block
  rulebook.events.on_update(&block)
end