59 lines
1.9 KiB
Lua
59 lines
1.9 KiB
Lua
-- Ported from src/objects/title/attract_camera.cpp. Everything but the physical
|
|
-- webcam capture + its textured quad (the `camera.*` bindings, script.cpp) lives here:
|
|
-- the background/live-icon/live-text draw, the live-icon animation, and the
|
|
-- 30s-fallback finished-timer.
|
|
AttractCamera = {}
|
|
AttractCamera.__index = AttractCamera
|
|
|
|
function AttractCamera.new()
|
|
local self = setmetatable({}, AttractCamera)
|
|
self.start_ms = tex.get_current_ms()
|
|
self.finished = false
|
|
|
|
camera.open()
|
|
audio.play_sound("camera", "attract_mode")
|
|
|
|
self.live_icon_texture_change = tex.get_animation(36, "title")
|
|
self.live_icon_texture_change:start()
|
|
|
|
local ok, timer = pcall(tex.get_animation, 37, "title")
|
|
self.scene_timer = ok and timer or nil
|
|
if self.scene_timer then self.scene_timer:start() end
|
|
|
|
self.t_background = tex.get_texture("title/camera/background")
|
|
self.t_live_icon = tex.get_texture("title/camera/live_icon")
|
|
self.t_live_text = tex.get_texture("title/camera/live_text")
|
|
|
|
self.viewport = tex.get_skin_config("attract_camera_viewport")
|
|
|
|
return self
|
|
end
|
|
|
|
function AttractCamera:update(current_ms)
|
|
camera.update()
|
|
self.live_icon_texture_change:update(current_ms)
|
|
if self.scene_timer then
|
|
self.scene_timer:update(current_ms)
|
|
self.finished = self.scene_timer.is_finished
|
|
else
|
|
self.finished = (current_ms - self.start_ms >= 30000)
|
|
end
|
|
end
|
|
|
|
function AttractCamera:draw()
|
|
tex.draw_texture(self.t_background)
|
|
if self.viewport then
|
|
camera.draw(self.viewport.x, self.viewport.y, self.viewport.width, self.viewport.height)
|
|
end
|
|
tex.draw_texture(self.t_live_icon, { frame = math.floor(self.live_icon_texture_change.attribute) })
|
|
tex.draw_texture(self.t_live_text)
|
|
end
|
|
|
|
function AttractCamera:is_finished()
|
|
return self.finished
|
|
end
|
|
|
|
function AttractCamera:close()
|
|
camera.close()
|
|
end
|