-- On charge le module de scene et créer l'objet de scene des niveaux
local Scene       = require "core.modules.scenes"
local Level       = Scene:extend()

-- Chargement des controllers
local World   = require "scenes.levels.world"

local leveldatas  = require "datas.levels"

-- INIT FUNCTIONS
-- Initialize and launch the level

function Level:new(levelID, missionID)
  self:reset()
  Level.super.new(self)
  self.assets:batchImport("scenes.levels.assets")
  previousMenu = previous
  self:loadMission(levelID, missionID)

  self:register()
end

function Level:reset()
  self.datas        = {}

  self.pause        = false
  self.map          = nil
  self.backcolor    = {0, 0, 0}

end

function Level:loadMission(levelID, missionID)
  local datas, missiondatas
  self.datas = require("datas.levels." .. levelID)

  local mapfile = "assets/maps/" .. self.datas.mapfile .. ".lua"
  self.world = World(self, mapfile, "scenes.levels.entities")
  self.world:loadMap()
  self.assets:setMusic("assets/music/" .. self.datas.music)

  self:launchMission()
end

function Level:launchMission()
  self.assets:silence()
  self.assets:playMusic()

end


-- UPDATE FUNCTIONS
-- Update the level

function Level:update(dt)
  local keys = self.sources[1].keys

  if keys["start"].isPressed then
    self.world:setActivity(self.pause)
    self.assets:setActivity(self.pause)
    self.pause = (self.pause == false)
  end
end

-- DRAW FUNCTIONS
-- draw level elements

function Level:draw(dt)
  utils.graphics.resetColor()
end

function Level:exit()
  self.controller:reset()
end

return Level
