Class: Gamefic::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/dispatcher.rb

Overview

The action executor for character commands.

Instance Method Summary collapse

Constructor Details

#initialize(actionable) ⇒ Dispatcher

Returns a new instance of Dispatcher.

Parameters:

  • actionable (#to_actions)


8
9
10
# File 'lib/gamefic/dispatcher.rb', line 8

def initialize(actionable)
  @actions = actionable.to_actions
end

Instance Method Details

#executeCommand?

Start executing actions in the dispatcher.

Returns:



15
16
17
18
19
20
21
22
# 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

#proceedAction?

Execute the next available action.

Actors should run #execute first.

Returns:



29
30
31
32
33
# File 'lib/gamefic/dispatcher.rb', line 29

def proceed
  return if !action || command.cancelled?

  actions.shift&.execute
end