Class: Gamefic::Rulebook::Events
- Inherits:
-
Object
- Object
- Gamefic::Rulebook::Events
- Defined in:
- lib/gamefic/rulebook/events.rb
Overview
Blocks of code to be executed for various narrative events, such as on_ready and on_update.
Instance Attribute Summary collapse
-
#conclude_blocks ⇒ Object
readonly
Returns the value of attribute conclude_blocks.
-
#player_conclude_blocks ⇒ Object
readonly
Returns the value of attribute player_conclude_blocks.
-
#player_output_blocks ⇒ Object
readonly
Returns the value of attribute player_output_blocks.
-
#ready_blocks ⇒ Object
readonly
Returns the value of attribute ready_blocks.
-
#update_blocks ⇒ Object
readonly
Returns the value of attribute update_blocks.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize ⇒ Events
constructor
A new instance of Events.
- #on_conclude(&block) ⇒ Proc
- #on_player_conclude {|| ... } ⇒ Proc
- #on_player_output {|, | ... } ⇒ Proc
- #on_player_ready {|| ... } ⇒ Proc
- #on_player_update(&block) ⇒ Object
- #on_ready(&block) ⇒ Proc
- #on_update(&block) ⇒ Object
Constructor Details
#initialize ⇒ Events
Returns a new instance of Events.
19 20 21 22 23 24 25 |
# File 'lib/gamefic/rulebook/events.rb', line 19 def initialize @ready_blocks = [] @update_blocks = [] @conclude_blocks = [] @player_conclude_blocks = [] @player_output_blocks = [] end |
Instance Attribute Details
#conclude_blocks ⇒ Object (readonly)
Returns the value of attribute conclude_blocks.
17 18 19 |
# File 'lib/gamefic/rulebook/events.rb', line 17 def conclude_blocks @conclude_blocks end |
#player_conclude_blocks ⇒ Object (readonly)
Returns the value of attribute player_conclude_blocks.
11 12 13 |
# File 'lib/gamefic/rulebook/events.rb', line 11 def player_conclude_blocks @player_conclude_blocks end |
#player_output_blocks ⇒ Object (readonly)
Returns the value of attribute player_output_blocks.
9 10 11 |
# File 'lib/gamefic/rulebook/events.rb', line 9 def player_output_blocks @player_output_blocks end |
#ready_blocks ⇒ Object (readonly)
Returns the value of attribute ready_blocks.
13 14 15 |
# File 'lib/gamefic/rulebook/events.rb', line 13 def ready_blocks @ready_blocks end |
#update_blocks ⇒ Object (readonly)
Returns the value of attribute update_blocks.
15 16 17 |
# File 'lib/gamefic/rulebook/events.rb', line 15 def update_blocks @update_blocks end |
Instance Method Details
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/gamefic/rulebook/events.rb', line 27 def empty? [player_output_blocks, player_conclude_blocks, ready_blocks, update_blocks, conclude_blocks].all?(&:empty?) end |
#freeze ⇒ Object
31 32 33 34 35 |
# File 'lib/gamefic/rulebook/events.rb', line 31 def freeze super instance_variables.each { |k| instance_variable_get(k).freeze } self end |
#on_conclude(&block) ⇒ Proc
61 62 63 |
# File 'lib/gamefic/rulebook/events.rb', line 61 def on_conclude &block @conclude_blocks.push block end |
#on_player_conclude {|| ... } ⇒ Proc
67 68 69 |
# File 'lib/gamefic/rulebook/events.rb', line 67 def on_player_conclude &block @player_conclude_blocks.push block end |
#on_player_output {|, | ... } ⇒ Proc
74 75 76 |
# File 'lib/gamefic/rulebook/events.rb', line 74 def on_player_output &block @player_output_blocks.push block end |
#on_player_ready {|| ... } ⇒ Proc
44 45 46 47 48 |
# File 'lib/gamefic/rulebook/events.rb', line 44 def on_player_ready &block @ready_blocks.push(proc do players.each { |plyr| block.call plyr } end) end |
#on_player_update(&block) ⇒ Object
54 55 56 57 58 |
# File 'lib/gamefic/rulebook/events.rb', line 54 def on_player_update &block @update_blocks.push(proc do players.each { |plyr| block.call plyr } end) end |
#on_ready(&block) ⇒ Proc
38 39 40 |
# File 'lib/gamefic/rulebook/events.rb', line 38 def on_ready &block @ready_blocks.push block end |
#on_update(&block) ⇒ Object
50 51 52 |
# File 'lib/gamefic/rulebook/events.rb', line 50 def on_update &block @update_blocks.push block end |