From 786189057ede108b4970f2f3cab4c0fe3ed35378 Mon Sep 17 00:00:00 2001 From: Fisch Date: Sat, 9 Nov 2024 12:07:59 +0100 Subject: [PATCH] fix menu restart time on keypress --- scripts/gamestate.gd | 7 ++++++- scripts/menu.gd | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/gamestate.gd b/scripts/gamestate.gd index 13a8901..ec6ecd4 100644 --- a/scripts/gamestate.gd +++ b/scripts/gamestate.gd @@ -9,11 +9,16 @@ var userinput_prefix="inputP" var time_elapsed=0 func addPlayer(key:int): + #return -1 if player already exists with this key. else return id of player added if not getPlayerkeys().has(key): #playerkeys.append(key) - players.append(Player.new(key,len(players))) + var addID=len(players) + players.append(Player.new(key,addID)) #print("Added Key"+str(key)) #print("List:"+str(getPlayerkeys())) + return addID + else: + return -1 func removeAllPlayers(): players=[] diff --git a/scripts/menu.gd b/scripts/menu.gd index d09abc6..fb22eaf 100644 --- a/scripts/menu.gd +++ b/scripts/menu.gd @@ -26,14 +26,15 @@ func _unhandled_key_input(event: InputEvent) -> void: if event is InputEventKey: if event.pressed: #print("Key keycode:"+str(event.keycode)) - Gamestate.addPlayer(event.keycode) + var addedID=Gamestate.addPlayer(event.keycode) $MenuDisplay.update_playerlist(Gamestate.players) - if len(Gamestate.getPlayerkeys())>=1: - $Timer.start() - else: - $Timer.stop() + if addedID!=-1: + if len(Gamestate.getPlayerkeys())>=1: + $Timer.start() + else: + $Timer.stop()