Files
YataiDON14/Scripts/global/timer.lua
T
2026-11-22 19:25:31 -05:00

87 lines
3.1 KiB
Lua

Timer = {}
Timer.__index = Timer
function Timer.new(time, current_time_ms, confirm_func, is_frozen)
local self = setmetatable({}, Timer)
self.time = time
self.last_time = current_time_ms
self.confirm_func = confirm_func
self.is_frozen = is_frozen
self.is_finished = false
self.num_resize = tex.get_animation(9, "global")
self.highlight_resize = tex.get_animation(10, "global")
self.highlight_fade = tex.get_animation(11, "global")
self.t14 = {
disc = tex.get_texture("global/t14_counter/timer_disc"),
rim = tex.get_texture("global/t14_counter/timer_rim"),
glow = tex.get_texture("global/t14_counter/timer_glow"),
digits = tex.get_texture("global/t14_counter/timer_digits"),
}
return self
end
function Timer:update(current_ms)
if self.time == 0 and not self.is_finished and not audio.is_sound_playing("voice_timer_0") then
self.is_finished = true
self.confirm_func()
end
self.num_resize:update(current_ms)
self.highlight_resize:update(current_ms)
self.highlight_fade:update(current_ms)
if self.is_frozen then return end
if current_ms >= self.last_time + 1000 and self.time > 0 then
self.time = self.time - 1
self.last_time = current_ms
if self.time < 10 then
audio.play_sound("timer_blip", "sound")
self.num_resize:start()
self.highlight_fade:start()
self.highlight_resize:start()
end
if self.time == 10 then
audio.play_sound("voice_timer_10", "voice")
elseif self.time == 5 then
audio.play_sound("voice_timer_5", "voice")
elseif self.time == 0 then
audio.play_sound("voice_timer_0", "voice")
end
end
end
-- Taiko 14 time_counter.swg: the number in a dark disc at the top right, its glow ring swelling out once a second.
-- Positions are the swg's 640x480 px (K scales them).
local K = tex.get_screen_width() / 640
local DISC_CX, DISC_CY, DIGIT_Y, DIGIT_PITCH, DIGIT_W = 579.7, 41.7, 22, 25.25, 32
local GLOW_W = 80
function Timer:draw(x, y)
tex.draw_texture(self.t14.disc)
tex.draw_texture(self.t14.rim)
-- per second: grows 1.17 -> 1.6 fading out, rests, then swells back in for the next tick
local f = (tex.get_current_ms() - self.last_time) / (1000 / 60) % 60
local s, a
if f < 30 then s, a = 1.17 + 0.43 * f / 30, 0.48 * (1 - f / 30)
elseif f < 40 then s, a = 0.8, 0
else s, a = 0.8 + 0.37 * (f - 40) / 20, 0.48 * (f - 40) / 20 end
if a > 0 then
local w = GLOW_W * s * K
tex.draw_texture(self.t14.glow, { x = DISC_CX * K - w / 2, y = DISC_CY * K - w / 2,
x2 = GLOW_W * K * (s - 1), y2 = GLOW_W * K * (s - 1), fade = a })
end
local counter = tostring(self.time)
local left = DISC_CX - (DIGIT_PITCH * (#counter - 1) + DIGIT_W) / 2
for i = 1, #counter do
tex.draw_texture(self.t14.digits, { frame = string.byte(counter, i) - 48,
x = (left + (i - 1) * DIGIT_PITCH) * K, y = DIGIT_Y * K })
end
end