class Gamefic::Dispatcher


The action executor for character commands.

def actor

Returns:
  • (Actor, nil) -
def actor
  action.actor
end

def command

Returns:
  • (Command) -
def command
  action.command
end

def execute

Returns:
  • (Command, nil) -
def execute
  return if action || actions.empty?
  @action = actions.shift
  Gamefic.logger.info "Dispatching #{actor.inspect} #{command.inspect}"
  run_hooks_and_response
  command
end

def initialize(actionable)

Parameters:
  • actionable (#to_actions) --
def initialize(actionable)
  @actions = actionable.to_actions
end

def proceed

Returns:
  • (Action, nil) -
def proceed
  return if !action || command.cancelled?
  actions.shift&.execute
end

def run_hooks(list)

def run_hooks(list)
  list.each do |blk|
    blk[actor, command]
    break if command.cancelled?
  end
end

def run_hooks_and_response

def run_hooks_and_response
  run_hooks actor.narratives.before_commands
  command.freeze
  return if command.cancelled?
  action.execute
  run_hooks actor.narratives.after_commands
end