room/day: add animation to text

This commit is contained in:
Franzi 2023-09-30 09:47:09 +02:00
parent 17992f7283
commit 4e15583b4e

View file

@ -308,37 +308,58 @@ end
local function view_room(starts, ends, config, x1, y1, x2, y2)
local font_size = config.font_size or 70
local align = config.room_align or "left"
local r,g,b = helper.parse_rgb(config.color or "#ffffff")
local default_color = {helper.parse_rgb(config.color or "#ffffff")}
for now in api.frame_between(starts, ends) do
local x = x1
local a = anims.Area(x2 - x1, y2 - y1)
local S = starts
local E = ends
local function text(...)
return a.add(anims.moving_font(S, E, font, ...))
end
local x = 0
local w = font:width(current_room, font_size)
if align == "right" then
x = x2 - w
x = a.width - w
elseif align == "center" then
x = (x1 + x2 - w) / 2
x = (a.width - w) / 2
end
font:write(x, y1, current_room, font_size, r,g,b)
text(x, 0, current_room, font_size, rgba(default_color,1))
for now in api.frame_between(starts, ends) do
a.draw(now, x1, y1, x2, y2)
end
end
local function view_day(starts, ends, config, x1, y1, x2, y2)
local font_size = config.font_size or 70
local r,g,b = helper.parse_rgb(config.color or "#ffffff")
local align = config.day_align or "left"
local template = config.day_template or "Day %d"
local default_color = {helper.parse_rgb(config.color or "#ffffff")}
for now in api.frame_between(starts, ends) do
local x = x1
local a = anims.Area(x2 - x1, y2 - y1)
local S = starts
local E = ends
local function text(...)
return a.add(anims.moving_font(S, E, font, ...))
end
local x = 0
local line = string.format(template, day)
local w = font:width(line, font_size)
if align == "right" then
x = x2 - w
x = a.width - w
elseif align == "center" then
x = (x1 + x2 - w) / 2
x = (a.width - w) / 2
end
font:write(x, y1, line, font_size, r,g,b)
text(x, 0, line, font_size, rgba(default_color,1))
for now in api.frame_between(starts, ends) do
a.draw(now, x1, y1, x2, y2)
end
end