2 Commits

View File

@ -271,68 +271,63 @@ local function stat_str(stat)
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") if isserver then
if f then local f = io.open(FILENAME, "r")
for l in f:lines() do if f then
-- Leaderboard is stored in the following tab separated format for l in f:lines() do
-- mapnum, name, skin, color, time, splits, flags, stat -- Leaderboard is stored in the following tab separated format
local t = {} -- mapnum, name, skin, color, time, splits, flags, stat
for word in (l+"\t"):gmatch("(.-)\t") do local t = {}
table.insert(t, word) for word in (l+"\t"):gmatch("(.-)\t") do
end table.insert(t, word)
local flags = 0
if t[7] != nil then
flags = tonumber(t[7])
end
scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
local spl = t[6] or ""
local stats = nil
if t[8] != nil then
if #t[8] >= 2 then
local speed = tonumber(string.sub(t[8], 1, 1))
local weight = tonumber(string.sub(t[8], 2, 2))
stats = stat_t(speed, weight)
end end
local flags = 0
if t[7] != nil then
flags = tonumber(t[7])
end
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 stats = nil
if t[8] != nil then
if #t[8] >= 2 then
local speed = tonumber(string.sub(t[8], 1, 1))
local weight = tonumber(string.sub(t[8], 2, 2))
stats = stat_t(speed, weight)
end
end
table.insert(
scoreTable,
score_t(
tonumber(t[1]),
t[2],
t[3],
t[4],
tonumber(t[5]),
spl,
flags,
stats
)
)
setScoreTable(tonumber(t[1]), flags, scoreTable)
end end
table.insert( sortScores()
scoreTable, f:close()
score_t( else
tonumber(t[1]), print("Failed to open file: ", FILENAME)
t[2],
t[3],
t[4],
tonumber(t[5]),
spl,
flags,
stats
)
)
setScoreTable(tonumber(t[1]), flags, scoreTable)
end end
sortScores()
f:close()
else
print("Failed to open file: ", FILENAME)
end end
function allowJoin(v) function allowJoin(v)
@ -1035,9 +1030,8 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
) )
-- Draw splits -- Draw splits
local splts = splits_from_str(score["splits"]) if showSplit and score["splits"] and score["splits"][prevLap] != nil then
if showSplit and splts and splts[prevLap] != nil then local split = splits[prevLap] - score["splits"][prevLap]
local split = splits[prevLap] - splts[prevLap]
v.drawString( v.drawString(
x + px + FACERANK_DIM, x + px + FACERANK_DIM,
y + 8, y + 8,
@ -1276,7 +1270,7 @@ local function saveTime(player)
player.mo.skin, player.mo.skin,
player.skincolor, player.skincolor,
timeFinished, timeFinished,
splits_to_str(splits), 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)
) )
@ -1323,30 +1317,32 @@ local function saveTime(player)
StatTrack = true StatTrack = true
end end
local f = assert(io.open(FILENAME, "w")) if isserver then
if f == nil then local f = assert(io.open(FILENAME, "w"))
print("Failed to open file for writing: " + FILENAME) if f == nil then
return print("Failed to open file for writing: " + FILENAME)
end return
end
for _, tbl in pairs(lb) do for _, tbl in pairs(lb) do
for _, scoreTable in pairs(tbl) do for _, scoreTable in pairs(tbl) do
for _, score in ipairs(scoreTable) do for _, score in ipairs(scoreTable) do
f:write( f:write(
score["map"], "\t", score["map"], "\t",
score["name"], "\t", score["name"], "\t",
score["skin"], "\t", score["skin"], "\t",
score["color"], "\t", score["color"], "\t",
score["time"], "\t", score["time"], "\t",
score["splits"], "\t", table.concat(score["splits"], " "), "\t",
score["flags"], "\t", score["flags"], "\t",
stat_str(score["stat"]), "\n" stat_str(score["stat"]), "\n"
) )
end
end end
end end
end
f:close() f:close()
end
end end
-- DEBUGGING -- DEBUGGING