|
@@ -302,14 +302,15 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
List<OnlineGameScript> games = new List<OnlineGameScript>();
|
|
List<OnlineGameScript> games = new List<OnlineGameScript>();
|
|
|
int gameId = -1;
|
|
int gameId = -1;
|
|
|
|
|
|
|
|
- OnlineGame prevGame = null;
|
|
|
|
|
|
|
+ OnlineGame prevGame = null;
|
|
|
|
|
+ KeyValuePair<int, string> signedInUser = Database.Instance.GetSignedInUser();
|
|
|
foreach (OnlineGame game in og.onlineGamesList) {
|
|
foreach (OnlineGame game in og.onlineGamesList) {
|
|
|
Int32.TryParse(game.id, out int currentGameId);
|
|
Int32.TryParse(game.id, out int currentGameId);
|
|
|
if (gameId != currentGameId) { // Spel ej i listan
|
|
if (gameId != currentGameId) { // Spel ej i listan
|
|
|
if (ogs != null) { // lägg till spel i listan, inte första gången
|
|
if (ogs != null) { // lägg till spel i listan, inte första gången
|
|
|
SetGlobalGameInfo(userName, ogs, gameId, prevGame);
|
|
SetGlobalGameInfo(userName, ogs, gameId, prevGame);
|
|
|
- if (game.currentPlayer.Equals(Database.Instance.GetSignedInUser().Value, StringComparison.InvariantCultureIgnoreCase)) {
|
|
|
|
|
- ogs.SetGameStatus("YOUR_TURN");
|
|
|
|
|
|
|
+ if (ogs.GameStatus == null) {
|
|
|
|
|
+ ogs.SetGameStatus(game.status);
|
|
|
}
|
|
}
|
|
|
games.Add(ogs);
|
|
games.Add(ogs);
|
|
|
}
|
|
}
|
|
@@ -329,16 +330,49 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
ogs.CurrentPlayer = game.username;
|
|
ogs.CurrentPlayer = game.username;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ SetGameStatus(ogs, signedInUser, game);
|
|
|
prevGame = game;
|
|
prevGame = game;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ SetGameStatus(ogs, signedInUser, og.onlineGamesList[og.onlineGamesList.Count - 1]);
|
|
|
SetGlobalGameInfo(userName, ogs, gameId, og.onlineGamesList[og.onlineGamesList.Count - 1]);
|
|
SetGlobalGameInfo(userName, ogs, gameId, og.onlineGamesList[og.onlineGamesList.Count - 1]);
|
|
|
|
|
+ if (ogs.GameStatus == null) {
|
|
|
|
|
+ ogs.SetGameStatus(og.onlineGamesList[og.onlineGamesList.Count - 1].status);
|
|
|
|
|
+ }
|
|
|
games.Add(ogs);
|
|
games.Add(ogs);
|
|
|
|
|
|
|
|
return games;
|
|
return games;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void SetGameStatus(OnlineGameScript ogs, KeyValuePair<int, string> signedInUser, OnlineGame game) {
|
|
|
|
|
+ if (game.currentPlayer.Equals(signedInUser.Key.ToString())) {
|
|
|
|
|
+ if (game.status.Equals("ACTIVE")) {
|
|
|
|
|
+ ogs.SetGameStatus("YOUR_TURN");
|
|
|
|
|
+ } else if (game.status.Equals("PENDING")) {
|
|
|
|
|
+ if (game.userId.Equals(signedInUser.Key.ToString()) && game.playerStatus.Equals("WAITING")) {
|
|
|
|
|
+ ogs.SetGameStatus("INVITED");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ogs.SetGameStatus("PENDING");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (game.status.Equals("ACTIVE")) {
|
|
|
|
|
+ if (game.currentPlayer.Equals(game.userId)) {
|
|
|
|
|
+ ogs.CurrentPlayer = game.username;
|
|
|
|
|
+ }
|
|
|
|
|
+ ogs.SetGameStatus("OTHERS_TURN");
|
|
|
|
|
+ } else if (game.status.Equals("PENDING")) {
|
|
|
|
|
+ if (game.userId.Equals(signedInUser.Key.ToString()) && game.playerStatus.Equals("WAITING")) {
|
|
|
|
|
+ ogs.SetGameStatus("INVITED");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ogs.SetGameStatus("PENDING");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void SetGlobalGameInfo(string userName, OnlineGameScript ogs, int gameId, OnlineGame game) {
|
|
private void SetGlobalGameInfo(string userName, OnlineGameScript ogs, int gameId, OnlineGame game) {
|
|
|
- ogs.SetGameStatus(game.status);
|
|
|
|
|
ogs.SetId(game.id);
|
|
ogs.SetId(game.id);
|
|
|
ogs.SetWinNumber(game.winNumber);
|
|
ogs.SetWinNumber(game.winNumber);
|
|
|
ogs.SetAnswerTimer(game.answerTimer);
|
|
ogs.SetAnswerTimer(game.answerTimer);
|
|
@@ -538,12 +572,11 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
Question q = GetQuestionData(gameId, userId);
|
|
Question q = GetQuestionData(gameId, userId);
|
|
|
|
|
|
|
|
Color32 categoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
|
|
Color32 categoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
|
|
|
- // Color32 questionCategoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
|
|
|
|
|
|
|
|
|
|
Int32.TryParse(q.category, out int categoryId);
|
|
Int32.TryParse(q.category, out int categoryId);
|
|
|
Int32.TryParse(q.id, out int questionId);
|
|
Int32.TryParse(q.id, out int questionId);
|
|
|
|
|
|
|
|
- NewQuestionData questionData = new NewQuestionData(q.answer, q.question, q.categoryName, categoryId, questionId, categoryColor);
|
|
|
|
|
|
|
+ NewQuestionData questionData = new NewQuestionData(q.answer, q.question, q.categoryName, categoryId, questionId, categoryColor, false);
|
|
|
|
|
|
|
|
return questionData;
|
|
return questionData;
|
|
|
}
|
|
}
|
|
@@ -585,7 +618,7 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
Int32.TryParse(q.category, out int categoryId);
|
|
Int32.TryParse(q.category, out int categoryId);
|
|
|
Int32.TryParse(q.id, out int questionId);
|
|
Int32.TryParse(q.id, out int questionId);
|
|
|
|
|
|
|
|
- NewQuestionData questionData = new NewQuestionData(q.answer, q.question, q.categoryName, categoryId, questionId, categoryColor);
|
|
|
|
|
|
|
+ NewQuestionData questionData = new NewQuestionData(q.answer, q.question, q.categoryName, categoryId, questionId, categoryColor, true);
|
|
|
|
|
|
|
|
questions.Add(questionData);
|
|
questions.Add(questionData);
|
|
|
}
|
|
}
|