From a19f158828b4b14ad95d2fffc2af284570a6dbc4 Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sun, 28 Jan 2024 02:40:38 +0100 Subject: [PATCH] feat: room has now a function to list player and get propositions --- Assets/Scripts/DatabaseClasses/Room.cs | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index c9f9830..a4c66ce 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; [Serializable] @@ -28,6 +29,15 @@ public List GetPlayerList() return new List(players.Values); } + /// + /// return the list of player ordered by who joined first + /// + /// + public List GetOrderedPlayerList() + { + return players.Values.OrderBy(x => x.creationDate).ToList(); + } + public List GetQuestionList() { return new List(questions.Values); @@ -37,5 +47,24 @@ public void setPlayersAreReady(int _state) { currentState = _state; } + + public List GetPropositionsByPlayer(Player player) + { + List propositions = new(); + + foreach (Question question in GetQuestionList()) + { + foreach (Proposition proposition in new List(question.propositions.Values)) + { + if (proposition.owner.id == player.id) + { + propositions.Add(proposition); + break; + } + } + } + + return propositions; + } }