From 1a724ac03c4f9cbcd9ebacf876f6a5c97e095e7f Mon Sep 17 00:00:00 2001 From: Fangh Date: Sun, 28 Jan 2024 16:34:06 +0100 Subject: [PATCH] fix: manage when no propositions --- Assets/Scripts/VotingPage.cs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/VotingPage.cs b/Assets/Scripts/VotingPage.cs index 78b762d..6ec4eea 100644 --- a/Assets/Scripts/VotingPage.cs +++ b/Assets/Scripts/VotingPage.cs @@ -38,7 +38,11 @@ private void Update() return; - if (endOfTimer <= DateTime.Now) + if (DateTime.Now < endOfTimer) + { + timerLabel.text = (DateTime.Now - endOfTimer).TotalSeconds.ToString("D2"); + } + else { timerLabel.text = "0"; if (remainingQuestions.Count > 0) @@ -51,10 +55,6 @@ private void Update() OnVoteEnded?.Invoke(); } } - else - { - timerLabel.text = (DateTime.Now - endOfTimer).ToString("D2"); - } } @@ -130,19 +130,24 @@ private void OnQuestionChanged(object sender, ValueChangedEventArgs _questionRef private void UpdateVoters() { - List playersThatHasVotedForFirstProposition = new List(); - foreach (string playerId in currentQuestion.propositions[0].voters) + if (currentQuestion.propositions[0] != null) { - playersThatHasVotedForFirstProposition.Add(currentPlayers[playerId]); + List playersThatHasVotedForFirstProposition = new List(); + foreach (string playerId in currentQuestion.propositions[0].voters) + { + playersThatHasVotedForFirstProposition.Add(currentPlayers[playerId]); + } + proposition1.UpdateVoters(playersThatHasVotedForFirstProposition); } - List playersThatHasVotedForSecondProposition = new List(); - foreach (string playerId in currentQuestion.propositions[1].voters) + if (currentQuestion.propositions[1] != null) { - playersThatHasVotedForSecondProposition.Add(currentPlayers[playerId]); + List playersThatHasVotedForSecondProposition = new List(); + foreach (string playerId in currentQuestion.propositions[1].voters) + { + playersThatHasVotedForSecondProposition.Add(currentPlayers[playerId]); + } + proposition2.UpdateVoters(playersThatHasVotedForSecondProposition); } - - proposition1.UpdateVoters(playersThatHasVotedForFirstProposition); - proposition2.UpdateVoters(playersThatHasVotedForSecondProposition); } }