Class: Gamefic::Rulebook
- Inherits:
-
Object
show all
- Defined in:
- lib/gamefic/rulebook.rb,
lib/gamefic/rulebook/calls.rb,
lib/gamefic/rulebook/hooks.rb,
lib/gamefic/rulebook/events.rb,
lib/gamefic/rulebook/scenes.rb
Overview
A collection of rules that define the behavior of a narrative.
Rulebooks provide a way to separate narrative data from code. This separation is necessary to ensure that the game state can be serialized in snapshots.
Defined Under Namespace
Classes: Calls, Events, Hooks, Scenes
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Rulebook.
Instance Attribute Details
17
18
19
|
# File 'lib/gamefic/rulebook.rb', line 17
def calls
@calls
end
|
20
21
22
|
# File 'lib/gamefic/rulebook.rb', line 20
def events
@events
end
|
23
24
25
|
# File 'lib/gamefic/rulebook.rb', line 23
def hooks
@hooks
end
|
26
27
28
|
# File 'lib/gamefic/rulebook.rb', line 26
def scenes
@scenes
end
|
Instance Method Details
#empty? ⇒ Boolean
121
122
123
|
# File 'lib/gamefic/rulebook.rb', line 121
def empty?
calls.empty? && hooks.empty? && scenes.empty? && events.empty?
end
|
#freeze ⇒ Object
35
36
37
38
39
|
# File 'lib/gamefic/rulebook.rb', line 35
def freeze
super
[@calls, @events, @hooks, @scenes].each(&:freeze)
self
end
|
42
43
44
|
# File 'lib/gamefic/rulebook.rb', line 42
def responses
@calls.responses
end
|
#responses_for(*verbs) ⇒ Array<Response>
Get an array of all the responses that match a list of verbs.
81
82
83
|
# File 'lib/gamefic/rulebook.rb', line 81
def responses_for *verbs
@calls.responses_for *verbs
end
|
#run_after_actions(action) ⇒ Object
105
106
107
|
# File 'lib/gamefic/rulebook.rb', line 105
def run_after_actions action
hooks.run_after action
end
|
#run_before_actions(action) ⇒ Object
101
102
103
|
# File 'lib/gamefic/rulebook.rb', line 101
def run_before_actions action
hooks.run_before action
end
|
#run_conclude_blocks ⇒ Object
109
110
111
|
# File 'lib/gamefic/rulebook.rb', line 109
def run_conclude_blocks
events.conclude_blocks.each(&:run)
end
|
#run_player_conclude_blocks(player) ⇒ Object
113
114
115
|
# File 'lib/gamefic/rulebook.rb', line 113
def run_player_conclude_blocks player
events.player_conclude_blocks.each { |blk| blk.run(player) }
end
|
#run_player_output_blocks(player, output) ⇒ Object
117
118
119
|
# File 'lib/gamefic/rulebook.rb', line 117
def run_player_output_blocks player, output
events.player_output_blocks.each { |blk| blk.run(player, output) }
end
|
#run_ready_blocks ⇒ Object
93
94
95
|
# File 'lib/gamefic/rulebook.rb', line 93
def run_ready_blocks
events.ready_blocks.each(&:run)
end
|
#run_update_blocks ⇒ Object
97
98
99
|
# File 'lib/gamefic/rulebook.rb', line 97
def run_update_blocks
events.update_blocks.each(&:run)
end
|
#synonyms ⇒ Object
An array of all the verbs defined in responses and any synonyms defined in syntaxes.
73
74
75
|
# File 'lib/gamefic/rulebook.rb', line 73
def synonyms
@calls.synonyms
end
|
47
48
49
|
# File 'lib/gamefic/rulebook.rb', line 47
def syntaxes
@calls.syntaxes
end
|
#syntaxes_for(*synonyms) ⇒ Array<Syntax>
Get an array of all the syntaxes that match a lit of verbs.
89
90
91
|
# File 'lib/gamefic/rulebook.rb', line 89
def syntaxes_for *synonyms
@calls.syntaxes_for *synonyms
end
|
#verbs ⇒ Array<Symbol>
An array of all the verbs available in the rulebook. This list only includes verbs that are explicitly defined in reponses. It excludes synonyms that might be defined in syntaxes (see #synonyms).
61
62
63
|
# File 'lib/gamefic/rulebook.rb', line 61
def verbs
@calls.verbs
end
|