diff --git a/scripts/game.gd b/scripts/game.gd index ebe59c3..7148d6e 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -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 diff --git a/scripts/highscoreHandler.gd b/scripts/highscoreHandler.gd index d448d9c..a7b5338 100644 --- a/scripts/highscoreHandler.gd +++ b/scripts/highscoreHandler.gd @@ -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 time0: - 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