sonic-radiance/sonic-radiance.love/scenes/battlesystem/choregraphy/qte/prompts/init.lua

66 lines
1.8 KiB
Lua
Raw Normal View History

2021-04-25 16:28:31 +02:00
local QtePrompts = Object:extend()
local Button = require "scenes.battlesystem.choregraphy.qte.prompts.button"
2021-04-25 16:28:31 +02:00
QtePrompts.BEGINTIME = 0.2
function QtePrompts:new(qte)
self.qte = qte
self.canPress = true
self.removeWhenPressed = true
self.assets = qte.choregraphy.assets
self.scene = core.scenemanager.currentScene
self.current = 1
2021-05-08 18:39:40 +02:00
self.defaultTimerValue = 1
2021-04-25 16:28:31 +02:00
self.list = {}
end
function QtePrompts:add(key, number)
table.insert(self.list, Button(self, key, number, QtePrompts.BEGINTIME))
end
function QtePrompts:getTimer()
2021-05-08 18:39:40 +02:00
local defaultValue = self.defaultTimerValue
2021-04-25 16:28:31 +02:00
local _, _, timerValue = self.qte:getTimerInfo()
return timerValue or defaultValue
end
function QtePrompts:update(dt)
for i, button in ipairs(self.list) do
button:update(dt, (i == self.current))
end
end
function QtePrompts:verifyPrompts()
local buttonValue, mustBeRemoved = 0, false
if (self.list[self.current] ~= nil) then
local keys = self.scene.sources[1].keys
buttonValue, mustBeRemoved = self.list[self.current]:verifyPrompts(keys, self.removeWhenPressed)
if (not self.canPress and buttonValue == 1) then
buttonValue = -1
end
if (mustBeRemoved) then
2021-05-08 18:39:40 +02:00
self.list[self.current]:finish(true)
2021-04-25 16:28:31 +02:00
self.current = self.current + 1
end
end
2021-05-08 18:39:40 +02:00
for i, button in ipairs(self.list) do
if (buttonValue == -1 and (i ~= self.current)) then
button:finish(false)
end
end
2021-04-25 16:28:31 +02:00
return buttonValue
end
function QtePrompts:isOver()
return (self.current > #self.list)
end
function QtePrompts:draw(x, y)
local SIZE = 20
for i, button in ipairs(self.list) do
button:draw(x + (SIZE*(i-1)) - ((SIZE/2)*(#self.list-1)), y, (i == self.current))
end
end
return QtePrompts