Files
YataiDONNijiiro/Scripts/background/bg_objects/rank_badge.lua
T
2026-11-23 11:20:21 -05:00

54 lines
1.5 KiB
Lua

local ClipPlayer = require("game/clip_player")
local RankBadge = {}
RankBadge.__index = RankBadge
local THRESHOLDS = { 500000, 600000, 700000, 800000, 900000, 950000, 1000000 }
local PLATE_SHAPES = { 36, 38, 40, 42, 44, 46, 48 } -- rank 1..7
local BASE_SHAPE = 36
local POS = { [1] = { 152, 276 - 118 }, [2] = { 152, 276 + 646 } }
function RankBadge.rank_of(score)
local r = 0
for i, t in ipairs(THRESHOLDS) do
if score >= t then r = i end
end
return r
end
function RankBadge.available()
local ok, d = pcall(require, "game/ending_anim/rank_hud")
return ok and type(d) == "table" and d.frames ~= nil
end
function RankBadge.new(player_num, path)
local self = setmetatable({}, RankBadge)
local p = POS[player_num] or POS[1]
self.clip = ClipPlayer.new("game/ending_anim/rank_hud", path or "game", "rank_hud_anim", p[1], p[2])
if self.clip then self.clip.hold_last = true end
self.rank = 0
return self
end
function RankBadge:set_score(score, now)
local r = RankBadge.rank_of(score)
if r == self.rank then return end
self.rank = r
if r > 0 and self.clip then
self.clip.shape_map = { [BASE_SHAPE] = PLATE_SHAPES[r] }
self.clip:start(now)
end
end
function RankBadge:draw(now)
if self.clip and self.clip:started() and not self.clip:finished(now) then
self.clip:draw(now)
end
end
function RankBadge:destroy()
if self.clip then self.clip:destroy() end
end
return RankBadge