From 6e57cf8bfb20878d3be3e49d83c07411ba6158f7 Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sun, 28 Jan 2024 11:46:24 +0100 Subject: [PATCH] questions havve id now --- Assets/Scripts/DatabaseClasses/Question.cs | 1 + Assets/Scripts/RoomManager.cs | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/DatabaseClasses/Question.cs b/Assets/Scripts/DatabaseClasses/Question.cs index db6666e..364fa76 100644 --- a/Assets/Scripts/DatabaseClasses/Question.cs +++ b/Assets/Scripts/DatabaseClasses/Question.cs @@ -6,6 +6,7 @@ [JsonObject] public class Question { + public string id; public string promptId; public Dictionary propositions; public double creationDate; diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index 7c8cf36..126ff98 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -43,11 +43,9 @@ public class RoomManager : MonoBehaviour private float votingCurrentTime = 0; /// - /// Contain the infos about the current displayed question (during votes) + /// Contain all the question for this game session /// - private Question currentQuestion; - - private List questions; + private Dictionary questions = new Dictionary(); /// /// When this is equal to questions.Count, go to score page @@ -300,7 +298,7 @@ public void GeneratePrompts() System.Random rnd = new(); List prompts = promptList.prompts.OrderBy(x => rnd.Next()).Take(myRoom.players.Count() * 2).ToList(); List fullPlayers = myRoom.players.Values.ToList().Concat(myRoom.players.Values.ToList()).OrderBy(x => rnd.Next()).ToList(); - Dictionary questions = new(); + questions.Clear(); foreach (Prompt prompt in prompts) { @@ -331,15 +329,15 @@ public void GeneratePrompts() break; } } - - questions.Add(Guid.NewGuid().ToString(), new Question() + string newId = Guid.NewGuid().ToString(); + questions.Add(newId, new Question() { + id = newId, promptId = prompt.id, propositions = propositions, creationDate = DateTime.Now.ToOADate(), }); } - string JSON = JsonConvert.SerializeObject(questions); realtimeDB.Child("rooms").Child(myRoom.code).Child("questions").SetRawJsonValueAsync(JSON); }