1 Commits

Author SHA1 Message Date
Not
0b2eb9e61d deserialize splits when needed 2022-09-15 23:23:25 +02:00

View File

@ -271,10 +271,21 @@ local function stat_str(stat)
return "0"
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
if isserver then
local f = io.open(FILENAME, "r")
if f then
local f = io.open(FILENAME, "r")
if f then
for l in f:lines() do
-- Leaderboard is stored in the following tab separated format
-- mapnum, name, skin, color, time, splits, flags, stat
@ -290,12 +301,7 @@ if isserver then
scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
local spl = {}
if t[6] != nil then
for str in t[6]:gmatch("([^ ]+)") do
table.insert(spl, tonumber(str))
end
end
local spl = t[6] or ""
local stats = nil
if t[8] != nil then
@ -325,9 +331,8 @@ if isserver then
sortScores()
f:close()
else
else
print("Failed to open file: ", FILENAME)
end
end
function allowJoin(v)
@ -1030,8 +1035,9 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
)
-- Draw splits
if showSplit and score["splits"] and score["splits"][prevLap] != nil then
local split = splits[prevLap] - score["splits"][prevLap]
local splts = splits_from_str(score["splits"])
if showSplit and splts and splts[prevLap] != nil then
local split = splits[prevLap] - splts[prevLap]
v.drawString(
x + px + FACERANK_DIM,
y + 8,
@ -1270,7 +1276,7 @@ local function saveTime(player)
player.mo.skin,
player.skincolor,
timeFinished,
splits,
splits_to_str(splits),
Flags,
stat_t(player.HMRs or pskin.kartspeed, player.HMRw or pskin.kartweight)
)
@ -1317,7 +1323,6 @@ local function saveTime(player)
StatTrack = true
end
if isserver then
local f = assert(io.open(FILENAME, "w"))
if f == nil then
print("Failed to open file for writing: " + FILENAME)
@ -1333,7 +1338,7 @@ local function saveTime(player)
score["skin"], "\t",
score["color"], "\t",
score["time"], "\t",
table.concat(score["splits"], " "), "\t",
score["splits"], "\t",
score["flags"], "\t",
stat_str(score["stat"]), "\n"
)
@ -1342,7 +1347,6 @@ local function saveTime(player)
end
f:close()
end
end
-- DEBUGGING