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

calls[R]

@return [Calls]

events[R]

@return [Events]

hooks[R]

@return [Hooks]

scenes[R]

@return [Scenes]

Public Class Methods

new() click to toggle source
# 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

empty?() click to toggle source
# File lib/gamefic/rulebook.rb, line 121
def empty?
  calls.empty? && hooks.empty? && scenes.empty? && events.empty?
end
freeze() click to toggle source
Calls superclass method
# File lib/gamefic/rulebook.rb, line 35
def freeze
  super
  [@calls, @events, @hooks, @scenes].each(&:freeze)
  self
end
responses() click to toggle source

@return [Array<Response>]

# File lib/gamefic/rulebook.rb, line 42
def responses
  @calls.responses
end
responses_for(*verbs) click to toggle source

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
run_after_actions(action) click to toggle source
# File lib/gamefic/rulebook.rb, line 105
def run_after_actions action
  hooks.run_after action
end
run_before_actions(action) click to toggle source
# File lib/gamefic/rulebook.rb, line 101
def run_before_actions action
  hooks.run_before action
end
run_conclude_blocks() click to toggle source
# File lib/gamefic/rulebook.rb, line 109
def run_conclude_blocks
  events.conclude_blocks.each(&:run)
end
run_player_conclude_blocks(player) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/gamefic/rulebook.rb, line 93
def run_ready_blocks
  events.ready_blocks.each(&:run)
end
run_update_blocks() click to toggle source
# File lib/gamefic/rulebook.rb, line 97
def run_update_blocks
  events.update_blocks.each(&:run)
end
synonyms() click to toggle source

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
syntaxes() click to toggle source

@return [Array<Syntax>]

# File lib/gamefic/rulebook.rb, line 47
def syntaxes
  @calls.syntaxes
end
syntaxes_for(*synonyms) click to toggle source

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
verbs() click to toggle source

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