From cb19251556df31f496275d681e191852b0e9c82e Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 3 Mar 2026 20:32:08 +0100 Subject: [PATCH] Meter.draw --- inc/logic/logic.meter.lua | 34 ++++++++++++++++++++++++++++++++++ inc/system/system.main.lua | 2 +- inc/system/system.ui.lua | 34 ---------------------------------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/inc/logic/logic.meter.lua b/inc/logic/logic.meter.lua index 4a49098..0fb3c23 100644 --- a/inc/logic/logic.meter.lua +++ b/inc/logic/logic.meter.lua @@ -117,3 +117,37 @@ function Meter.on_minigame_complete() m.combo = m.combo + 1 m.combo_timer = 0 end + +--- Draws meters. +--- @within Meter +function Meter.draw() + if not Context or not Context.game_in_progress or not Context.meters then return end + if Context.meters.hidden then return end + + local m = Context.meters + local max = Meter.get_max() + local bar_w = 44 + local bar_h = 2 + local bar_x = 182 + local label_x = 228 + local line_h = 5 + local start_y = 11 + local bar_offset = math.floor((line_h - bar_h) / 2) + + local meter_list = { + { key = "wpm", label = "WPM", color = Meter.COLOR_WPM, row = 0 }, + { key = "ism", label = "ISM", color = Meter.COLOR_ISM, row = 1 }, + { key = "bm", label = "BM", color = Meter.COLOR_BM, row = 2 }, + } + + for _, meter in ipairs(meter_list) do + local label_y = start_y + meter.row * line_h + local bar_y = label_y + bar_offset + local fill_w = math.max(0, math.floor((m[meter.key] / max) * bar_w)) + rect(bar_x, bar_y, bar_w, bar_h, Meter.COLOR_BG) + if fill_w > 0 then + rect(bar_x, bar_y, fill_w, bar_h, meter.color) + end + print(meter.label, label_x, label_y, meter.color, false, 1, true) + end +end diff --git a/inc/system/system.main.lua b/inc/system/system.main.lua index bc9f315..0cdec98 100644 --- a/inc/system/system.main.lua +++ b/inc/system/system.main.lua @@ -24,7 +24,7 @@ function TIC() Meter.update() Timer.update() if Context.game_in_progress then - UI.draw_meters() + Meter.draw() Timer.draw() end end diff --git a/inc/system/system.ui.lua b/inc/system/system.ui.lua index fc34e86..d48fe3d 100644 --- a/inc/system/system.ui.lua +++ b/inc/system/system.ui.lua @@ -79,37 +79,3 @@ function UI.word_wrap(text, max_chars_per_line) end return lines end - ---- Draws meters. ---- @within UI -function UI.draw_meters() - if not Context or not Context.game_in_progress or not Context.meters then return end - if Context.meters.hidden then return end - - local m = Context.meters - local max = Meter.get_max() - local bar_w = 44 - local bar_h = 2 - local bar_x = 182 - local label_x = 228 - local line_h = 5 - local start_y = 11 - local bar_offset = math.floor((line_h - bar_h) / 2) - - local meter_list = { - { key = "wpm", label = "WPM", color = Meter.COLOR_WPM, row = 0 }, - { key = "ism", label = "ISM", color = Meter.COLOR_ISM, row = 1 }, - { key = "bm", label = "BM", color = Meter.COLOR_BM, row = 2 }, - } - - for _, meter in ipairs(meter_list) do - local label_y = start_y + meter.row * line_h - local bar_y = label_y + bar_offset - local fill_w = math.max(0, math.floor((m[meter.key] / max) * bar_w)) - rect(bar_x, bar_y, bar_w, bar_h, Meter.COLOR_BG) - if fill_w > 0 then - rect(bar_x, bar_y, fill_w, bar_h, meter.color) - end - print(meter.label, label_x, label_y, meter.color, false, 1, true) - end -end \ No newline at end of file