questions havve id now

This commit is contained in:
Morgan - 6 Freedom 2024-01-28 11:46:24 +01:00
parent f254c044e8
commit 6e57cf8bfb
2 changed files with 7 additions and 8 deletions

View File

@ -6,6 +6,7 @@
[JsonObject] [JsonObject]
public class Question public class Question
{ {
public string id;
public string promptId; public string promptId;
public Dictionary<string, Proposition> propositions; public Dictionary<string, Proposition> propositions;
public double creationDate; public double creationDate;

View File

@ -43,11 +43,9 @@ public class RoomManager : MonoBehaviour
private float votingCurrentTime = 0; private float votingCurrentTime = 0;
/// <summary> /// <summary>
/// Contain the infos about the current displayed question (during votes) /// Contain all the question for this game session
/// </summary> /// </summary>
private Question currentQuestion; private Dictionary<string, Question> questions = new Dictionary<string, Question>();
private List<Question> questions;
/// <summary> /// <summary>
/// When this is equal to questions.Count, go to score page /// When this is equal to questions.Count, go to score page
@ -300,7 +298,7 @@ public void GeneratePrompts()
System.Random rnd = new(); System.Random rnd = new();
List<Prompt> prompts = promptList.prompts.OrderBy(x => rnd.Next()).Take(myRoom.players.Count() * 2).ToList(); List<Prompt> prompts = promptList.prompts.OrderBy(x => rnd.Next()).Take(myRoom.players.Count() * 2).ToList();
List<Player> fullPlayers = myRoom.players.Values.ToList().Concat(myRoom.players.Values.ToList()).OrderBy(x => rnd.Next()).ToList(); List<Player> fullPlayers = myRoom.players.Values.ToList().Concat(myRoom.players.Values.ToList()).OrderBy(x => rnd.Next()).ToList();
Dictionary<string, Question> questions = new(); questions.Clear();
foreach (Prompt prompt in prompts) foreach (Prompt prompt in prompts)
{ {
@ -331,15 +329,15 @@ public void GeneratePrompts()
break; break;
} }
} }
string newId = Guid.NewGuid().ToString();
questions.Add(Guid.NewGuid().ToString(), new Question() questions.Add(newId, new Question()
{ {
id = newId,
promptId = prompt.id, promptId = prompt.id,
propositions = propositions, propositions = propositions,
creationDate = DateTime.Now.ToOADate(), creationDate = DateTime.Now.ToOADate(),
}); });
} }
string JSON = JsonConvert.SerializeObject(questions); string JSON = JsonConvert.SerializeObject(questions);
realtimeDB.Child("rooms").Child(myRoom.code).Child("questions").SetRawJsonValueAsync(JSON); realtimeDB.Child("rooms").Child(myRoom.code).Child("questions").SetRawJsonValueAsync(JSON);
} }