local reap = require("lib.reap")

local BASE = reap.base_path(...)

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

local debug_entity = require("love_src.src.world.common.template.debug_entity")
local button = require("love_src.src.world.common.template.button")
local video = require("love_src.src.world.common.template.video")
local c_video = require("love_src.src.world.common.component.video")
local wm = require("world_map")

local wrapper = world:extend()

local function button_func()
  load_world(wm["2_town_square"])
end

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

function wrapper:load(_args)
  wrapper.super.load(self, {
    "love_src/src/world/common/system/"
  }, {
    {
      assemblage = debug_entity.assembleDebug,
      data = {
        position = {0, 0},
        label = "1_intro"
      }
    },
    {
      assemblage = button.assemble,
      data = {
        collider = {
          x = 20,
          y = 20,
          w = 20,
          h = 20
        },
        func = button_func,
        label = "skip"
      }
    },
    {
      assemblage = video.assemble,
      data = {
        path = "love_src/asset/video/1_intro.ogv"
      }
    }
  })
end

function wrapper:update(dt)
  wrapper.super.update(self, dt)
  for k, v in pairs(self.entities) do
    local c_v = v[c_video.dict.video]
    if c_v ~= nil then
      if (not c_v.data.video:isPlaying()) then
        load_world(wm["2_town_square"])
      end
    end
  end
end

return wrapper
