fix: currentstate is no more global

This commit is contained in:
Morgan - 6 Freedom 2024-01-27 23:47:31 +01:00
parent 9da2198871
commit 6deff961d4

View File

@ -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)
/// </summary>
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<Room>(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: