From c39e0ece3506f147d888685c67fcfecc82a837c5 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 3 Mar 2026 20:05:49 +0100 Subject: [PATCH] move meter to system (temporary) --- impostor.inc | 2 +- inc/screen/screen.toilet.lua | 2 +- inc/system/system.day.lua | 7 +++++++ .../system.meter.lua} | 15 +++++++++++++++ inc/system/system.timer.lua | 19 ------------------- 5 files changed, 24 insertions(+), 21 deletions(-) rename inc/{init/init.meter.lua => system/system.meter.lua} (86%) diff --git a/impostor.inc b/impostor.inc index 8f53b9b..2729974 100644 --- a/impostor.inc +++ b/impostor.inc @@ -2,8 +2,8 @@ meta/meta.header.lua init/init.module.lua init/init.config.lua init/init.minigame.lua -init/init.meter.lua init/init.context.lua +system/system.meter.lua system/system.util.lua system/system.print.lua system/system.input.lua diff --git a/inc/screen/screen.toilet.lua b/inc/screen/screen.toilet.lua index 4c9b288..f388400 100644 --- a/inc/screen/screen.toilet.lua +++ b/inc/screen/screen.toilet.lua @@ -42,7 +42,7 @@ Screen.register({ local m = Context.meters local max_val = Meter.get_max() - local decay_pct = Timer.get_decay_percentage() + local decay_pct = Meter.get_decay_percentage() local decay_text = string.format("-%d%%", decay_pct) local combo_mult = Meter.get_combo_multiplier() local combo_pct = math.floor((combo_mult - 1) * 100) diff --git a/inc/system/system.day.lua b/inc/system/system.day.lua index 8b03d01..36bf617 100644 --- a/inc/system/system.day.lua +++ b/inc/system/system.day.lua @@ -9,3 +9,10 @@ end function Day.register_handler(handler) table.insert(_day_increase_handlers, handler) end + +Day.register_handler(function() + local m = Context.meters + m.ism = math.max(0, m.ism - METER_DECAY_PER_DAY) + m.wpm = math.max(0, m.wpm - METER_DECAY_PER_DAY) + m.bm = math.max(0, m.bm - METER_DECAY_PER_DAY) +end) \ No newline at end of file diff --git a/inc/init/init.meter.lua b/inc/system/system.meter.lua similarity index 86% rename from inc/init/init.meter.lua rename to inc/system/system.meter.lua index 1548383..4a49098 100644 --- a/inc/init/init.meter.lua +++ b/inc/system/system.meter.lua @@ -2,6 +2,7 @@ local METER_MAX = 1000 local METER_DEFAULT = 500 local METER_GAIN_PER_CHORE = 100 +local METER_DECAY_PER_DAY = 20 local COMBO_BASE_BONUS = 0.02 local COMBO_MAX_BONUS = 0.16 local COMBO_TIMEOUT_FRAMES = 600 @@ -52,6 +53,20 @@ function Meter.get_max() return METER_MAX end +--- Sets the decay amount applied to all meters per day. +--- @within Meter +--- @param amount number Amount to subtract from each meter. +function Meter.set_decay(amount) + METER_DECAY_PER_DAY = amount +end + +--- Gets the meter decay as a percentage of the max meter value. +--- @within Meter +--- @return number The decay percentage per day. +function Meter.get_decay_percentage() + return math.floor(METER_DECAY_PER_DAY / METER_MAX * 100) +end + --- Gets combo multiplier. --- @within Meter --- @return number The current combo multiplier. diff --git a/inc/system/system.timer.lua b/inc/system/system.timer.lua index 005a607..bf878e6 100644 --- a/inc/system/system.timer.lua +++ b/inc/system/system.timer.lua @@ -1,7 +1,6 @@ --- @section Timer local timer_duration = 1800 -local timer_decay_per_revolution = 20 --- Gets initial timer values. --- @within Timer @@ -21,25 +20,10 @@ function Timer.set_duration(frames) timer_duration = frames end ---- Sets the decay amount applied to all meters per revolution. ---- @within Timer ---- @param amount number Amount to subtract from each meter. -function Timer.set_decay(amount) - timer_decay_per_revolution = amount -end - ---- Gets the timer decay as a percentage of the max meter value. ---- @within Timer ---- @return number The decay percentage per revolution. -function Timer.get_decay_percentage() - return math.floor(timer_decay_per_revolution / Meter.get_max() * 100) -end - --- Updates the timer and handles revolution events. --- @within Timer function Timer.update() if not Context or not Context.game_in_progress or not Context.meters or not Context.timer then return end - local m = Context.meters local t = Context.timer local in_minigame = string.find(Window.get_current_id(), "^minigame_") ~= nil @@ -48,9 +32,6 @@ function Timer.update() if t.progress >= 1 then Day.increase() t.progress = t.progress - 1 - m.ism = math.max(0, m.ism - timer_decay_per_revolution) - m.wpm = math.max(0, m.wpm - timer_decay_per_revolution) - m.bm = math.max(0, m.bm - timer_decay_per_revolution) end end end