class Tataru::Runner

thing that runs a quest

Attributes

memory[R]
oplog[R]

Public Class Methods

new(instruction_list) click to toggle source
# File lib/tataru/runner.rb, line 8
def initialize(instruction_list)
  @memory = Memory.new
  @instruction_list = instruction_list
  @oplog = []
end

Public Instance Methods

current_state() click to toggle source
# File lib/tataru/runner.rb, line 46
def current_state; end
ended?() click to toggle source
# File lib/tataru/runner.rb, line 14
def ended?
  @memory.program_counter >= @instruction_list.length ||
    !@memory.error.nil? ||
    @memory.end
end
log_operation(instr) click to toggle source
# File lib/tataru/runner.rb, line 20
def log_operation(instr)
  return unless instr.is_a? Instructions::ResourceInstruction

  oplog << {
    operation: instr.class.name.underscore
                    .sub(%r{^tataru/instructions/}, '')
                    .sub(/_instruction$/, '').upcase.to_s,
    resource: (memory.hash[:temp][:resource_name]).to_s
  }
end
run_next() click to toggle source
# File lib/tataru/runner.rb, line 31
def run_next
  return if ended?

  instr = @instruction_list[@memory.program_counter]

  log_operation(instr)

  instr.execute(@memory)
  @memory.program_counter += 1
rescue RuntimeError => e
  @memory.error = e
rescue StandardError => e
  @memory.error = e
end