Module: Gamefic::Plot::CommandMount

Included in:
Gamefic::Plot
Defined in:
lib/gamefic/plot/command_mount.rb

Instance Method Summary collapse

Instance Method Details

#action(command, *queries, &proc) ⇒ Object



26
27
28
# File 'lib/gamefic/plot/command_mount.rb', line 26

def action(command, *queries, &proc)
  Action.new(self, command, *queries, &proc)
end

#commandwordsObject



78
79
80
81
82
83
84
85
# File 'lib/gamefic/plot/command_mount.rb', line 78

def commandwords
  words = Array.new
  syntaxes.each { |s|
    word = s.first_word
    words.push(word) if !word.nil?
  }
  words.uniq
end

#interpret(command, translation) ⇒ Syntax

Create an alternate Syntax for an Action. The command and its translation can be parameterized.

Examples:

Create a synonym for the Inventory Action.

interpret "catalogue", "inventory"
# The command "catalogue" will be translated to "inventory"

Create a parameterized synonym for the Look Action.

interpret "scrutinize :entity", "look :entity"
# The command "scrutinize chair" will be translated to "look chair"

Parameters:

  • command (String)

    The format of the original command

  • translation (String)

    The format of the translated command

Returns:

  • (Syntax)

    the Syntax object



68
69
70
# File 'lib/gamefic/plot/command_mount.rb', line 68

def interpret command, translation
  xlate command, translation
end

#meta(command, *queries) {|| ... } ⇒ Object

Create a Meta Action that responds to a command. Meta Actions are very similar to standard Actions, except the Plot understands them to be commands that operate above and/or outside of the actual game world. Examples of Meta Actions are commands that report the player’s current score, save and restore saved games, or list the game’s credits.

Examples:

A simple Meta Action

meta :credits do |actor|
  actor.tell "This game was written by John Smith."
end

Parameters:

  • command (Symbol)

    An imperative verb for the command

  • *queries (Array<Query::Base>)

    Queries to filter the command’s tokens

Yield Parameters:



21
22
23
24
25
# File 'lib/gamefic/plot/command_mount.rb', line 21

def meta(command, *queries, &proc)
  act = self.action(command, *queries, &proc)
  act.meta = true
  act
end

#respond(command, *queries) {|| ... } ⇒ Object

Create an Action that responds to a command. An Action uses the command argument to identify the imperative verb that triggers the action. It can also accept queries to tokenize the remainder of the input and filter for particular entities or properties. The block argument contains the code to be executed when the input matches all of the Action’s criteria (i.e., verb and queries).

Examples:

A simple Action.

respond :salute do |actor|
  actor.tell "Hello, sir!"
end
# The command "salute" will respond "Hello, sir!"

An Action that accepts a Character

respond :salute, Use.visible(Character) do |actor, character|
  actor.tell "#{The character} returns your salute."
end

Parameters:

  • command (Symbol)

    An imperative verb for the command

  • *queries (Array<Query::Base>)

    Queries to filter the command’s tokens

Yield Parameters:



51
52
53
# File 'lib/gamefic/plot/command_mount.rb', line 51

def respond(command, *queries, &proc)
  self.action(command, *queries, &proc)
end

#syntax(*args) ⇒ Object



71
72
73
# File 'lib/gamefic/plot/command_mount.rb', line 71

def syntax(*args)
  xlate(*args)
end

#xlate(*args) ⇒ Object



74
75
76
77
# File 'lib/gamefic/plot/command_mount.rb', line 74

def xlate(*args)
  syn = Syntax.new(self, *args)
  syn
end