fix(roommanager): deserialize dictionnary and not list of rooms
This commit is contained in:
parent
032bc974bf
commit
a2e2eb5898
@ -9,10 +9,17 @@ public class Player
|
||||
public string name;
|
||||
public string id;
|
||||
|
||||
[JsonConstructor]
|
||||
public Player(string _name, string _id)
|
||||
{
|
||||
name = _name;
|
||||
id = _id;
|
||||
}
|
||||
|
||||
public Player(string _name)
|
||||
{
|
||||
id = Guid.NewGuid().ToString();
|
||||
SetName( _name);
|
||||
SetName(_name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -84,11 +84,13 @@ private void Initialize()
|
||||
/// </summary>
|
||||
private void WhichCodesAreAlreadyUsed(Action<List<int>> callback_OnCodesChecked)
|
||||
{
|
||||
Debug.Log("Checking other rooms to get which codes are already used", this);
|
||||
List<int> alreadyUsedCodes = new List<int>();
|
||||
try
|
||||
{
|
||||
realtimeDB.Child("rooms").GetValueAsync().ContinueWithOnMainThread(task =>
|
||||
{
|
||||
Debug.Log("looking into the online rooms", this);
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
Debug.LogException(task.Exception);
|
||||
@ -96,10 +98,13 @@ private void WhichCodesAreAlreadyUsed(Action<List<int>> callback_OnCodesChecked)
|
||||
else if (task.IsCompleted)
|
||||
{
|
||||
DataSnapshot snapshot = task.Result;
|
||||
Debug.Log(snapshot.Value);
|
||||
if (snapshot.Value != null)
|
||||
{
|
||||
List<Room> onlineRooms = JsonConvert.DeserializeObject<List<Room>>(snapshot.GetRawJsonValue());
|
||||
foreach (Room r in onlineRooms)
|
||||
string JSON = snapshot.GetRawJsonValue();
|
||||
Debug.Log($"found some rooms :\n{JSON}", this);
|
||||
Dictionary<string, Room> onlineRooms = JsonConvert.DeserializeObject<Dictionary<string, Room>>(JSON);
|
||||
foreach (Room r in onlineRooms.Values)
|
||||
{
|
||||
Debug.Log($"Code {r.code} is already used by another party", this);
|
||||
alreadyUsedCodes.Add(int.Parse(r.code));
|
||||
|
Loading…
Reference in New Issue
Block a user