Module: Gamefic::Scriptable::Actions
- Includes:
- Queries
- Included in:
- Narrative, Gamefic::Scriptable
- Defined in:
- lib/gamefic/scriptable/actions.rb
Overview
Scriptable methods related to creating actions.
Instance Method Summary collapse
-
#after_action(*verbs) {|| ... } ⇒ Action::Hook
Add a proc to be evaluated after a character executes an action.
-
#before_action(*verbs) {|| ... } ⇒ Action::Hook
Add a proc to be evaluated before a character executes an action.
-
#interpret(command, translation) ⇒ Syntax
Create an alternate Syntax for a response.
-
#meta(verb, *queries) {|| ... } ⇒ Symbol
Create a meta response for a command.
-
#respond(verb, *queries) {|| ... } ⇒ Symbol
Create a response to a command.
-
#synonyms ⇒ Array<Symbol>
Synonyms are a combination of the rulebook’s concrete verbs plus the alternative variants defined in syntaxes.
- #syntaxes ⇒ Array<Syntax>
-
#verbs ⇒ Array<Symbol>
Verbs are the symbols that have responses defined in the rulebook.
Methods included from Queries
#anywhere, #available, #children, #myself, #parent, #plaintext, #siblings
Methods included from Proxy
Instance Method Details
#after_action(*verbs) {|| ... } ⇒ Action::Hook
Add a proc to be evaluated after a character executes an action. When a verbs are specified, the proc will only be evaluated if the action’s verb matches them.
77 78 79 |
# File 'lib/gamefic/scriptable/actions.rb', line 77 def after_action *verbs, &block rulebook.hooks.after_action *verbs, &block end |
#before_action(*verbs) {|| ... } ⇒ Action::Hook
Add a proc to be evaluated before a character executes an action. When verbs are specified, the proc will only be evaluated if the action’s verb matches them.
66 67 68 |
# File 'lib/gamefic/scriptable/actions.rb', line 66 def before_action *verbs, &block rulebook.hooks.before_action *verbs, &block end |
#interpret(command, translation) ⇒ Syntax
Create an alternate Syntax for a response. The command and its translation can be parameterized.
95 96 97 |
# File 'lib/gamefic/scriptable/actions.rb', line 95 def interpret command, translation rulebook.calls.add_syntax Syntax.new(command, translation) end |
#meta(verb, *queries) {|| ... } ⇒ Symbol
Create a meta response for a command. Meta responses are very similar to standard responses, except they’re flagged as meta (‘Response#meta?`) to indicate that they provide a feature that is not considered an in-game action, such as displaying help documentation or a scoreboard.
53 54 55 56 57 |
# File 'lib/gamefic/scriptable/actions.rb', line 53 def (verb, *queries, &proc) args = map_response_args(queries) rulebook.calls.add_response Response.new(verb, rulebook.narrative, *args, meta: true, &proc) verb end |
#respond(verb, *queries) {|| ... } ⇒ Symbol
Create a response to a command. A Response uses the ‘verb` 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 is the proc to execute when the input matches all of the Response’s criteria (i.e., verb and queries).
32 33 34 35 36 |
# File 'lib/gamefic/scriptable/actions.rb', line 32 def respond(verb, *queries, &proc) args = map_response_args(queries) rulebook.calls.add_response Response.new(verb, rulebook.narrative, *args, &proc) verb end |
#synonyms ⇒ Array<Symbol>
Synonyms are a combination of the rulebook’s concrete verbs plus the alternative variants defined in syntaxes.
129 130 131 |
# File 'lib/gamefic/scriptable/actions.rb', line 129 def synonyms rulebook.synonyms end |
#syntaxes ⇒ Array<Syntax>
134 135 136 |
# File 'lib/gamefic/scriptable/actions.rb', line 134 def syntaxes rulebook.syntaxes end |
#verbs ⇒ Array<Symbol>
Verbs are the symbols that have responses defined in the rulebook.
111 112 113 |
# File 'lib/gamefic/scriptable/actions.rb', line 111 def verbs rulebook.verbs end |