sonic-radiance/sonic-radiance.love/game/events/init.lua
2021-03-20 21:08:54 +01:00

72 lines
1.6 KiB
Lua

local EventManager = Object:extend()
local stepObjectList = require "game.events.event"
local eventUtils = require "game.events.utils"
function EventManager:new(scene)
self.scene = scene
self.world = scene.world
self.isStarted = false
self.currentStepId = 0
self.currentStep = nil
self.stepList = {}
end
function EventManager:startEvent(owner, stepList)
self.stepList = stepList
self.owner = owner
self.isStarted = true
self.currentStepId = 0
self.currentStep = nil
self.scene:startEvent()
end
function EventManager:update(dt)
if (self.isStarted) then
if (self.currentStep ~= nil) then
self.currentStep:updateStep(dt)
else
self:switchStep()
end
end
end
function EventManager:switchStep()
if self:haveNextStep() then
self.currentStepId = self.currentStepId + 1
local stepData = eventUtils.getStepDatas(self.stepList[self.currentStepId])
core.debug:print("event", "Starting step " .. stepData.name)
if (stepObjectList[stepData.name] ~= nil) then
self.currentStep = stepObjectList[stepData.name](self, stepData.arguments)
end
else
self:endEvent()
end
end
function EventManager:endStep()
self.currentStep = nil
end
function EventManager:endEvent()
core.debug:print("event", "Ending event, giving back controle")
self.scene:endEvent()
self.isStarted = false
end
function EventManager:haveNextStep()
return ((self.currentStepId + 1) <= #self.stepList)
end
function EventManager:draw()
if (self.isStarted) then
if (self.currentStep ~= nil) then
self.currentStep:draw()
end
end
end
return EventManager