-- YataiDON-HSS child override of PyTaikoGreen/Scripts/global/timer.lua -- (ROUND 52, r52-lua-divergence-fixes). Byte-copy of the parent's drawing and -- tick logic; only the VOICE cue schedule changes, corrected against the -- arcade's own common/Timer.lua (the reference build script_lua; every call site Setup(9)): -- -- * timer_30sec at 30 s -- the parent had no 30 s cue at all -- (new sample: Sounds/global/voice_timer_30.ogg = voice_common_v12a -- timer_30sec, Timer.lua:91-93). -- * timer_10sec at 10 s / timer_05sec at 5 s -- kept, but with the arcade's -- pre-empt: a still-playing earlier voice is stopped first -- (Timer.lua:87-89 StopSlot on now_count 10 or 5). -- * NOTHING at 0. The cabinet stops any playing voice and StopCount()s -- (Timer.lua:106-112); the parent's voice_timer_0 is a Green-ism. The -- parent's finish gate ("wait until voice_timer_0 stops playing") is -- therefore replaced by an immediate finish, with any live voice cut. -- * the per-second red-zone blip (timer_count <= red_limit 9) is unchanged -- -- the parent's `time < 10` (9..0) already matches. -- -- audio.stop_sound is a ROUND 52 engine binding; every use is guarded so this -- file stays load-safe on an engine built before it. Timer = {} Timer.__index = Timer local function stop_voice(name) if audio.stop_sound and audio.is_sound_playing(name) then audio.stop_sound(name) end end local VOICES = { "voice_timer_30", "voice_timer_10", "voice_timer_5" } local function stop_all_voices() for _, v in ipairs(VOICES) do stop_voice(v) end end function Timer.new(time, current_time_ms, confirm_func, is_frozen) local self = setmetatable({}, Timer) self.time = time self.last_time = current_time_ms self.confirm_func = confirm_func self.is_frozen = is_frozen self.is_finished = false self.bg = tex.load_texture("global/timer/bg") self.bg_red = tex.load_texture("global/timer/bg_red") self.counter_black = tex.load_texture("global/timer/counter_black") self.counter_white = tex.load_texture("global/timer/counter_white") self.highlight = tex.load_texture("global/timer/highlight") self.num_resize = tex.get_animation(9, "global") self.highlight_resize = tex.get_animation(10, "global") self.highlight_fade = tex.get_animation(11, "global") self.margin = tex.get_skin_config("timer_text_margin").x return self end function Timer:update(current_ms) -- Arcade Timer.lua:106-112 -- reaching 0 stops any playing voice and -- StopCount()s at once; nothing is spoken and nothing is waited for. if self.time == 0 and not self.is_finished then self.is_finished = true stop_all_voices() self.confirm_func() end self.num_resize:update(current_ms) self.highlight_resize:update(current_ms) self.highlight_fade:update(current_ms) if self.is_frozen then return end if current_ms >= self.last_time + 1000 and self.time > 0 then self.time = self.time - 1 self.last_time = current_ms if self.time < 10 then audio.play_sound("timer_blip", "sound") self.num_resize:start() self.highlight_fade:start() self.highlight_resize:start() end if self.time == 30 then audio.play_sound("voice_timer_30", "voice") elseif self.time == 10 then -- Timer.lua:87-89: pre-empt a still-running earlier voice. stop_voice("voice_timer_30") audio.play_sound("voice_timer_10", "voice") elseif self.time == 5 then stop_voice("voice_timer_30") stop_voice("voice_timer_10") audio.play_sound("voice_timer_5", "voice") end end end function Timer:draw(x, y) local counter = tostring(self.time) local counter_tex if self.time < 10 then tex.draw_texture(self.bg_red) counter_tex = self.counter_white tex.draw_texture(self.highlight, { scale = self.highlight_resize.attribute, center = true, fade = self.highlight_fade.attribute, }) else tex.draw_texture(self.bg) counter_tex = self.counter_black end local total_width = #counter * self.margin for i = 1, #counter do local digit = string.byte(counter, i) - string.byte("0") tex.draw_texture(counter_tex, { frame = digit, scale = self.num_resize.attribute, center = true, x = -(total_width / 2) + ((i - 1) * self.margin), }) end end