fix: clearing room when new game
This commit is contained in:
parent
aa410f21e5
commit
e9ac369702
@ -53,6 +53,11 @@ private void Awake()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
|
{
|
||||||
|
InitializeFirstPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeFirstPage()
|
||||||
{
|
{
|
||||||
explanationPage.SetActive(false);
|
explanationPage.SetActive(false);
|
||||||
waitForPropositionsPage.gameObject.SetActive(false);
|
waitForPropositionsPage.gameObject.SetActive(false);
|
||||||
@ -98,7 +103,40 @@ private void ResetAllPlayerLabels()
|
|||||||
private bool deleteRoomFilesCompleted = false;
|
private bool deleteRoomFilesCompleted = false;
|
||||||
private bool deleteRealtimeDBCompleted = false;
|
private bool deleteRealtimeDBCompleted = false;
|
||||||
|
|
||||||
private IEnumerator OnApplicationQuit()
|
private void OnApplicationQuit()
|
||||||
|
{
|
||||||
|
StartCoroutine(Coroutine_ClearCurrentRoom(() =>
|
||||||
|
{
|
||||||
|
Debug.Log("You can go. Bye bye...");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Initialize()
|
||||||
|
{
|
||||||
|
FirebaseInitializer.Instance.onFirebaseReady -= Initialize;
|
||||||
|
realtimeDB = FirebaseDatabase.DefaultInstance.RootReference;
|
||||||
|
Debug.Log("Realtime DB initialized");
|
||||||
|
ClearOldAndCreateNewRoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClearOldAndCreateNewRoom()
|
||||||
|
{
|
||||||
|
CleanOldRooms();
|
||||||
|
StartCoroutine(Coroutine_ClearCurrentRoom(() =>
|
||||||
|
{
|
||||||
|
CreateNewRoom();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator Coroutine_ClearCurrentRoom(Action callback_OnRoomClear = null)
|
||||||
|
{
|
||||||
|
if(myRoom == null || string.IsNullOrEmpty(myRoom.code))
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
Debug.Log("There is no room to clean", this);
|
||||||
|
callback_OnRoomClear?.Invoke();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Debug.Log($"delete files of room {myRoom.code} from storage", this);
|
Debug.Log($"delete files of room {myRoom.code} from storage", this);
|
||||||
StorageManager.Instance.DeleteFileOfRoom(myRoom, () =>
|
StorageManager.Instance.DeleteFileOfRoom(myRoom, () =>
|
||||||
@ -119,17 +157,10 @@ private IEnumerator OnApplicationQuit()
|
|||||||
{
|
{
|
||||||
yield return null; // Yield until both tasks are completed
|
yield return null; // Yield until both tasks are completed
|
||||||
}
|
}
|
||||||
|
callback_OnRoomClear?.Invoke();
|
||||||
|
|
||||||
Debug.Log("Everything is clean. You can go. Bye bye...");
|
Debug.Log("Everything is clean.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Initialize()
|
|
||||||
{
|
|
||||||
FirebaseInitializer.Instance.onFirebaseReady -= Initialize;
|
|
||||||
realtimeDB = FirebaseDatabase.DefaultInstance.RootReference;
|
|
||||||
Debug.Log("Realtime DB initialized");
|
|
||||||
CleanOldRooms();
|
|
||||||
CreateNewRoom();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -276,6 +307,10 @@ private void OnNewGameStateStarted()
|
|||||||
{
|
{
|
||||||
switch (myRoom.currentState)
|
switch (myRoom.currentState)
|
||||||
{
|
{
|
||||||
|
case (int)GameState.EnteringName: //if game has been reset by a player on mobile
|
||||||
|
ClearOldAndCreateNewRoom();
|
||||||
|
break;
|
||||||
|
|
||||||
case (int)GameState.WaitingForOtherPlayersToJoin:
|
case (int)GameState.WaitingForOtherPlayersToJoin:
|
||||||
Debug.Log("New State : WaitingForOtherPlayersToJoin");
|
Debug.Log("New State : WaitingForOtherPlayersToJoin");
|
||||||
break;
|
break;
|
||||||
@ -412,25 +447,4 @@ private void DeleteRoom(string _roomCode)
|
|||||||
Debug.Log($"Room {_roomCode} has been deleted");
|
Debug.Log($"Room {_roomCode} has been deleted");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> DoesPathExistAsync(StorageReference storageReference)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await storageReference.GetMetadataAsync();
|
|
||||||
return true; // Path exists
|
|
||||||
}
|
|
||||||
catch (StorageException ex)
|
|
||||||
{
|
|
||||||
if (ex.ErrorCode == StorageException.ErrorObjectNotFound)
|
|
||||||
{
|
|
||||||
return false; // Path does not exist
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogException(ex);
|
|
||||||
return false; // Handle other errors as needed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user