resave scores if checksums have been written

This commit is contained in:
Not 2022-07-10 20:47:01 +02:00
parent 00aa2060f3
commit 907c07a25d

View File

@ -289,9 +289,30 @@ local function writeScore(fh, score)
)
end
local function saveScores()
local f = assert(io.open(FILENAME + ".txt", "w"))
if f == nil then
print("Failed to open file for writing: " + FILENAME + ".txt")
return
end
for _, tbl in pairs(lb) do
for _, scoreTable in pairs(tbl) do
for _, score in ipairs(scoreTable) do
writeScore(f, score)
end
end
end
f:close()
end
-- Read the leaderboard
local f = io.open(FILENAME + ".txt", "r")
if f then
-- track if scores checksums have been written
local checksumWrite = false
for l in f:lines() do
-- Leaderboard is stored in the following tab separated format
-- mapnum, name, skin, color, time, splits, flags, stat, map_checksum
@ -326,11 +347,14 @@ if f then
local mapnum = tonumber(t[1])
-- Checksums
local cks = t[9] or mapChecksum(mapnum)
local cks = t[9]
-- We have no previous recognition of this map
-- remove it
if cks == nil then
checksumWrite = true
cks = mapChecksum(mapnum)
-- We have no previous recognition of this map
-- remove it
if cks == nil then
local rsfh = io.open(FILENAME + "_removed_scores.txt", "a")
if not rsfh then
@ -363,6 +387,11 @@ if f then
sortScores()
f:close()
-- save scores
if checksumWrite then
saveScores()
end
else
print("Failed to open file: ", FILENAME + ".txt")
end
@ -1232,21 +1261,7 @@ local function saveTime(player)
StatTrack = true
end
local f = assert(io.open(FILENAME + ".txt", "w"))
if f == nil then
print("Failed to open file for writing: " + FILENAME + ".txt")
return
end
for _, tbl in pairs(lb) do
for _, scoreTable in pairs(tbl) do
for _, score in ipairs(scoreTable) do
writeScore(f, score)
end
end
end
f:close()
saveScores()
end
-- DEBUGGING