Files
YataiDON14/Scripts/global/t14_clip.lua
T
2026-10-02 14:07:44 +08:00

43 lines
1.3 KiB
Lua

local M = {}
-- clip = { frames = {...}, size = { {w, h}, ... }, tex = "screen/subset/" }
function M.new(clip)
return setmetatable({ clip = clip, cache = {} }, { __index = M })
end
function M:texture(i)
local t = self.cache[i]
if t == nil then
t = tex.get_texture(string.format("%st%02d", self.clip.tex, i)) or false
self.cache[i] = t
end
return t or nil
end
-- frame index (1-based), alpha multiplier; the movie's 640 px width fills the screen
function M:draw(i, fade)
local ops = self.clip.frames[i]
if not ops then return end
local K = tex.get_screen_width() / 640
fade = fade or 1
for n = 1, #ops, 11 do
local id = ops[n]
local t = self:texture(id)
if t then
local sz = self.clip.size[id + 1]
tex.draw_texture(t, {
x = ops[n + 1] * K, y = ops[n + 2] * K,
x2 = ops[n + 3] * K - sz[1], y2 = ops[n + 4] * K - sz[2],
rotation = ops[n + 5], mirror = (ops[n + 6] == 1) and "vertical" or nil,
fade = ops[n + 7] * fade,
color = { math.floor(ops[n + 8] * 255 + 0.5), math.floor(ops[n + 9] * 255 + 0.5),
math.floor(ops[n + 10] * 255 + 0.5), 255 },
})
end
end
end
function M:count() return #self.clip.frames end
return M