From 211aa89485d32cefabedd2c305e3282f7a1ef94e Mon Sep 17 00:00:00 2001 From: Fangh Date: Sun, 4 Feb 2024 13:21:39 +0100 Subject: [PATCH] wip: try to know why state doesn't update on phone --- Assets/Scripts/DatabaseClasses/Room.cs | 14 ++++++++++++++ Assets/Scripts/GameManager.cs | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index 99c7496..cf2312c 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -28,6 +28,20 @@ public Room(string _code) currentState = 1; //default by PC } + public Room Copy() + { + Room newRoom = new Room(this.code) + { + questions = new Dictionary(this.questions), + players = new Dictionary(this.players), + currentQuestionId = this.currentQuestionId, + creationDate = this.creationDate, + currentState = this.currentState + }; + + return newRoom; + } + /// /// Return the only player with a specific ID /// diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 0946c00..98be0df 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -289,7 +289,6 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) try { - if (e?.Snapshot?.GetRawJsonValue() != null) { string JSON = e.Snapshot.GetRawJsonValue(); @@ -307,6 +306,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) return; } + Debug.Log($"lasState = {lastState}. Currentstep = {(GameState)myRoom.currentState}", this); if (myRoom.currentState != (int)lastState) { OnNewGameState(); @@ -468,7 +468,7 @@ public void OnClickSubmitSignIn() public void onClickSamePlayers() { Debug.Log("Play with same players !", this); - Room newRoom = myRoom; + Room newRoom = myRoom.Copy(); newRoom.currentState = (int)GameState.Explanation; newRoom.questions.Clear(); newRoom.currentQuestionId = 0; @@ -486,7 +486,7 @@ public void onClickSamePlayers() public void onClickNewPlayers() { Debug.Log("Play with new players !", this); - Room newRoom = myRoom; + Room newRoom = myRoom.Copy(); newRoom.currentState = (int)GameState.EnteringName; newRoom.currentQuestionId = 0; newRoom.questions = null;