class Gamefic::Dispatcher
The action executor for character commands.
Attributes
@return [Action, nil]
@return [Array<Action>]
Public Class Methods
Source
# File lib/gamefic/dispatcher.rb, line 8 def initialize(actionable) @actions = actionable.to_actions end
@param actionable [#to_actions]
Public Instance Methods
Source
# File lib/gamefic/dispatcher.rb, line 15 def execute return if action || actions.empty? @action = actions.shift Gamefic.logger.info "Dispatching #{actor.inspect} #{command.inspect}" run_hooks_and_response command end
Start executing actions in the dispatcher.
@return [Command, nil]
Source
# File lib/gamefic/dispatcher.rb, line 29 def proceed return if !action || command.cancelled? actions.shift&.execute end
Execute the next available action.
Actors should run execute
first.
@return [Action, nil]
Private Instance Methods
Source
# File lib/gamefic/dispatcher.rb, line 44 def actor action.actor end
@return [Actor, nil]
Source
# File lib/gamefic/dispatcher.rb, line 49 def command action.command end
@return [Command]
Source
# File lib/gamefic/dispatcher.rb, line 53 def run_hooks(list) list.each do |blk| blk[actor, command] break if command.cancelled? end end
Source
# File lib/gamefic/dispatcher.rb, line 60 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