From c46f40001c2f92caf1260973a867212fde02f2b7 Mon Sep 17 00:00:00 2001 From: Not Date: Mon, 18 Apr 2022 19:32:05 +0200 Subject: [PATCH] add cvar for separation of SPB, KARTBIG, and EXP --- leaderboard.lua | 93 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index c455442..4b83e94 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -28,6 +28,9 @@ local F_SPBJUS = 0x2 local F_SPBBIG = 0x4 local F_SPBEXP = 0x8 +-- Score table separator +local ST_SEP = F_SPBATK + local clearcheats = false local START_TIME = 6 * TICRATE + (3 * TICRATE / 4) @@ -112,24 +115,78 @@ local cv_interrupt = CV_RegisterVar({ end }) +local function setST(t, map, flags, scoreTable) + local mode = flags & ST_SEP + t[mode] = t[mode] or {} + t[mode][map] = scoreTable +end + +local function getST(t, map, flags) + local mode = flags & ST_SEP + return t[mode] and t[mode][map] or nil +end + local function setScoreTable(map, flags, scoreTable) - local mode = flags & F_SPBATK - lb[mode] = lb[mode] or {} - lb[mode][map] = scoreTable + setST(lb, map, flags, scoreTable) end local function getScoreTable(map, flags) - --local id = tostring(map) - --if flags & F_SPBATK then - -- id = id + "S" - --end - - --return id - - local mode = flags & F_SPBATK - return lb[mode] and lb[mode][map] or nil + return getST(lb, map, flags) end +-- True if a is better than b +local function lbComp(a, b) + -- Calculates the difficulty, harder has higher priority + -- if s is positive then a is harder + -- if s is negative then b is harder + -- if s is 0 then compare time + local s = (a["flags"] & (F_SPBEXP | F_SPBBIG)) - (b["flags"] & (F_SPBEXP | F_SPBBIG)) + return s > 0 or not(s < 0 or a["time"] >= b["time"]) +end + +local function sortScores() + for mode, t in pairs(lb) do + for map, scoreTable in pairs(t) do + table.sort(scoreTable, lbComp) + setScoreTable(map, mode, scoreTable) + end + end +end + +-- Reinitialize lb based on new ST_SEP value +local function reinit_lb() + local nlb = {} + + for mode, t in pairs(lb) do + for map, scoreTable in pairs(t) do + for i, score in ipairs(scoreTable) do + local st = getST(nlb, map, score["flags"]) or {} + table.insert(st, score) + setST(nlb, map, score["flags"], st) + end + end + end + + lb = nlb + sortScores() +end + +local cv_spb_separate = CV_RegisterVar({ + name = "lb_spb_separate", + defaultvalue = 0, + flags = CV_NETVAR | CV_CALL, + PossibleValue = CV_YesNo, + func = function(v) + if v.value then + ST_SEP = F_SPBATK | F_SPBBIG | F_SPBEXP + else + ST_SEP = F_SPBATK + end + + reinit_lb() + end +}) + local function score_t(map, name, skin, color, time, splits, flags, restat) return { ["map"] = map, @@ -208,9 +265,11 @@ if f then stats ) ) + setScoreTable(tonumber(t[1]), flags, scoreTable) end + sortScores() f:close() else print("Failed to open file: ", FILENAME) @@ -887,16 +946,6 @@ function cachePatches(v) end end --- True if a is better than b -local function lbComp(a, b) - -- Calculates the difficulty, harder has higher priority - -- if s is positive then a is harder - -- if s is negative then b is harder - -- if s is 0 then compare time - local s = (a["flags"] & (F_SPBEXP | F_SPBBIG)) - (b["flags"] & (F_SPBEXP | F_SPBBIG)) - return s > 0 or not(s < 0 or a["time"] >= b["time"]) -end - -- Find location of player and scroll to it function scroll_to(player) local m = getScoreTable(gamemap, Flags) or {}