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

274 lines
10 KiB
Lua

TotalResult = {}
TotalResult.__index = TotalResult
-- Taiko 14 total_result.swg (1P layout): the credit's Don points count up, then the title ladder rolls to a
-- rank (average points per song, 50 a step). Positions are the swg's 640x480 px (K scales them), times are
-- 60 fps frames.
local PATH = "total_result/sogo/"
local FRAME_MS = 1000 / 60
local TOMOE_IN = 60
local TEAL_RISE, DON_JUMP_AT, DON_LAND_AT = 20, 20, 58
local RED_AT = 30
local PANEL_AT, COUNT_AT, COUNT_LEN = 40, 60, 160
local MERGE_AT = COUNT_AT + COUNT_LEN
local LADDER_AT = MERGE_AT + 30
local ROLL_AT = LADDER_AT + 12
local CELEBRATE_LEN, OUT_AFTER, OUT_LEN = 300, 300, 20
local RANK_STEP, RANKS = 50, 10
local CURSOR_Y, PLATE_GAP = 279.4, 50
local DIGIT_X, DIGIT_PITCH, DIGIT_Y = 188.7, 28.17, 231.9
local TOMOE_X, TOMOE_Y = 470, 240
local function clamp(v, lo, hi) return math.max(lo, math.min(hi, v)) end
local function lerp(a, b, p) return a + (b - a) * p end
local function ease_in(p) return p * p end
local function ease_out(p) return 1 - (1 - p) * (1 - p) end
local function seg(t, from, len) return clamp((t - from) / len, 0, 1) end
local function snd(name, kind)
if audio.has_sound(name) then audio.play_sound(name, kind or "sound") end
end
function TotalResult.new(data)
local self = setmetatable({}, TotalResult)
self.K = tex.get_screen_width() / 640
self.tex, self.info = {}, {}
for _, name in ipairs({ "back", "top_bar", "header", "tomoe", "ladder_bar", "ladder_cursor", "rank", "rank_reached",
"total_panel", "coin", "digits", "point_mark", "drum_red", "drum_teal", "bachi_left",
"bachi_dance", "bachi_cheer", "don" }) do
self.tex[name] = tex.get_texture(PATH .. name)
local info = tex.get_texture_info("sogo", name)
self.info[name] = info and { info.x[1] or 0, info.y[1] or 0, info.x2[1] or 0, info.y2[1] or 0 }
or { 0, 0, 0, 0 }
end
local player = data.players[1] or data.players[2]
local total, songs = 0, 0
if player then
for _, song in ipairs(player.songs) do
total = total + song.points
songs = songs + 1
end
end
self.total = total
self.rank = songs > 0 and clamp(math.floor(total / songs / RANK_STEP), 0, RANKS - 1) or 0
self.roll_len = math.max(20, self.rank * 6)
self.settle_at = ROLL_AT + self.roll_len + 12
self.t0 = nil
self.f = 0
self.offset = 0
self.out_at = nil
self.done = false
self.fired = {}
snd("bgm", "music")
return self
end
function TotalResult:tl(name, x, y, o)
o = o or {}
local t = self.tex[name]
if not t then return end
local i = self.info[name]
local sx, sy = o.sx or o.s or 1, o.sy or o.s or 1
tex.draw_texture(t, { frame = o.frame or 0, x = x * self.K - i[1], y = y * self.K - i[2], x2 = i[3] * (sx - 1),
y2 = i[4] * (sy - 1), fade = o.fade, color = o.color, blend = o.blend })
end
function TotalResult:ctr(name, cx, cy, o)
o = o or {}
local t = self.tex[name]
if not t then return end
local i = self.info[name]
local s = o.s or 1
tex.draw_texture(t, { frame = o.frame or 0, x = cx * self.K - i[1], y = cy * self.K - i[2], x2 = i[3] * (s - 1),
y2 = i[4] * (s - 1), origin = { i[3] * s / 2, i[4] * s / 2 }, rotation = o.rot or 0,
fade = o.fade })
end
function TotalResult:once(key, cond, fn)
if cond and not self.fired[key] then
self.fired[key] = true
fn()
end
end
function TotalResult:update(current_ms)
if not self.t0 then self.t0 = current_ms end
self.f = (current_ms - self.t0) / FRAME_MS + self.offset
local f = self.f
self:once("intro", f >= 10, function() snd("voice_intro", "voice") end)
local tick = math.floor((f - COUNT_AT) / 4)
if f >= COUNT_AT and f < MERGE_AT and tick ~= self.tick then
self.tick = tick
snd("count")
end
self:once("merge", f >= MERGE_AT, function() snd("merge") end)
self:once("slide", f >= ROLL_AT, function() snd("slide") end)
self:once("set", f >= self.settle_at, function()
snd("set")
snd("rank_" .. self.rank, "voice")
end)
self:once("title", f >= self.settle_at + 90, function() snd("voice_title", "voice") end)
self:once("thanks", f >= self.settle_at + 150, function() snd("voice_thanks", "voice") end)
if not self.out_at and f >= self.settle_at + OUT_AFTER then self.out_at = f end
if self.out_at and f >= self.out_at + OUT_LEN then
if audio.is_sound_playing("bgm") then audio.stop_sound("bgm") end
self.done = true
end
end
-- first press jumps to the title, the next one leaves
function TotalResult:skip()
if self.out_at then return false end
if self.f < self.settle_at then
self.offset = self.offset + (self.settle_at - self.f)
for _, key in ipairs({ "intro", "merge", "slide" }) do self.fired[key] = true end
else
self.out_at = self.f
end
return true
end
function TotalResult:is_done() return self.done end
function TotalResult:nameplate() return 0 end
function TotalResult:draw_back()
local f = self.f
self:tl("back", 0, 0)
local p = seg(f, 0, TOMOE_IN)
self:ctr("tomoe", TOMOE_X, TOMOE_Y, { s = lerp(1.988, 1, ease_out(p)), rot = 2 * f, fade = p })
self:tl("top_bar", 0, -1)
self:tl("header", 22, 62, { fade = seg(f, 10, 15) })
end
function TotalResult:celebrating()
return self.f >= self.settle_at and self.f < self.settle_at + CELEBRATE_LEN
end
function TotalResult:draw_don()
local f = self.f
local drum_y = lerp(492, 434, seg(f, 0, TEAL_RISE))
local bounce = 0
if f >= 60 and f < 70 then bounce = 4 * math.sin(math.pi * (f - 60) / 10) end
self:tl("drum_teal", 39.5, drum_y + bounce)
if f < DON_JUMP_AT then return end
if f < DON_LAND_AT then
local p = (f - DON_JUMP_AT) / (DON_LAND_AT - DON_JUMP_AT)
local x = lerp(-213.4, 62.3, p)
local y = lerp(340.6, 264.4, p) - 250 * p * (1 - p) * 1.0
self:tl("don", x, y, { frame = 0, s = 0.8 })
return
end
local frame, y, sy = 1, 275.6 + bounce, 0.8
if self:celebrating() then
local e = f - self.settle_at
if e < 72 then
frame = 2 + math.floor(e / 4) % 18
sy = 0.8 - 0.04 * math.sin(math.pi * (e % 18) / 18)
y = 275.6 + 8 * math.sin(math.pi * (e % 18) / 18)
end
end
self:tl("don", 62.6, y, { frame = frame, sx = 0.8, sy = sy })
end
function TotalResult:draw_bachi()
local f = self.f
if f < RED_AT then return end
local e = f - RED_AT
local y
if e < 16 then y = lerp(426, 308.3, ease_out(e / 16))
elseif e < 22 then y = lerp(308.3, 340.8, ease_in((e - 16) / 6))
elseif e < 30 then y = lerp(340.8, 316.4, ease_out((e - 22) / 8))
else y = 316.4 end
local dy = y - 316.4
if self:celebrating() then
local c = f - self.settle_at
self:tl("bachi_cheer", 304, 137 + 4 * math.sin(math.pi * c / 31.5), { frame = math.floor(c / 9) % 7 })
else
self:tl("bachi_left", 391.5, 207.1 + dy)
local frame = math.floor(f / 10) % 10
self:tl("bachi_dance", 454.5, 207.1 + dy, { frame = frame })
end
self:tl("drum_red", 349.5, y)
end
function TotalResult:draw_total()
local f = self.f
if f < PANEL_AT or f >= MERGE_AT + 40 then return end
local x, fade = 176.7, seg(f, PANEL_AT, 8)
local m = f - MERGE_AT
if m >= 0 then
x = m < 20 and lerp(176.7, 137.2, ease_out(m / 20)) or lerp(137.2, 336.6, ease_in((m - 20) / 20))
fade = 1 - seg(m, 20, 20)
end
self:tl("total_panel", x, 181.5, { fade = fade })
local c = f - PANEL_AT
if c < 20 then
local hop = c < 5 and lerp(171.5, 92.8, ease_out(c / 5)) or lerp(92.8, 171.5, ease_in((c - 5) / 15))
self:tl("coin", 167.3 + (x - 176.7), hop, { frame = math.floor(c) % 16, fade = 1 - seg(c, 12, 8) })
end
local shown = math.floor(self.total * ease_out(seg(f, COUNT_AT, COUNT_LEN)))
if m >= 0 then shown = self.total end
local str = tostring(shown)
local dx, dy, flash = x - 176.7, 0, 0
if m >= 0 then
local p = seg(m, 10, 15)
dx, dy, flash = dx + 240 * ease_in(p), -60 * ease_in(p), seg(m, 0, 10)
end
local dfade = m >= 0 and 1 - seg(m, 22, 4) or fade
for i = 1, #str do
local slot = 8 - #str + i
local dx_i = DIGIT_X + (slot - 1) * DIGIT_PITCH + dx
self:tl("digits", dx_i, DIGIT_Y + dy, { frame = tonumber(str:sub(i, i)), s = 0.95, fade = dfade })
if flash > 0 then
self:tl("digits", dx_i, DIGIT_Y + dy, { frame = tonumber(str:sub(i, i)), s = 0.95, fade = flash * dfade,
blend = "additive" })
end
end
self:tl("point_mark", 414 + dx, 230.1 + dy, { s = 0.95, fade = dfade })
end
function TotalResult:draw_ladder()
local f = self.f
if f < LADDER_AT then return end
local fade = seg(f, LADDER_AT, 10)
local level = 0
if f >= ROLL_AT then
local e = f - ROLL_AT
if e < self.roll_len then
level = (self.rank + 0.35) * ease_out(e / self.roll_len)
else
level = lerp(self.rank + 0.35, self.rank, ease_out(seg(e, self.roll_len, 12)))
end
end
for i = 0, RANKS - 1 do
local y = CURSOR_Y + (level - i) * PLATE_GAP
if y > 100 and y < 480 then
local reached = i < level - 0.5
self:tl("ladder_bar", 168, y, { frame = reached and 0 or 1, fade = fade })
self:tl(reached and "rank_reached" or "rank", 232, y + 20, { frame = i, fade = fade })
end
end
self:tl("ladder_cursor", 168, CURSOR_Y, { fade = fade })
local s = 1
if f >= self.settle_at then
local e = f - self.settle_at
s = e < 6 and lerp(1.6, 1, ease_in(e / 6)) or 1
end
local shown = clamp(math.floor(level + 0.5), 0, RANKS - 1)
self:ctr("rank", 232 + 88, CURSOR_Y + 20 + 16, { frame = shown, s = s, fade = fade })
end
function TotalResult:draw()
self:draw_back()
self:draw_ladder()
self:draw_total()
self:draw_bachi()
self:draw_don()
if self.out_at then
local fade = seg(self.f, self.out_at, OUT_LEN)
tex.draw_rect(0, 0, tex.get_screen_width(), tex.get_screen_height(), 0, 0, 0, math.floor(fade * 255))
end
end