Compare commits
2 Commits
f824e760e3
...
52316347da
Author | SHA1 | Date | |
---|---|---|---|
52316347da | |||
4a1e42c5cb |
@ -229,7 +229,6 @@ do
|
|||||||
|
|
||||||
for l in f:lines() do
|
for l in f:lines() do
|
||||||
local score = parseScore(l)
|
local score = parseScore(l)
|
||||||
print(score.name)
|
|
||||||
LiveStore[score.map] = $ or {}
|
LiveStore[score.map] = $ or {}
|
||||||
table.insert(LiveStore[score.map], score)
|
table.insert(LiveStore[score.map], score)
|
||||||
end
|
end
|
||||||
|
94
tools/coldstore.py
Executable file
94
tools/coldstore.py
Executable file
@ -0,0 +1,94 @@
|
|||||||
|
#!/bin/python
|
||||||
|
import sys
|
||||||
|
from os import linesep
|
||||||
|
|
||||||
|
if len(sys.argv) != 4 or not sys.argv[1] or not sys.argv[2] or not sys.argv[3]:
|
||||||
|
print("Usage: coldstore.py <leaderboard.txt> <coldstore.txt> <leaderboard_records.lua>")
|
||||||
|
quit()
|
||||||
|
|
||||||
|
leaderboard_txt = sys.argv[1]
|
||||||
|
coldstore_txt = sys.argv[2]
|
||||||
|
records_lua = sys.argv[3]
|
||||||
|
|
||||||
|
def ParseScore(score):
|
||||||
|
# Map Name Skin Color Time Splits Flags Stat
|
||||||
|
split = score.split("\t")
|
||||||
|
return {
|
||||||
|
"map": split[0],
|
||||||
|
"name": split[1],
|
||||||
|
"skin": split[2],
|
||||||
|
"color": split[3],
|
||||||
|
"time": int(split[4]),
|
||||||
|
"splits": split[5],
|
||||||
|
"flags": int(split[6]),
|
||||||
|
"stat": split[7]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Compare scores
|
||||||
|
def CompareScore(a, b):
|
||||||
|
return a["time"] < b["time"]
|
||||||
|
|
||||||
|
F_SEP = 0xF
|
||||||
|
def SameScore(a, b):
|
||||||
|
return a["name"] == b["name"] and (a["flags"] & F_SEP) == (b["flags"] & F_SEP)
|
||||||
|
|
||||||
|
def LoadRecordsFromFile(path):
|
||||||
|
records = []
|
||||||
|
with open(path, "r") as f:
|
||||||
|
for line in f.readlines():
|
||||||
|
records.append(ParseScore(line.strip()))
|
||||||
|
return records
|
||||||
|
|
||||||
|
def AddScore(records, score):
|
||||||
|
mapid = score["map"]
|
||||||
|
mapTable = records.get(mapid) or []
|
||||||
|
|
||||||
|
for i in range(len(mapTable)):
|
||||||
|
scoreb = mapTable[i]
|
||||||
|
if SameScore(score, scoreb):
|
||||||
|
if CompareScore(score, scoreb):
|
||||||
|
mapTable[i] = score
|
||||||
|
records[mapid] = mapTable
|
||||||
|
return
|
||||||
|
mapTable.append(score)
|
||||||
|
records[mapid] = mapTable
|
||||||
|
|
||||||
|
# load leaderboard.txt and coldstore.txt
|
||||||
|
recordsList = LoadRecordsFromFile(leaderboard_txt)
|
||||||
|
recordsList.extend(LoadRecordsFromFile(coldstore_txt))
|
||||||
|
|
||||||
|
|
||||||
|
# construct the map tables
|
||||||
|
records = {}
|
||||||
|
for score in recordsList:
|
||||||
|
AddScore(records, score)
|
||||||
|
|
||||||
|
# convert records to flat list
|
||||||
|
recordsList = []
|
||||||
|
for mapTable in records.values():
|
||||||
|
for score in mapTable:
|
||||||
|
recordsList.append("\t".join([str(v) for v in list(score.values())]))
|
||||||
|
|
||||||
|
# truncate and write records to coldstore
|
||||||
|
with open(coldstore_txt, "w") as f:
|
||||||
|
for score in recordsList:
|
||||||
|
f.write(score + linesep)
|
||||||
|
|
||||||
|
luaA = """local ParseScore = lb_parse_score
|
||||||
|
local AddColdStore = lb_add_coldstore_record
|
||||||
|
local records = {
|
||||||
|
"""
|
||||||
|
luaB = """}
|
||||||
|
for _, str in ipairs(records) do
|
||||||
|
AddColdStore(ParseScore(str))
|
||||||
|
end
|
||||||
|
"""
|
||||||
|
# pack the records.lua file
|
||||||
|
with open(records_lua, "w") as f:
|
||||||
|
f.write(luaA)
|
||||||
|
for score in recordsList:
|
||||||
|
f.write("\"{}\",{}".format(score, linesep))
|
||||||
|
f.write(luaB)
|
||||||
|
|
||||||
|
# truncate leaderboard.txt
|
||||||
|
with open(leaderboard_txt, "w"): pass
|
Loading…
Reference in New Issue
Block a user