From edd04888ed52028262f28ef57494b93124b5263b Mon Sep 17 00:00:00 2001 From: Fangh Date: Mon, 29 Jan 2024 21:30:09 +0100 Subject: [PATCH] fix: players can (hopefully) vote --- Assets/Scripts/DatabaseClasses/Proposition.cs | 29 ++++++++++++++++++- Assets/Scripts/GameManager.cs | 13 +++++++-- Assets/Scripts/RoomManager.cs | 6 +--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/DatabaseClasses/Proposition.cs b/Assets/Scripts/DatabaseClasses/Proposition.cs index b63278b..14b211b 100644 --- a/Assets/Scripts/DatabaseClasses/Proposition.cs +++ b/Assets/Scripts/DatabaseClasses/Proposition.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.Collections.Generic; [Serializable] [JsonObject] @@ -7,6 +8,32 @@ public class Proposition { public string photoUrl; public Player owner; - public string[] voters; + public List voters; public double creationDate; + + [JsonConstructor] + public Proposition(string _photoUrl, Player _owner, List _voters, double _creationDate) + { + photoUrl = _photoUrl; + owner = null; + voters = _voters; + creationDate = _creationDate; + } + + public Proposition() + { + photoUrl = string.Empty; + owner = null; + voters = new List(); + creationDate = DateTime.Now.ToOADate(); + } + + public Proposition(Player _player) + { + photoUrl = string.Empty; + owner = _player; + voters = new List(); + creationDate = DateTime.Now.ToOADate(); + } + } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 3d6ccc6..a24419c 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -488,12 +488,21 @@ private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlin } - + /// + /// Call this function from the vote button in the scene + /// + /// public void OnClickProposition(int propositionNumber) { - List voters = myRoom.questions[myRoom.currentQuestionId].propositions[propositionNumber].voters.ToList(); + Debug.Log($"Room has {myRoom.questions.Count} questions. the current Question is Q({myRoom.currentQuestionId})."); + Debug.Log($"Q({myRoom.currentQuestionId}) has {myRoom.questions[myRoom.currentQuestionId].propositions.Count} propositions."); + Debug.Log($"Player click on proposition {propositionNumber}."); + Debug.Log($"it has {myRoom.questions[myRoom.currentQuestionId].propositions[propositionNumber].voters.Count} voters."); + + List voters = myRoom.questions[myRoom.currentQuestionId].propositions[propositionNumber].voters; voters.Add(currentPlayer.id); myOnlineRoom.Child("questions").Child(myRoom.currentQuestionId.ToString()).Child("propositions").Child(propositionNumber.ToString()).Child("voters").SetValueAsync(voters); + myRoom.currentState = (int)GameState.VoteSent; WaitingOtherPlayers.SetActive(true); VotePicture.SetActive(false); diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index a1225b2..5f75101 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -181,11 +181,7 @@ public void GeneratePrompts() for (int j = 0; j < 2; j++) { - propositions.Add(j, new Proposition() - { - owner = players[i + j < players.Count() ? i + j : 0], - creationDate = DateTime.Now.ToOADate() - }); + propositions.Add(j, new Proposition(players[i + j < players.Count() ? i + j : 0])); } questions.Add(i, new Question()