From 6deff961d44b68bcbb959ca6685c858a49bd2599 Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sat, 27 Jan 2024 23:47:31 +0100 Subject: [PATCH] fix: currentstate is no more global --- Assets/Scripts/RoomManager.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index f046b60..7a7314e 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -30,9 +30,7 @@ public class RoomManager : MonoBehaviour private float propositionCurrentTime = 0; public TextMeshProUGUI timerGUI; - private GameState currentState; private Room myRoom = null; - public float votingTime = 20; private float votingCurrentTime = 0; @@ -54,7 +52,6 @@ public class RoomManager : MonoBehaviour private void Awake() { FirebaseInitializer.Instance.onFirebaseReady += Initialize; - currentState = GameState.EnteringName; } @@ -63,12 +60,14 @@ private void Start() propositionCurrentTime = propositionTime; votingCurrentTime = votingTime; ResetAllPlayerLabels(); - currentState = GameState.WaitingForOtherPlayersToJoin; } private void Update() { - if (currentState == GameState.Explanation && endOfExplanationDate != DateTime.MinValue) + if (myRoom == null) + return; + + if (myRoom.currentState == (int)GameState.Explanation && endOfExplanationDate != DateTime.MinValue) { TimeSpan duration = endOfExplanationDate - DateTime.Now; counter.text = duration.TotalSeconds.ToString("D1"); @@ -76,11 +75,16 @@ private void Update() if (duration.TotalMilliseconds <= 0) { Debug.Log("It's time to make proposition !", this); - currentState = GameState.MakeProposition; + SendRoomState(GameState.MakeProposition); } } } + private void SendRoomState(GameState _newState) + { + realtimeDB.Child("rooms").Child(myRoom.code).Child("currentState").SetValueAsync((int)_newState); + } + private void ResetAllPlayerLabels() { for (int i = 0; i < waitingForPlayersLabels.Count; i++) @@ -207,7 +211,6 @@ public void PlayerSendProposition(Proposition _proposition) /// public void HostStartGame() { - currentState = GameState.MakeProposition; waitingForPropositionsPage.SetActive(true); waitingForPlayersPage.SetActive(false); propositionCurrentTime = propositionTime; @@ -313,7 +316,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value) return; } string JSON = value.Snapshot.GetRawJsonValue(); - Debug.Log(JSON); + Debug.Log($"your room has been updated :\n{JSON}"); try { myRoom = JsonConvert.DeserializeObject(JSON); @@ -324,17 +327,17 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value) } - switch (currentState) + switch (myRoom.currentState) { - case GameState.WaitingForOtherPlayersToJoin: + case (int)GameState.WaitingForOtherPlayersToJoin: UpdateConnectedPlayerList(myRoom.GetPlayerList()); break; - case GameState.Explanation: + case (int)GameState.Explanation: waitingForPlayersPage.SetActive(false); explanationPage.SetActive(true); endOfExplanationDate = DateTime.Now.AddSeconds(30); break; - case GameState.MakeProposition: + case (int)GameState.MakeProposition: HostStartGame(); break; default: