class Gamefic::Response
queries.
A proc to be executed in response to a command that matches its verb and
def accept?(actor, command)
-
command
(Command
) -- -
actor
(Active
) --
def accept?(actor, command) command.verb == verb && command.arguments.length == queries.length && queries.zip(command.arguments).all? { |query, argument| query.accept?(actor, argument) } end
def bind(narrative)
def bind(narrative) clone.inject_binding narrative end
def bound?
def bound? !!gamefic_binding.narrative end
def calculate_precision
-
(Integer)
-
def calculate_precision total = queries.sum(&:precision) total -= 1000 unless verb total end
def execute *args
def execute *args Gamefic.logger.warn "Executing unbound response #{inspect}" unless bound? gamefic_binding.call(*args) end
def gamefic_binding
def gamefic_binding @gamefic_binding ||= Binding.new(nil, @block) end
def generate_default_syntax
def generate_default_syntax args = queries.length.times.map { |num| num.zero? ? ':var' : ":var#{num + 1}" } tmpl = "#{verb} #{args.join(' ')}".strip Syntax.new(tmpl, tmpl) end
def initialize verb, *queries, meta: false, &block
-
meta
(Boolean
) -- -
queries
(Array
) -- -
verb
(Symbol
) --
def initialize verb, *queries, meta: false, &block @verb = verb&.to_sym @meta = meta @block = block @queries = map_queries(queries) end
def inject_binding(narrative)
def inject_binding(narrative) @queries = map_queries(narrative.unproxy(@queries)) @gamefic_binding = Binding.new(narrative, @block) self end
def inspect
def inspect "#<#{self.class} #{([verb] + queries).map(&:inspect).join(', ')}>" end
def map_queries(args)
def map_queries(args) args.map { |arg| select_query(arg) } end
def meta?
listing credits.
responses can include features like displaying help documentation or
serve a purpose other than performing in-game actions. Out-of-game
The `meta?` flag is just a way for authors to identify responses that
def meta? @meta end
def precision
-
(Integer)
-
Other tags:
- Note: - Precision is decreased if the response has a nil verb.
def precision @precision ||= calculate_precision end
def select_query(arg)
def select_query(arg) case arg when Entity, Class, Module, Proc, Proxy::Base available(arg) when String, Regexp plaintext(arg) when Query::Base arg else raise ArgumentError, "invalid argument in response: #{arg.inspect}" end end
def syntax
def syntax @syntax ||= generate_default_syntax end