|
@@ -57,8 +57,10 @@ public class Database : MonoBehaviour {
|
|
|
internal void SetupNewOnlineGame(int limitPerQuestion, int limitPerPlayer, int toWin, List<InviteSearchResult> inviteUsers) {
|
|
internal void SetupNewOnlineGame(int limitPerQuestion, int limitPerPlayer, int toWin, List<InviteSearchResult> inviteUsers) {
|
|
|
List<int> playerIds = new List<int>();
|
|
List<int> playerIds = new List<int>();
|
|
|
inviteUsers.ForEach(i => playerIds.Add(i.GetId()));
|
|
inviteUsers.ForEach(i => playerIds.Add(i.GetId()));
|
|
|
|
|
+ Debug.Log(playerIds);
|
|
|
int currentUser = Database.Instance.GetSignedInUser();
|
|
int currentUser = Database.Instance.GetSignedInUser();
|
|
|
playerIds.Add(currentUser);
|
|
playerIds.Add(currentUser);
|
|
|
|
|
+ Debug.Log(inviteUsers);
|
|
|
|
|
|
|
|
var form = new WWWForm();
|
|
var form = new WWWForm();
|
|
|
form.AddField("currentUser", currentUser);
|
|
form.AddField("currentUser", currentUser);
|
|
@@ -67,7 +69,7 @@ public class Database : MonoBehaviour {
|
|
|
form.AddField("limitPerPlayer", limitPerPlayer);
|
|
form.AddField("limitPerPlayer", limitPerPlayer);
|
|
|
form.AddField("playerIds", String.Join(",", playerIds));
|
|
form.AddField("playerIds", String.Join(",", playerIds));
|
|
|
|
|
|
|
|
- CallDatabase("NewOnlineGame.php", form);
|
|
|
|
|
|
|
+ Debug.Log(CallOnlineDatabaseWithResponse("NewOnlineGame.php", form));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Serializable]
|
|
[Serializable]
|
|
@@ -83,6 +85,17 @@ public class Database : MonoBehaviour {
|
|
|
public List<Question> questionsList = new List<Question>();
|
|
public List<Question> questionsList = new List<Question>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ [Serializable]
|
|
|
|
|
+ public class PlayerInfo {
|
|
|
|
|
+ public string username;
|
|
|
|
|
+ public string status;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Serializable]
|
|
|
|
|
+ public class PlayerInfos {
|
|
|
|
|
+ public List<PlayerInfo> playerInfoList = new List<PlayerInfo>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
[Serializable]
|
|
[Serializable]
|
|
|
public class OnlineGame {
|
|
public class OnlineGame {
|
|
|
public string id;
|
|
public string id;
|
|
@@ -267,7 +280,7 @@ public class Database : MonoBehaviour {
|
|
|
|
|
|
|
|
string response = CallOnlineDatabaseWithResponse("OnlineGames.php", formData);
|
|
string response = CallOnlineDatabaseWithResponse("OnlineGames.php", formData);
|
|
|
|
|
|
|
|
- response = "{\"onlineGamesList\" : [ " + response + " ]}";
|
|
|
|
|
|
|
+ response = "{\"onlineGamesList\" : " + response + " }";
|
|
|
|
|
|
|
|
OnlineGames og = new OnlineGames();
|
|
OnlineGames og = new OnlineGames();
|
|
|
JsonUtility.FromJsonOverwrite(response, og);
|
|
JsonUtility.FromJsonOverwrite(response, og);
|
|
@@ -278,13 +291,47 @@ public class Database : MonoBehaviour {
|
|
|
foreach (OnlineGame game in og.onlineGamesList) {
|
|
foreach (OnlineGame game in og.onlineGamesList) {
|
|
|
onlineGameObject = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
|
|
onlineGameObject = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
|
|
|
ogs = onlineGameObject.GetComponent<OnlineGameScript>();
|
|
ogs = onlineGameObject.GetComponent<OnlineGameScript>();
|
|
|
-
|
|
|
|
|
- ogs.SetGameStatusText(game.status);
|
|
|
|
|
|
|
+ ogs.SetGameStatus(game.status);
|
|
|
|
|
+ if (game.status.Equals("PENDING")) {
|
|
|
|
|
+ Int32.TryParse(game.id, out int gameId);
|
|
|
|
|
+ List<KeyValuePair<string, string>> playerInfos = GetGameInfo(gameId);
|
|
|
|
|
+ string extraInfo = "";
|
|
|
|
|
+ foreach (KeyValuePair<string, string> s in playerInfos) {
|
|
|
|
|
+ if (s.Value.Equals("WAITING")) {
|
|
|
|
|
+ extraInfo += s.Key + ",";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ extraInfo = extraInfo.TrimEnd(',');
|
|
|
|
|
+ ogs.SetGameStatusText(extraInfo);
|
|
|
|
|
+ } else if (game.status.Equals("OTHERS_TURN")) {
|
|
|
|
|
+ ogs.SetGameStatusText(game.currentPlayer);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ogs.SetGameStatusText();
|
|
|
|
|
+ }
|
|
|
games.Add(ogs);
|
|
games.Add(ogs);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return games;
|
|
return games;
|
|
|
- //TODO Continue development here
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ internal List<KeyValuePair<string, string>> GetGameInfo(int gameId) {
|
|
|
|
|
+ List<KeyValuePair<string, string>> returnList = new List<KeyValuePair<string, string>>();
|
|
|
|
|
+
|
|
|
|
|
+ WWWForm form = new WWWForm();
|
|
|
|
|
+ form.AddField("gameId", gameId);
|
|
|
|
|
+
|
|
|
|
|
+ string response = CallOnlineDatabaseWithResponse("OnlineGameInfo.php", form);
|
|
|
|
|
+
|
|
|
|
|
+ response = "{\"playerInfoList\" : " + response + " }";
|
|
|
|
|
+ PlayerInfos pi = new PlayerInfos();
|
|
|
|
|
+ JsonUtility.FromJsonOverwrite(response, pi);
|
|
|
|
|
+
|
|
|
|
|
+ foreach (PlayerInfo p in pi.playerInfoList) {
|
|
|
|
|
+ KeyValuePair<string, string> player = new KeyValuePair<string, string>(p.username, p.status);
|
|
|
|
|
+ returnList.Add(player);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return returnList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
internal List<LocalGameScript> GetLocalGames(GameObject prefab) {
|
|
internal List<LocalGameScript> GetLocalGames(GameObject prefab) {
|
|
@@ -785,7 +832,9 @@ public class Database : MonoBehaviour {
|
|
|
}
|
|
}
|
|
|
// Show result
|
|
// Show result
|
|
|
string jsonData = www.downloadHandler.text;
|
|
string jsonData = www.downloadHandler.text;
|
|
|
- jsonData = "{\"usernamesList\" : [ " + jsonData + " ]}";
|
|
|
|
|
|
|
+
|
|
|
|
|
+ jsonData = "{\"usernamesList\" : " + jsonData + " }";
|
|
|
|
|
+
|
|
|
JsonUtility.FromJsonOverwrite(jsonData, uNames);
|
|
JsonUtility.FromJsonOverwrite(jsonData, uNames);
|
|
|
}
|
|
}
|
|
|
// TODO handle empty
|
|
// TODO handle empty
|