fix(connection): when there is no room
This commit is contained in:
parent
94c3daa525
commit
65ebad88cb
@ -12,7 +12,6 @@ public class RoomManager : MonoBehaviour
|
||||
{
|
||||
public List<TextMeshProUGUI> playerLabels = new List<TextMeshProUGUI>();
|
||||
|
||||
|
||||
private RoomState currentState;
|
||||
private Room myRoom = null;
|
||||
private List<Player> players;
|
||||
@ -86,6 +85,8 @@ private void Initialize()
|
||||
private void WhichCodesAreAlreadyUsed(Action<List<int>> callback_OnCodesChecked)
|
||||
{
|
||||
List<int> alreadyUsedCodes = new List<int>();
|
||||
try
|
||||
{
|
||||
realtimeDB.Child("rooms").GetValueAsync().ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.IsFaulted)
|
||||
@ -95,14 +96,27 @@ private void WhichCodesAreAlreadyUsed(Action<List<int>> callback_OnCodesChecked)
|
||||
else if (task.IsCompleted)
|
||||
{
|
||||
DataSnapshot snapshot = task.Result;
|
||||
List<Room> onlineRooms = JsonUtility.FromJson<List<Room>>(snapshot.GetRawJsonValue());
|
||||
if (snapshot.Value != null)
|
||||
{
|
||||
List<Room> onlineRooms = JsonConvert.DeserializeObject<List<Room>>(snapshot.GetRawJsonValue());
|
||||
foreach (Room r in onlineRooms)
|
||||
{
|
||||
Debug.Log($"Code {r.code} is already used by another party", this);
|
||||
alreadyUsedCodes.Add(int.Parse(r.code));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Your party is the first one!", this);
|
||||
}
|
||||
}
|
||||
callback_OnCodesChecked?.Invoke(alreadyUsedCodes);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -114,16 +128,15 @@ public void CreateNewRoom()
|
||||
{
|
||||
WhichCodesAreAlreadyUsed(codes =>
|
||||
{
|
||||
Debug.Log("coucou");
|
||||
Room newRoom = new Room(GenerateRandomAvailableCode(codes).ToString("D4"));
|
||||
myRoom = newRoom;
|
||||
|
||||
try
|
||||
{
|
||||
string JSON = JsonUtility.ToJson(newRoom);
|
||||
string JSON = JsonConvert.SerializeObject(newRoom);
|
||||
|
||||
realtimeDB.Child("rooms").Child(newRoom.code).SetRawJsonValueAsync(JSON).ContinueWithOnMainThread(task =>
|
||||
{
|
||||
|
||||
//then subscribe to it
|
||||
realtimeDB.Child("rooms").Child(newRoom.code).ValueChanged += OnRoomUpdate;
|
||||
roomCodeLabel.text = myRoom.code;
|
||||
@ -236,7 +249,6 @@ public void GenerateCouples()
|
||||
/// </summary>
|
||||
private void OnRoomUpdate(object sender, ValueChangedEventArgs value)
|
||||
{
|
||||
Debug.Log("coucou");
|
||||
if (value.DatabaseError != null)
|
||||
{
|
||||
Debug.LogError(value.DatabaseError.Message);
|
||||
@ -253,12 +265,10 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value)
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
|
||||
Debug.Log("caca");
|
||||
|
||||
switch (currentState)
|
||||
{
|
||||
case RoomState.WaitingForPlayers:
|
||||
Debug.Log("prout");
|
||||
UpdateConnectedPlayerList(myRoom.GetPlayerList());
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user