local reap = require("lib.reap")

local BASE = reap.base_path(...)
local image = require("love_src.wrapper.lappy.new.image").obj

local world = require("love_src.wrapper.Concord.world")

local debug_entity = require("love_src.src.world.common.template.debug_entity")
local book = require("love_src.src.world.common.template.book")

local animation = require("love_src.src.world.common.component.animation")
local transform = require("love_src.src.world.common.component.transform")

local wrapper = world:extend()

function wrapper:new()
  wrapper.super.new(self, BASE, ".race")
end

function wrapper:load(_args)
  wrapper.super.load(self, {
    "love_src/src/world/common/system/"
  }, {
    {
      assemblage = debug_entity.assembleDebug,
      data = {
        position = {0, 0},
        label = "race world"
      }
    },
    {
      assemblage = book.assemble,
      data = book.default_data
    }
  })
end

function wrapper:draw()
  wrapper.super.draw(self)

  for k, v in pairs(self.entities) do
    if v[animation.dict.frame_i] ~= nil then
      local frame_i = v[animation.dict.frame_i].data
      local img = v[animation.dict.image_frame].data.images
      if (img ~= nil) then
        love.graphics.draw(img[frame_i], v[transform.dict.position].data[1], v[transform.dict.position].data[2])
      end
    end
  end
end

return wrapper
