sonic-radiance/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/parent.lua

169 lines
3.7 KiB
Lua
Raw Normal View History

2020-07-31 21:00:31 +02:00
local QteParent = Object:extend()
2021-05-08 19:10:30 +02:00
local TweenManager = require "birb.classes.time"
local Prompts = require "scenes.battlesystem.choregraphy.qte.prompts"
2021-04-25 12:18:53 +02:00
2020-07-31 21:00:31 +02:00
function QteParent:new(choregraphySystem, arguments)
self.choregraphy = choregraphySystem
self.arguments = arguments
2021-04-25 12:18:53 +02:00
self.tweens = TweenManager(self)
2020-07-31 21:00:31 +02:00
self.isBlocking = nil
2021-04-25 16:28:31 +02:00
self.prompts = Prompts(self)
2021-05-08 18:39:40 +02:00
self.timer = 0
self.timerActive = false
self.isSuccess = false
self.tag = ""
end
function QteParent:setTag(tag)
self.tag = tag
2020-07-31 21:00:31 +02:00
end
2021-04-25 12:18:53 +02:00
function QteParent:blockAction(action, isBlocked)
if (isBlocked) then
2020-07-31 21:00:31 +02:00
self.isBlocking = action
end
end
2021-05-08 18:39:40 +02:00
function QteParent:endQte()
self.choregraphy:endQte(self.isSuccess)
if (self.isBlocking ~= nil) then
self.isBlocking:getSignal("qteEnded")
end
if (not utils.string.isEmpty(self.tag)) then
self.choregraphy:finishTagAction(self.tag)
end
2021-05-08 18:39:40 +02:00
end
2020-07-31 21:00:31 +02:00
function QteParent:setOrigin(origin)
local x, y, z = 424/2, 240/2, 0
local argy = 16
2021-04-25 12:18:53 +02:00
local battleCoord = false
if (origin == "target") then
local target = self.choregraphy.action.target
x, y = target.actor:getCoordinate()
z = target.actor.z
2021-04-25 12:18:53 +02:00
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()
z = self.choregraphy.actor.z
2021-04-25 12:18:53 +02:00
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 - z
2021-04-25 12:18:53 +02:00
end
2020-07-31 21:00:31 +02:00
end
2021-07-18 18:26:15 +02:00
function QteParent:updateQte(dt, isActive)
2020-07-31 21:00:31 +02:00
if (not self.isStarted) then
self:start()
self.isStarted = true
else
self:update(dt)
2021-04-25 12:18:53 +02:00
self.tweens:update(dt)
2021-04-25 16:28:31 +02:00
self.prompts:update(dt)
2021-07-18 18:26:15 +02:00
if (isActive) then
self:verifyPrompts()
end
2020-07-31 21:00:31 +02:00
end
end
2021-04-25 12:18:53 +02:00
function QteParent:timerResponse(timer)
if (timer == "qteTimer") then
core.debug:print("qte", "Timer finished")
2021-05-08 18:39:40 +02:00
if (self.timerActive) then
self:finish(self:isSuccessOnEnd())
end
elseif (timer == "startTimer") then
core.debug:print("qte", "Timer started with " .. self.timer .. " seconds")
self.tweens:newTimer(self.timer, "qteTimer")
self.timerActive = true
self.prompts.defaultTimerValue = 0
elseif (timer == "endQte") then
2021-07-18 18:26:15 +02:00
self.choregraphy:removeQte()
2021-04-25 12:18:53 +02:00
end
2020-07-31 21:00:31 +02:00
end
2021-04-25 12:18:53 +02:00
function QteParent:finish(success)
2021-05-08 18:39:40 +02:00
self.isSuccess = success
self.timerActive = false
self.tweens:newTimer(self.prompts.BEGINTIME, "endQte")
2021-07-18 18:26:15 +02:00
self:endQte()
2020-07-31 21:00:31 +02:00
end
2021-04-25 16:28:31 +02:00
function QteParent:verifyPrompts()
local promptResult = self.prompts:verifyPrompts()
if (promptResult == 1) then
self:promptSuccess()
elseif (promptResult == -1) then
self:fail()
end
end
function QteParent:draw()
self:drawOverButtons()
self.prompts:draw(self.x, self.y)
self:drawUnderButtons()
end
2021-04-25 12:18:53 +02:00
-- USABLE FUNCTIONS
-- Use these functions to access some of the API
function QteParent:setTimer(time)
2021-05-08 18:39:40 +02:00
core.debug:print("qte", "Timer started with " .. time .. " prepared")
self.timer = time
self.tweens:newTimer(self.prompts.BEGINTIME, "startTimer")
2021-04-25 12:18:53 +02:00
end
function QteParent:delay(time)
core.debug:print("qte", "Timer delayed by " .. time .. " seconds")
self.tweens:delayTimer(time, "qteTimer", false)
end
function QteParent:getTimerInfo()
2021-04-25 16:28:31 +02:00
return self.tweens:getTimerInfo("qteTimer")
2021-04-25 12:18:53 +02:00
end
2020-07-31 21:00:31 +02:00
2021-04-25 16:28:31 +02:00
function QteParent:success()
2020-07-31 21:00:31 +02:00
self:finish(true)
end
function QteParent:fail()
self:finish(false)
end
2021-04-25 12:18:53 +02:00
-- PUBLIC API
-- The functions that the children must overrides
function QteParent:start()
end
function QteParent:update(dt)
--
end
2021-04-25 16:28:31 +02:00
function QteParent:promptSuccess()
end
2021-04-25 12:18:53 +02:00
function QteParent:isSuccessOnEnd()
return false
end
2021-04-25 16:28:31 +02:00
function QteParent:drawOverButtons()
end
function QteParent:drawUnderButtons()
2021-04-25 12:18:53 +02:00
2020-07-31 21:00:31 +02:00
end
return QteParent