Files
YataiDONNijiiro/Scripts/title/attract_announce.lua
T
2026-12-05 17:01:32 -05:00

56 lines
1.8 KiB
Lua

-- the parent skin's copy of a script: the second match on package.path (the first is this file)
local function load_parent(name)
local seen = false
for tmpl in package.path:gmatch("[^;]+") do
local chunk = loadfile((tmpl:gsub("%?", name)))
if chunk then
if seen then return chunk end
seen = true
end
end
end
local parent = load_parent("title/attract_announce")
if parent then parent() end
local ParentAnnounce = AttractAnnounce
AttractAnnounce = {}
AttractAnnounce.__index = AttractAnnounce
local F = 1000 / 60
local IN_F, LOOP_F = 20, 200
local BANNERS = {
touhou = { "touhou_marisa", "touhou_reimu" },
imas15 = { "imas15" },
}
-- mode: "campaign" | "tournament"; campaigns: the cabinet's active campaign ids
function AttractAnnounce.new(mode, campaigns)
local self = setmetatable({}, AttractAnnounce)
local names = mode == "tournament" and { "tournament" } or {}
if mode == "campaign" then
for _, id in ipairs(campaigns or {}) do
for _, name in ipairs(BANNERS[id] or {}) do names[#names + 1] = name end
end
end
-- the parent's new() sets the global class as metatable, which is this one by now
if #names == 0 and ParentAnnounce then return setmetatable(ParentAnnounce.new(mode, campaigns), ParentAnnounce) end
self.banners = {}
for _, name in ipairs(names) do self.banners[#self.banners + 1] = tex.get_texture("title/banner/" .. name) end
self.t0 = nil
self.f = 0
return self
end
function AttractAnnounce:update(current_ms)
self.t0 = self.t0 or current_ms
self.f = (current_ms - self.t0) / F
end
function AttractAnnounce:draw(fade)
if #self.banners == 0 or self.f < IN_F then return end
local i = math.floor((self.f - IN_F) / LOOP_F) % #self.banners + 1
tex.draw_texture(self.banners[i], { fade = fade or 1 })
end