feat: initial qte parent

This commit is contained in:
Kazhnuz 2021-04-25 12:18:53 +02:00
parent 4184ef37a8
commit e3acafc824

View file

@ -1,57 +1,83 @@
local QteParent = Object:extend() local QteParent = Object:extend()
local TweenManager = require "game.modules.tweenmanager"
function QteParent:new(choregraphySystem, arguments) function QteParent:new(choregraphySystem, arguments)
self.choregraphy = choregraphySystem self.choregraphy = choregraphySystem
self.arguments = arguments self.arguments = arguments
self.timer = 0 self.tweens = TweenManager(self)
self.origin = nil
self.isBlocking = nil self.isBlocking = nil
end end
function QteParent:blockAction(action, blockProcess) function QteParent:blockAction(action, isBlocked)
if (blockProcess) then if (isBlocked) then
self.isBlocking = action self.isBlocking = action
end end
end end
function QteParent:setOrigin(origin) function QteParent:setOrigin(origin)
self.origin = origin local x, y = 424/2, 240/2
local argy = 24
local battleCoord = false
if (origin == "target") then
local target = self.choregraphy.action.target
x, y = target.actor:getCoordinate()
battleCoord = true
elseif (origin == "start") then
x, y = self.choregraphy.actor.start.x, self.choregraphy.actor.start.y
battleCoord = true
elseif (origin == "actor") then
x, y = self.choregraphy.actor:getCoordinate()
battleCoord = true
end
if (not battleCoord) then
self.x, self.y = x, y
else
x, y = self.choregraphy.world.map:gridToPixel(x, y, true)
self.x, self.y = x, y - argy
end
end end
function QteParent:drawButton(x, y, letter) function QteParent:updateQte(dt)
local grayValue = .44
local darkValue = .11
love.graphics.setColor(grayValue, grayValue, grayValue, 1)
love.graphics.circle("fill", x, y, 8, 8)
love.graphics.setColor(darkValue, darkValue, darkValue, 1)
love.graphics.circle("line", x, y, 8, 8)
love.graphics.print(letter, x, y)
utils.graphics.resetColor()
end
function QteParent:updateStep(dt)
if (not self.isStarted) then if (not self.isStarted) then
self:start() self:start()
self.isStarted = true self.isStarted = true
else else
self:update(dt) self:update(dt)
self:updateTimer(dt) self.tweens:update(dt)
end end
end end
function QteParent:update(dt) function QteParent:timerResponse(timer)
-- if (timer == "qteTimer") then
end core.debug:print("qte", "Timer finished")
self:finish(self:isSuccessOnEnd())
function QteParent:updateTimer(dt)
if (self.arguments.duration ~= nil) then
self.timer = self.timer + dt
if (self.timer > self.arguments.duration) then
self:fail()
end
end end
end end
function QteParent:finish(success)
self.choregraphy:endQte(success)
if (self.isBlocking ~= nil) then
self.isBlocking:getSignal("qteEnded")
end
end
-- USABLE FUNCTIONS
-- Use these functions to access some of the API
function QteParent:setTimer(time)
core.debug:print("qte", "Timer started with " .. time .. " seconds")
self.tweens:newTimer(time, "qteTimer")
end
function QteParent:delay(time)
core.debug:print("qte", "Timer delayed by " .. time .. " seconds")
self.tweens:delayTimer(time, "qteTimer", false)
end
function QteParent:getTimerInfo()
self.tweens:getTimerInfo("qteTimer")
end
function QteParent:succes() function QteParent:succes()
self:finish(true) self:finish(true)
@ -61,11 +87,23 @@ function QteParent:fail()
self:finish(false) self:finish(false)
end end
function QteParent:finish(success) -- PUBLIC API
self.choregraphy:endQte(success) -- The functions that the children must overrides
if (self.isBlocking ~= nil) then
self.isBlocking:finish() function QteParent:start()
end
end
function QteParent:update(dt)
--
end
function QteParent:isSuccessOnEnd()
return false
end
function QteParent:draw()
end end
return QteParent return QteParent