class Gamefic::Rulebook
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.
Attributes
@return [Calls]
@return [Events]
@return [Hooks]
@return [Scenes]
Public Class Methods
# File lib/gamefic/rulebook.rb, line 28 def initialize @calls = Calls.new @events = Events.new @hooks = Hooks.new @scenes = Scenes.new end
Public Instance Methods
# File lib/gamefic/rulebook.rb, line 121 def empty? calls.empty? && hooks.empty? && scenes.empty? && events.empty? end
# File lib/gamefic/rulebook.rb, line 35 def freeze super [@calls, @events, @hooks, @scenes].each(&:freeze) self end
@return [Array<Response>]
# File lib/gamefic/rulebook.rb, line 42 def responses @calls.responses end
Get an array of all the responses that match a list of verbs.
@param verbs [Array<Symbol>] @return [Array<Response>]
# File lib/gamefic/rulebook.rb, line 81 def responses_for *verbs @calls.responses_for *verbs end
# File lib/gamefic/rulebook.rb, line 105 def run_after_actions action hooks.run_after action end
# File lib/gamefic/rulebook.rb, line 101 def run_before_actions action hooks.run_before action end
# File lib/gamefic/rulebook.rb, line 109 def run_conclude_blocks events.conclude_blocks.each(&:run) end
# File lib/gamefic/rulebook.rb, line 113 def run_player_conclude_blocks player events.player_conclude_blocks.each { |blk| blk.run(player) } end
# 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
# File lib/gamefic/rulebook.rb, line 93 def run_ready_blocks events.ready_blocks.each(&:run) end
# File lib/gamefic/rulebook.rb, line 97 def run_update_blocks events.update_blocks.each(&:run) end
An array of all the verbs defined in responses and any synonyms defined in syntaxes.
@example
rulebook.respond :verb { |_| nil } rulebook.interpret 'synonym', 'verb' rulebook.synonyms #=> [:synonym, :verb]
# File lib/gamefic/rulebook.rb, line 73 def synonyms @calls.synonyms end
@return [Array<Syntax>]
# File lib/gamefic/rulebook.rb, line 47 def syntaxes @calls.syntaxes end
Get an array of all the syntaxes that match a lit of verbs.
@param words [Array<Symbol>] @return [Array<Syntax>]
# File lib/gamefic/rulebook.rb, line 89 def syntaxes_for *synonyms @calls.syntaxes_for *synonyms end
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
).
@example
rulebook.respond :verb { |_| nil } rulebook.interpret 'synonym', 'verb' rulebook.verbs #=> [:verb]
@return [Array<Symbol>]
# File lib/gamefic/rulebook.rb, line 61 def verbs @calls.verbs end