feat: generatePrompt
This commit is contained in:
parent
a2e2eb5898
commit
5130a1dc4b
@ -1,11 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[Serializable]
|
||||
[JsonObject]
|
||||
public class Question
|
||||
{
|
||||
public string promptId;
|
||||
public Proposition propositions;
|
||||
public int creationDate;
|
||||
public Dictionary<string, Proposition> propositions;
|
||||
public double creationDate;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ public class GameManager : MonoBehaviour
|
||||
private GameState currentState;
|
||||
private List<Player> players = new();
|
||||
public Player currentPlayer = null;
|
||||
public Question currentQuestion = null;
|
||||
|
||||
[Header("Other component")]
|
||||
public float explanationTime = 4f;
|
||||
|
@ -25,6 +25,7 @@ private void Initialize()
|
||||
{
|
||||
FirebaseInitializer.Instance.onFirebaseReady -= Initialize;
|
||||
db = FirebaseFirestore.DefaultInstance;
|
||||
LoadPromptsFromFirestore();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -5,7 +5,6 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
|
||||
public class RoomManager : MonoBehaviour
|
||||
@ -15,6 +14,7 @@ public class RoomManager : MonoBehaviour
|
||||
private RoomState currentState;
|
||||
private Room myRoom = null;
|
||||
private List<Player> players;
|
||||
public PromptList promptList;
|
||||
|
||||
public float propositionTime = 60;
|
||||
public float votingTime = 20;
|
||||
@ -231,22 +231,41 @@ public void OnPropositionUpdate()
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will generate a question with a prompt and two owners
|
||||
/// </summary>
|
||||
public void GenerateQuestion()
|
||||
public void GeneratePrompts()
|
||||
{
|
||||
System.Random rnd = new();
|
||||
List<Prompt> prompts = promptList.prompts.OrderBy(x => rnd.Next()).Take(players.Count() * 2).ToList();
|
||||
List<Player> fullPlayers = players.Concat(players).OrderBy(x => rnd.Next()).ToList();
|
||||
Dictionary<string, Question> questions = new();
|
||||
|
||||
}
|
||||
foreach (Prompt prompt in prompts)
|
||||
{
|
||||
Dictionary<string, Proposition> propositions = new();
|
||||
Player basePlayer = fullPlayers[0];
|
||||
propositions.Add(Guid.NewGuid().ToString(), new Proposition() { owner = basePlayer });
|
||||
|
||||
/// <summary>
|
||||
/// Generate all the player pairs
|
||||
/// (players should not play against themself.
|
||||
/// (players should not play twice with the same person)
|
||||
/// </summary>
|
||||
public void GenerateCouples()
|
||||
{
|
||||
for (int i = 1; i < fullPlayers.Count(); i++)
|
||||
{
|
||||
Player secondPlayer = fullPlayers[i];
|
||||
|
||||
if (basePlayer.id != secondPlayer.id)
|
||||
{
|
||||
propositions.Add(Guid.NewGuid().ToString(), new Proposition() { owner = secondPlayer });
|
||||
fullPlayers.RemoveAt(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
questions.Add(Guid.NewGuid().ToString(), new Question()
|
||||
{
|
||||
promptId = prompt.id,
|
||||
propositions = propositions,
|
||||
creationDate = DateTime.Now.ToOADate(),
|
||||
});
|
||||
}
|
||||
|
||||
string JSON = JsonConvert.SerializeObject(questions);
|
||||
realtimeDB.Child("rooms").Child(myRoom.code).Child("questions").SetRawJsonValueAsync(JSON);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user