add preset and round selection to highscore
This commit is contained in:
parent
0b63997ce4
commit
4b8a17ff44
2 changed files with 23 additions and 11 deletions
|
@ -86,7 +86,7 @@ func _ready() -> void:
|
|||
print("i_position="+str(i_position)+" carpos is ="+str(newcarinstance.getPosition())+" instancepos="+str(newcarinstance.position)+" colori="+str(player.colori)+" color="+str(player.color))
|
||||
i+=1
|
||||
|
||||
print("mapname="+str(Gamestate.getSelectedMapName()+"_"+str(Gamestate.getRounds())))
|
||||
|
||||
|
||||
|
||||
func custom_array_sort_rank(a, b):
|
||||
|
@ -245,7 +245,7 @@ func finishGame():
|
|||
|
||||
|
||||
if Gamestate.getPlayers().size()==1: #was played in singleplayer
|
||||
var timediff=HighscoreHandler.updateHighscore(Gamestate.getSelectedMapName()+"_"+str(Gamestate.getRounds()),getfinalTimeByPlayer(Gamestate.getPlayers()[0]))
|
||||
var timediff=HighscoreHandler.updateHighscore(Gamestate.getSelectedMapName(),"normal",str(Gamestate.getRounds()),getfinalTimeByPlayer(Gamestate.getPlayers()[0]))
|
||||
print("Timediff="+str(timediff))
|
||||
timediff=round(timediff*1000)/1000
|
||||
highscore_label.visible=true
|
||||
|
|
|
@ -4,25 +4,37 @@ const HIGHSCORE_FILE_PATH = "highscores.json"
|
|||
|
||||
|
||||
|
||||
func updateHighscore(mapname:String,rounds:int,preset:int,time:float):
|
||||
func updateHighscore(mapname:String,preset:String,rounds:String,time:float):
|
||||
var highscores=loadHighscoreDict()
|
||||
if highscores.has(mapname):
|
||||
var lasthighscore=loadHighscore(mapname)
|
||||
var lasthighscore=loadHighscore(mapname,preset,rounds)
|
||||
if lasthighscore !=null:
|
||||
if time<lasthighscore: #better time
|
||||
highscores[mapname].append({"created":Time.get_unix_time_from_system(),"time":time})
|
||||
highscores[mapname][preset][rounds].append({"created":Time.get_unix_time_from_system(),"time":time})
|
||||
storeHighscoreDict(highscores)
|
||||
return time-lasthighscore
|
||||
else: #first entry
|
||||
highscores[mapname]=[{"created":Time.get_unix_time_from_system(),"time":time}]
|
||||
else: #first entry for this map and config
|
||||
print("first entry for this config")
|
||||
if !highscores.has(mapname):
|
||||
print("mapname not known")
|
||||
highscores[mapname]={}
|
||||
if !highscores[mapname].has(preset):
|
||||
print("preset not known")
|
||||
highscores[mapname][preset]={}
|
||||
if !highscores[mapname][preset].has(rounds):
|
||||
print("rounds not known")
|
||||
highscores[mapname][preset][rounds]=[{"created":Time.get_unix_time_from_system(),"time":time}]
|
||||
|
||||
storeHighscoreDict(highscores)
|
||||
return 0
|
||||
|
||||
|
||||
func loadHighscore(mapname:String):
|
||||
func loadHighscore(mapname:String,preset:String,rounds:String):
|
||||
var highscores=loadHighscoreDict()
|
||||
if highscores.has(mapname):
|
||||
if highscores[mapname].size()>0:
|
||||
return highscores[mapname][highscores[mapname].size()-1]["time"] #return last entry
|
||||
if highscores[mapname].has(preset):
|
||||
if highscores[mapname][preset].has(rounds):
|
||||
if highscores[mapname][preset][rounds].size()>0:
|
||||
return highscores[mapname][preset][rounds][highscores[mapname].size()-1]["time"] #return last entry
|
||||
else:
|
||||
return null
|
||||
|
||||
|
|
Loading…
Reference in a new issue