|
|
@@ -151,6 +151,7 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
public string userId;
|
|
|
public string username;
|
|
|
public string userLockedQuestions;
|
|
|
+ public string playerStatus;
|
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
|
@@ -300,78 +301,54 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
OnlineGameScript ogs = null;
|
|
|
List<OnlineGameScript> games = new List<OnlineGameScript>();
|
|
|
int gameId = -1;
|
|
|
- string playerToAct = "";
|
|
|
|
|
|
foreach (OnlineGame game in og.onlineGamesList) {
|
|
|
Int32.TryParse(game.id, out int currentGameId);
|
|
|
- if (gameId != currentGameId) {
|
|
|
- if (ogs != null) {
|
|
|
+ if (gameId != currentGameId) { // Spel ej i listan
|
|
|
+ if (ogs != null) { // lägg till spel i listan, inte första gången
|
|
|
+ SetGlobalGameInfo(userName, ogs, gameId, game);
|
|
|
games.Add(ogs);
|
|
|
}
|
|
|
onlineGameObject = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
|
|
|
ogs = onlineGameObject.GetComponent<OnlineGameScript>();
|
|
|
gameId = currentGameId;
|
|
|
|
|
|
- if (game.currentPlayer.Equals(userId.ToString())) {
|
|
|
- playerToAct = game.username;
|
|
|
+ /* if (game.currentPlayer.Equals(userId.ToString())) { // Inloggad spelares tur att agera
|
|
|
+ ogs.CurrentPlayer = game.username;
|
|
|
+ ogs.addPlayer(game.username);
|
|
|
+ } else */
|
|
|
+ if (game.currentPlayer.Equals(game.userId)) { // om första raden i spelinfo är annan spelare och det är dennes tur att agera
|
|
|
ogs.CurrentPlayer = game.username;
|
|
|
ogs.addPlayer(game.username);
|
|
|
- ogs.SetGameStatus("YOUR_TURN");
|
|
|
- } else if (game.currentPlayer.Equals(game.userId)) {
|
|
|
- ogs.CurrentPlayer = game.username;
|
|
|
+ ogs.PlayerInfos.Add(new KeyValuePair<string, string>(game.username, game.playerStatus));
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else { // Spel redan i listan, fyll på med info
|
|
|
ogs.addPlayer(game.username);
|
|
|
- if (game.currentPlayer.Equals(userId.ToString())) {
|
|
|
- ogs.SetGameStatus("YOUR_TURN");
|
|
|
- playerToAct = game.username;
|
|
|
- ogs.CurrentPlayer = game.username;
|
|
|
- ogs.addPlayer(game.username);
|
|
|
- } else if (game.currentPlayer.Equals(game.userId)) {
|
|
|
+ ogs.PlayerInfos.Add(new KeyValuePair<string, string>(game.username, game.playerStatus));
|
|
|
+ if (game.currentPlayer.Equals(game.userId)) {
|
|
|
ogs.CurrentPlayer = game.username;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- ogs.SetGameStatus(game.status);
|
|
|
- //ogs.CurrentPlayer = game.currentPlayer;
|
|
|
- List<KeyValuePair<string, string>> playerInfos = GetGameInfo(gameId); // TODO, This is not good, too many db calls!
|
|
|
- if (game.status.Equals("PENDING")) {
|
|
|
- string extraInfo = "";
|
|
|
- foreach (KeyValuePair<string, string> s in playerInfos) {
|
|
|
- if (s.Value.Equals("WAITING") && s.Key.Equals(userName, StringComparison.InvariantCultureIgnoreCase)) {
|
|
|
- ogs.SetGameStatus("INVITED");
|
|
|
- extraInfo += s.Key + ",";
|
|
|
- } else if (s.Value.EndsWith("WAITING")) {
|
|
|
- extraInfo += s.Key + ",";
|
|
|
- }
|
|
|
- }
|
|
|
- extraInfo = extraInfo.TrimEnd(',');
|
|
|
- ogs.SetGameStatusText(extraInfo);
|
|
|
-
|
|
|
- } else if (game.status.Equals("OTHERS_TURN")) {
|
|
|
- ogs.SetGameStatusText(ogs.CurrentPlayer);
|
|
|
- } else if (game.status.Equals("ACTIVE")) {
|
|
|
- ogs.SetGameStatusText(ogs.CurrentPlayer);
|
|
|
- } else {
|
|
|
- ogs.SetGameStatusText();
|
|
|
- }
|
|
|
|
|
|
- ogs.SetId(game.id);
|
|
|
- ogs.SetWinNumber(game.winNumber);
|
|
|
- ogs.SetAnswerTimer(game.answerTimer);
|
|
|
- ogs.SetRoundTimeLimit(game.roundTimeLimit);
|
|
|
- ogs.SetRound(game.round);
|
|
|
- ogs.StartDate = game.startDate;
|
|
|
- ogs.LastPlayedDate = game.lastPlayedDate;
|
|
|
-
|
|
|
- ogs.PlayerInfos = playerInfos;
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+ SetGlobalGameInfo(userName, ogs, gameId, og.onlineGamesList[og.onlineGamesList.Count]);
|
|
|
games.Add(ogs);
|
|
|
|
|
|
return games;
|
|
|
}
|
|
|
|
|
|
+ private void SetGlobalGameInfo(string userName, OnlineGameScript ogs, int gameId, OnlineGame game) {
|
|
|
+ ogs.SetGameStatus(game.status);
|
|
|
+ ogs.SetId(game.id);
|
|
|
+ ogs.SetWinNumber(game.winNumber);
|
|
|
+ ogs.SetAnswerTimer(game.answerTimer);
|
|
|
+ ogs.SetRoundTimeLimit(game.roundTimeLimit);
|
|
|
+ ogs.SetRound(game.round);
|
|
|
+ ogs.StartDate = game.startDate;
|
|
|
+ ogs.LastPlayedDate = game.lastPlayedDate;
|
|
|
+ }
|
|
|
+
|
|
|
internal List<KeyValuePair<string, string>> GetGameInfo(int gameId) {
|
|
|
List<KeyValuePair<string, string>> returnList = new List<KeyValuePair<string, string>>();
|
|
|
|