diff --git a/Assets/Scripts/DatabaseClasses/Question.cs b/Assets/Scripts/DatabaseClasses/Question.cs index 216b3f9..d7d6c20 100644 --- a/Assets/Scripts/DatabaseClasses/Question.cs +++ b/Assets/Scripts/DatabaseClasses/Question.cs @@ -8,16 +8,15 @@ public class Question { public string id; public string promptId; - public Dictionary propositions; + public Dictionary propositions; public double creationDate; public Proposition GetFirstProposition() { - return propositions["0"]; + return propositions[0]; } public Proposition GetSecondProposition() { - return propositions["1"]; + return propositions[1]; } } - diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index d129c66..f34cda6 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -8,7 +8,7 @@ public class Room { public string code; - public Dictionary questions; + public Dictionary questions; public Dictionary players; public string currentQuestionId; public double creationDate; @@ -19,7 +19,7 @@ public Room(string _code) code = _code; creationDate = DateTime.Now.ToOADate(); players = new Dictionary(); - questions = new Dictionary(); + questions = new Dictionary(); currentQuestionId = ""; currentState = 1; //default by PC } @@ -47,28 +47,23 @@ public List GetOrderedPlayerList() return players.Values.OrderBy(x => x.creationDate).ToList(); } - public List GetQuestionList() - { - return new List(questions.Values); - } - public List GetQuestionsByPlayer(Player player) { - List questions = new(); + List playerQuestions = new(); - foreach (Question question in GetQuestionList()) + foreach (Question question in new List(questions.Values)) { foreach (Proposition proposition in new List(question.propositions.Values)) { if (proposition.owner.id == player.id) { - questions.Add(question); + playerQuestions.Add(question); break; } } } - return questions; + return playerQuestions; } @@ -79,21 +74,21 @@ public void SetPlayersAreReady(int _state) public List GetPropositionsByPlayer(Player player) { - List propositions = new(); + List playerPropositions = new(); - foreach (Question question in GetQuestionList()) + foreach (Question question in new List(questions.Values)) { foreach (Proposition proposition in new List(question.propositions.Values)) { if (proposition.owner.id == player.id) { - propositions.Add(proposition); + playerPropositions.Add(proposition); break; } } } - return propositions; + return playerPropositions; } } diff --git a/Assets/Scripts/QuestionHandler.cs b/Assets/Scripts/QuestionHandler.cs index 55e5044..5a389bc 100644 --- a/Assets/Scripts/QuestionHandler.cs +++ b/Assets/Scripts/QuestionHandler.cs @@ -32,9 +32,9 @@ void Redraw(int currentQuestion) cameraManager.WebcamResume(); } - string GetPropRef(string playerId) + int GetPropRef(Player player) { - return gameManager.myRoom.questions[(currentQuestion - 1).ToString()].propositions.First(x => x.Value.owner.id == playerId).Key; + return gameManager.myRoom.questions[currentQuestion - 1].propositions.First(x => x.Value.owner.id == player.id).Key; } public void OnSubmitButton() @@ -44,7 +44,7 @@ public void OnSubmitButton() gameManager.myRoom.code, gameManager.currentPlayer.id, currentQuestion, - GetPropRef(gameManager.currentPlayer.id)); + GetPropRef(gameManager.currentPlayer)); if (currentQuestion < 2) { Redraw(++currentQuestion); diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index 42cac40..283ceab 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -287,22 +287,22 @@ public void GeneratePrompts() System.Random rnd = new(); List prompts = promptList.prompts.OrderBy(x => rnd.Next()).Take(myRoom.players.Count()).ToList(); List players = myRoom.players.Values.ToList().OrderBy(x => rnd.Next()).ToList(); - Dictionary questions = new(); + Dictionary questions = new(); for (int i = 0; i < players.Count(); i++) { - Dictionary propositions = new(); + Dictionary propositions = new(); for (int j = 0; j < 2; j++) { - propositions.Add(j.ToString(), new Proposition() + propositions.Add(j, new Proposition() { owner = players[i + j < players.Count() ? i + j : 0], creationDate = DateTime.Now.ToOADate() }); } - questions.Add(i.ToString(), new Question() + questions.Add(i, new Question() { id = Guid.NewGuid().ToString(), promptId = prompts[i].id, diff --git a/Assets/Scripts/StorageManager.cs b/Assets/Scripts/StorageManager.cs index 227bf9d..f7302e9 100644 --- a/Assets/Scripts/StorageManager.cs +++ b/Assets/Scripts/StorageManager.cs @@ -33,7 +33,7 @@ void Update() } - public void UploadPhoto(string roomCode, string playerId, int question, string proposition) + public void UploadPhoto(string roomCode, string playerId, int question, int proposition) { Texture2D photo = gameObject.GetComponent().GetPhoto(); byte[] photoBytes = ImageConversion.EncodeToJPG(photo); @@ -58,7 +58,7 @@ public void UploadPhoto(string roomCode, string playerId, int question, string p .Child("questions") .Child(question.ToString()) .Child("propositions") - .Child(proposition) + .Child(proposition.ToString()) .Child("photoUrl") .SetValueAsync(imageRef.Path); } diff --git a/Assets/Scripts/VotingPage.cs b/Assets/Scripts/VotingPage.cs index 3f59cf8..e0225d6 100644 --- a/Assets/Scripts/VotingPage.cs +++ b/Assets/Scripts/VotingPage.cs @@ -58,7 +58,7 @@ private void Update() // Start is called before the first frame update - public void ShowVotingPage(DatabaseReference _roomRef, Dictionary _currentPlayers, Dictionary _questions, Action _callback_OnVoteEnded) + public void ShowVotingPage(DatabaseReference _roomRef, Dictionary _currentPlayers, Dictionary _questions, Action _callback_OnVoteEnded) { Debug.Log("Initializing voting page"); this.gameObject.SetActive(true); @@ -66,7 +66,7 @@ public void ShowVotingPage(DatabaseReference _roomRef, Dictionary QuestionByID in _questions) { remainingQuestions.Enqueue(QuestionByID.Value); roomRef.Child("questions").Child(QuestionByID.Key).ValueChanged += OnQuestionChanged;