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

170 lines
3.8 KiB
Lua
Raw Normal View History

2021-09-16 22:29:36 +02:00
local GuiElements = require "birb.modules.gui.elements.parent"
local QteParent = GuiElements:extend()
2020-07-31 21:00:31 +02:00
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
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 = ""
2021-09-16 22:29:36 +02:00
QteParent.super.new(self, "qte", -1, -1, 1, 1)
self:start()
self.isStarted = true
self:getFocus()
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-09-16 22:29:36 +02:00
function QteParent:updateElement(dt)
QteParent.super.updateElement(self, dt)
self.prompts:update(dt)
end
function QteParent:keypressed(key)
self:verifyPrompts(key)
2020-07-31 21:00:31 +02:00
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-09-16 22:29:36 +02:00
self:destroy()
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-09-16 22:29:36 +02:00
function QteParent:verifyPrompts(key)
local promptResult = self.prompts:verifyPrompts(key)
2021-04-25 16:28:31 +02:00
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