|
|
@@ -29,27 +29,31 @@ public class Database : MonoBehaviour {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- internal void GetCategories(List<CategoryPanel.Category> list) {
|
|
|
- string sql = "SELECT name, r, g, b, a, id FROM category";
|
|
|
- IDbCommand cmd = GetConnection();
|
|
|
- cmd.CommandText = sql;
|
|
|
+ internal void GetCategories(List<CategoryPanel.Category> list, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ OnlineDatabase.Instance.GetCategories(list);
|
|
|
+ } else {
|
|
|
+ string sql = "SELECT name, r, g, b, a, id FROM category";
|
|
|
+ IDbCommand cmd = GetConnection();
|
|
|
+ cmd.CommandText = sql;
|
|
|
|
|
|
- IDataReader reader = cmd.ExecuteReader();
|
|
|
+ IDataReader reader = cmd.ExecuteReader();
|
|
|
|
|
|
- while (reader.Read()) {
|
|
|
- CategoryPanel.Category cat = new CategoryPanel.Category();
|
|
|
+ while (reader.Read()) {
|
|
|
+ CategoryPanel.Category cat = new CategoryPanel.Category();
|
|
|
|
|
|
- byte r = (byte)reader.GetInt32(1);
|
|
|
- byte g = (byte)reader.GetInt32(2);
|
|
|
- byte b = (byte)reader.GetInt32(3);
|
|
|
- byte a = (byte)reader.GetInt32(4);
|
|
|
- cat.color = new Color32(r, g, b, a);
|
|
|
- cat.name = reader.GetString(0);
|
|
|
- cat.id = reader.GetInt32(5);
|
|
|
+ byte r = (byte)reader.GetInt32(1);
|
|
|
+ byte g = (byte)reader.GetInt32(2);
|
|
|
+ byte b = (byte)reader.GetInt32(3);
|
|
|
+ byte a = (byte)reader.GetInt32(4);
|
|
|
+ cat.color = new Color32(r, g, b, a);
|
|
|
+ cat.name = reader.GetString(0);
|
|
|
+ cat.id = reader.GetInt32(5);
|
|
|
|
|
|
- list.Add(cat);
|
|
|
+ list.Add(cat);
|
|
|
+ }
|
|
|
+ CloseConnection();
|
|
|
}
|
|
|
- CloseConnection();
|
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
|
@@ -224,7 +228,7 @@ public class Database : MonoBehaviour {
|
|
|
|
|
|
}
|
|
|
|
|
|
- internal int GetQuestionTimer(int gameId) {
|
|
|
+ internal int GetQuestionTimer(int gameId, string gameMode) {
|
|
|
if (questionTimer == -1) {
|
|
|
string sql = "SELECT answerTimer FROM game WHERE id = " + gameId;
|
|
|
if (databaseUrl == null) {
|
|
|
@@ -328,7 +332,10 @@ public class Database : MonoBehaviour {
|
|
|
conn.Close();
|
|
|
}
|
|
|
|
|
|
- public string GetCurrentPlayer(int gameId) {
|
|
|
+ public string GetCurrentPlayer(int gameId, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ return OnlineDatabase.Instance.GetCurrentPlayer(gameId);
|
|
|
+ }
|
|
|
string sql = "SELECT currentPlayer FROM game WHERE id = " + gameId;
|
|
|
IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
conn.Open();
|
|
|
@@ -347,16 +354,20 @@ public class Database : MonoBehaviour {
|
|
|
return currentPlayer;
|
|
|
}
|
|
|
|
|
|
- public void SetCurrentPlayer(int gameId, string currentPlayer) {
|
|
|
- string sql = "UPDATE game SET currentPlayer = '" + currentPlayer + "' WHERE id = " + gameId;
|
|
|
- IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
- conn.Open();
|
|
|
- IDbCommand cmd = conn.CreateCommand();
|
|
|
- cmd.CommandText = sql;
|
|
|
- cmd.ExecuteNonQuery();
|
|
|
+ public void SetCurrentPlayer(int gameId, string currentPlayer, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ OnlineDatabase.Instance.SetCurrentPlayer(gameId, currentPlayer);
|
|
|
+ } else {
|
|
|
+ string sql = "UPDATE game SET currentPlayer = '" + currentPlayer + "' WHERE id = " + gameId;
|
|
|
+ IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
+ conn.Open();
|
|
|
+ IDbCommand cmd = conn.CreateCommand();
|
|
|
+ cmd.CommandText = sql;
|
|
|
+ cmd.ExecuteNonQuery();
|
|
|
|
|
|
- cmd.Dispose();
|
|
|
- conn.Close();
|
|
|
+ cmd.Dispose();
|
|
|
+ conn.Close();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
internal int GetPlayerPoints(int gameId, string playerName) {
|
|
|
@@ -378,31 +389,42 @@ public class Database : MonoBehaviour {
|
|
|
return points;
|
|
|
}
|
|
|
|
|
|
- internal void SetFinishedDate(int gameId, string finishedDate) {
|
|
|
- string sql = "UPDATE game SET finishedDate = '" + finishedDate + "' WHERE id = " + gameId;
|
|
|
- IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
- conn.Open();
|
|
|
- IDbCommand cmd = conn.CreateCommand();
|
|
|
- cmd.CommandText = sql;
|
|
|
- cmd.ExecuteNonQuery();
|
|
|
+ internal void SetFinishedDate(int gameId, string finishedDate, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ OnlineDatabase.Instance.SetFinishedDate(gameId, finishedDate);
|
|
|
+ } else {
|
|
|
+ string sql = "UPDATE game SET finishedDate = '" + finishedDate + "' WHERE id = " + gameId;
|
|
|
+ IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
+ conn.Open();
|
|
|
+ IDbCommand cmd = conn.CreateCommand();
|
|
|
+ cmd.CommandText = sql;
|
|
|
+ cmd.ExecuteNonQuery();
|
|
|
|
|
|
- cmd.Dispose();
|
|
|
- conn.Close();
|
|
|
+ cmd.Dispose();
|
|
|
+ conn.Close();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- internal void SetRoundValue(int gameId, int round) {
|
|
|
- string sql = "UPDATE game SET round = " + round + " WHERE id = " + gameId;
|
|
|
- IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
- conn.Open();
|
|
|
- IDbCommand cmd = conn.CreateCommand();
|
|
|
- cmd.CommandText = sql;
|
|
|
- cmd.ExecuteNonQuery();
|
|
|
+ internal void SetRoundValue(int gameId, int round, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ OnlineDatabase.Instance.SetRoundValue(gameId, round);
|
|
|
+ } else {
|
|
|
+ string sql = "UPDATE game SET round = " + round + " WHERE id = " + gameId;
|
|
|
+ IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
+ conn.Open();
|
|
|
+ IDbCommand cmd = conn.CreateCommand();
|
|
|
+ cmd.CommandText = sql;
|
|
|
+ cmd.ExecuteNonQuery();
|
|
|
|
|
|
- cmd.Dispose();
|
|
|
- conn.Close();
|
|
|
+ cmd.Dispose();
|
|
|
+ conn.Close();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- internal int GetRoundValue(int gameId) {
|
|
|
+ internal int GetRoundValue(int gameId, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ return OnlineDatabase.Instance.GetRoundValue(gameId);
|
|
|
+ }
|
|
|
if (this.round == -1) {
|
|
|
string sql = "SELECT round FROM game WHERE id = " + gameId;
|
|
|
IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
@@ -420,7 +442,10 @@ public class Database : MonoBehaviour {
|
|
|
return this.round;
|
|
|
}
|
|
|
|
|
|
- internal List<KeyValuePair<string, int>> GetPlayersForGame(int gameId) {
|
|
|
+ internal List<KeyValuePair<string, int>> GetPlayersForGame(int gameId, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ return OnlineDatabase.Instance.GetPlayersForGame(gameId);
|
|
|
+ }
|
|
|
string sql = "SELECT name, (SELECT count(*) FROM usersLockedQuestions WHERE playerName = localUsers.name AND gameId = " + gameId + ") as numAnswers FROM localGamePlayers " +
|
|
|
"LEFT JOIN localUsers ON localGamePlayers.playerId = localUsers.id " +
|
|
|
"WHERE gameId = " + gameId;
|
|
|
@@ -468,7 +493,10 @@ public class Database : MonoBehaviour {
|
|
|
connectionType = type;
|
|
|
}
|
|
|
|
|
|
- internal int GetQuestionsLost(int gameId, string playerName) {
|
|
|
+ internal int GetQuestionsLost(int gameId, string playerName, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ return OnlineDatabase.Instance.GetQuestionsLost(gameId, playerName);
|
|
|
+ }
|
|
|
string sql = "SELECT questionsLost FROM localGamePlayers WHERE gameId = " + gameId + " AND playerId = (SELECT id from localUsers WHERE name = '" + playerName + "')";
|
|
|
IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
conn.Open();
|
|
|
@@ -559,7 +587,10 @@ public class Database : MonoBehaviour {
|
|
|
conn2.Close();
|
|
|
}
|
|
|
|
|
|
- internal int GetWinCondition(int gameId) {
|
|
|
+ internal int GetWinCondition(int gameId, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ return OnlineDatabase.Instance.GetWinCondition(gameId);
|
|
|
+ }
|
|
|
if (winAmount == -1) {
|
|
|
string sql = "SELECT winNumber FROM game WHERE id = " + gameId;
|
|
|
IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
@@ -591,7 +622,10 @@ public class Database : MonoBehaviour {
|
|
|
return (int)lastInsert64;
|
|
|
}
|
|
|
|
|
|
- public NewQuestion GetNewQuestion(List<int> userAnsweredQuestions, string userName) {
|
|
|
+ public NewQuestion GetNewQuestion(List<int> userAnsweredQuestions, string userName, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ return OnlineDatabase.Instance.GetNewQuestion(userAnsweredQuestions, userName);
|
|
|
+ }
|
|
|
int gameId = GameObject.Find("GameManager").GetComponent<GameManagerScript>().GameId;
|
|
|
Color32 questionCategoryColor = new Color32(0, 0, 20, 20);
|
|
|
if (connectionType == null) {
|
|
|
@@ -672,7 +706,10 @@ public class Database : MonoBehaviour {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public List<QuestionCard> GetPlayerQuestions(int gameId, string playerNameValue) {
|
|
|
+ public List<QuestionCard> GetPlayerQuestions(int gameId, string playerNameValue, string gameMode) {
|
|
|
+ if (gameMode.Equals("Online")) {
|
|
|
+ return OnlineDatabase.Instance.GetPlayerQuestions(gameId, playerNameValue);
|
|
|
+ }
|
|
|
if (databaseUrl == null) {
|
|
|
SetLocalOrOnline(GetGameMode(gameId));
|
|
|
}
|
|
|
@@ -730,30 +767,4 @@ public class Database : MonoBehaviour {
|
|
|
categoryString = qe.questionsList[0].category;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public List<UserName> GetUsersToInvite(string searchString) {
|
|
|
- string postUrl = "nordh.xyz/narKampen/dbFiles/PlayerSearch.php?";
|
|
|
- postUrl += "search=" + UnityWebRequest.EscapeURL(searchString);
|
|
|
-
|
|
|
-
|
|
|
- UserNames uNames = new UserNames();
|
|
|
- UnityWebRequest www = UnityWebRequest.Get(postUrl);
|
|
|
- www.SendWebRequest();
|
|
|
-
|
|
|
- if (www.isNetworkError || www.isHttpError) {
|
|
|
- Debug.Log(www.error);
|
|
|
- } else {
|
|
|
- while (!www.isDone) {
|
|
|
- }
|
|
|
- // Show result
|
|
|
- string jsonData = www.downloadHandler.text;
|
|
|
-
|
|
|
- jsonData = "{\"usernamesList\" : " + jsonData + " }";
|
|
|
-
|
|
|
- JsonUtility.FromJsonOverwrite(jsonData, uNames);
|
|
|
- }
|
|
|
- // TODO handle empty
|
|
|
- return uNames.usernamesList;
|
|
|
- }
|
|
|
-
|
|
|
}
|