3 Commits

Author SHA1 Message Date
Not
0b2eb9e61d deserialize splits when needed 2022-09-15 23:23:25 +02:00
Not
2d4784f62e compress stats into a single number 2022-09-15 02:08:24 +02:00
Not
6953f343dc keep previously used flag 2022-09-12 17:00:42 +02:00
2 changed files with 38 additions and 28 deletions

View File

@ -266,15 +266,18 @@ local function drawFlags(v, x, y, flags)
end end
end end
local MSK_SPEED = 0xF0
local MSK_WEIGHT = 0xF
local function drawStats(v, x, y, skin, stats) local function drawStats(v, x, y, skin, stats)
local s = skins[skin] local s = skins[skin]
if not (s if stats
and s.kartspeed == stats["speed"] and not (s
and s.kartweight == stats["weight"] and s.kartspeed == (stats & MSK_SPEED) >> 4
) and s.kartweight == stats & MSK_WEIGHT
and stats then ) then
v.drawString(x-2, y-2, stats["speed"], V_ALLOWLOWERCASE, "thin") v.drawString(x-2, y-2, (stats & MSK_SPEED) >> 4, V_ALLOWLOWERCASE, "thin")
v.drawString(x + 13, y + 9, stats["weight"], V_ALLOWLOWERCASE, "thin") v.drawString(x + 13, y + 9, stats & MSK_WEIGHT, V_ALLOWLOWERCASE, "thin")
end end
end end

View File

@ -253,24 +253,36 @@ local function score_t(map, name, skin, color, time, splits, flags, stat)
} }
end end
local MSK_SPEED = 0xF0
local MSK_WEIGHT = 0xF
local function stat_t(speed, weight) local function stat_t(speed, weight)
if speed and weight then if speed and weight then
return { return (speed << 4) | weight
["speed"] = speed,
["weight"] = weight
}
end end
return nil return 0
end end
local function stat_str(stat) local function stat_str(stat)
if stat then if stat then
return string.format("%d%d", stat["speed"], stat["weight"]) return string.format("%d%d", (stat & MSK_SPEED) >> 4, stat & MSK_WEIGHT)
end end
return "0" return "0"
end end
local function splits_from_str(splitstr)
local spl = {}
for str in splitstr:gmatch("([^ ]+)") do
table.insert(spl, tonumber(str))
end
return spl
end
local function splits_to_str(splits)
return table.concat(splits, " ")
end
-- Read the leaderboard -- Read the leaderboard
local f = io.open(FILENAME, "r") local f = io.open(FILENAME, "r")
if f then if f then
@ -289,12 +301,7 @@ if f then
scoreTable = getScoreTable(tonumber(t[1]), flags) or {} scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
local spl = {} local spl = t[6] or ""
if t[6] != nil then
for str in t[6]:gmatch("([^ ]+)") do
table.insert(spl, tonumber(str))
end
end
local stats = nil local stats = nil
if t[8] != nil then if t[8] != nil then
@ -987,11 +994,11 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
local pskin = score["skin"] and skins[score["skin"]] local pskin = score["skin"] and skins[score["skin"]]
if stat and not ( if stat and not (
pskin pskin
and pskin.kartweight == stat["weight"] and pskin.kartweight == stat & MSK_WEIGHT
and pskin.kartspeed == stat["speed"] and pskin.kartspeed == (stat & MSK_SPEED) >> 4
) then ) then
v.drawString(x + FACERANK_DIM - 2, y + 4, stat["speed"], V_HUDTRANS | VFLAGS, "small") v.drawString(x + FACERANK_DIM - 2, y + 4, (stat & MSK_SPEED) >> 4, V_HUDTRANS | VFLAGS, "small")
v.drawString(x + FACERANK_DIM - 2, y + 8, stat["weight"], V_HUDTRANS | VFLAGS, "small") v.drawString(x + FACERANK_DIM - 2, y + 8, stat & MSK_WEIGHT, V_HUDTRANS | VFLAGS, "small")
end end
if gui == GUI_ON or (gui == GUI_SPLITS and showSplit) then if gui == GUI_ON or (gui == GUI_SPLITS and showSplit) then
@ -1028,8 +1035,9 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
) )
-- Draw splits -- Draw splits
if showSplit and score["splits"] and score["splits"][prevLap] != nil then local splts = splits_from_str(score["splits"])
local split = splits[prevLap] - score["splits"][prevLap] if showSplit and splts and splts[prevLap] != nil then
local split = splits[prevLap] - splts[prevLap]
v.drawString( v.drawString(
x + px + FACERANK_DIM, x + px + FACERANK_DIM,
y + 8, y + 8,
@ -1268,7 +1276,7 @@ local function saveTime(player)
player.mo.skin, player.mo.skin,
player.skincolor, player.skincolor,
timeFinished, timeFinished,
splits, splits_to_str(splits),
Flags, Flags,
stat_t(player.HMRs or pskin.kartspeed, player.HMRw or pskin.kartweight) stat_t(player.HMRs or pskin.kartspeed, player.HMRw or pskin.kartweight)
) )
@ -1330,7 +1338,7 @@ local function saveTime(player)
score["skin"], "\t", score["skin"], "\t",
score["color"], "\t", score["color"], "\t",
score["time"], "\t", score["time"], "\t",
table.concat(score["splits"], " "), "\t", score["splits"], "\t",
score["flags"], "\t", score["flags"], "\t",
stat_str(score["stat"]), "\n" stat_str(score["stat"]), "\n"
) )
@ -1433,7 +1441,6 @@ local function think()
end end
end end
Flags = 0
if leveltime > START_TIME - (3 * TICRATE) / 2 then if leveltime > START_TIME - (3 * TICRATE) / 2 then
if clearcheats then if clearcheats then
clearcheats = false clearcheats = false