local main_wrapper = require "love_src.wrapper.lappy.world"
local vm     = require "lib.vornmath"
---@class wrappers.Concord.world : lappy.world
local world = main_wrapper:extend()

local reap = require("lib.reap")
local BASE = reap.base_path(...)

function world:new()
  world.super.new(self, BASE, "actor")
end

local default = {
  forward = 0.0,
  steer = 0.0
}

function world:load(entity, data)
  self.e = entity
  self.data = data or default
end

local function handle_input(v2, accel, brake, steer)
  local desire_forward = 0
  local desire_steer = 0
  if (v2[1] > 0) then
    desire_forward = accel
  elseif (v2[1] < 0) then
    desire_forward = - brake
  end
  if (v2[2] < 0) then
    desire_steer = steer
  elseif (v2[2] > 0) then
    desire_steer = - steer
  end
  return desire_forward, desire_steer
end

local function plan()
  return vm.vec2(1.0, 1.0)
end

function world:update(dt)
  local accel, brake, steer = self.e.components.racer.data.accel, self.e.components.racer.data.brake, self.e.components.racer.data.steer
  local plan_v = plan()
  local desire_forward, desire_steer = handle_input(plan_v, accel, brake, steer)

  self.data.forward = desire_forward
  self.data.steer = desire_steer
end

return world
