feat: generatePrompt
This commit is contained in:
parent
a2e2eb5898
commit
5130a1dc4b
@ -1,11 +1,12 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[JsonObject]
|
[JsonObject]
|
||||||
public class Question
|
public class Question
|
||||||
{
|
{
|
||||||
public string promptId;
|
public string promptId;
|
||||||
public Proposition propositions;
|
public Dictionary<string, Proposition> propositions;
|
||||||
public int creationDate;
|
public double creationDate;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ public class GameManager : MonoBehaviour
|
|||||||
private GameState currentState;
|
private GameState currentState;
|
||||||
private List<Player> players = new();
|
private List<Player> players = new();
|
||||||
public Player currentPlayer = null;
|
public Player currentPlayer = null;
|
||||||
public Question currentQuestion = null;
|
|
||||||
|
|
||||||
[Header("Other component")]
|
[Header("Other component")]
|
||||||
public float explanationTime = 4f;
|
public float explanationTime = 4f;
|
||||||
|
@ -25,6 +25,7 @@ private void Initialize()
|
|||||||
{
|
{
|
||||||
FirebaseInitializer.Instance.onFirebaseReady -= Initialize;
|
FirebaseInitializer.Instance.onFirebaseReady -= Initialize;
|
||||||
db = FirebaseFirestore.DefaultInstance;
|
db = FirebaseFirestore.DefaultInstance;
|
||||||
|
LoadPromptsFromFirestore();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
public class RoomManager : MonoBehaviour
|
public class RoomManager : MonoBehaviour
|
||||||
@ -15,6 +14,7 @@ public class RoomManager : MonoBehaviour
|
|||||||
private RoomState currentState;
|
private RoomState currentState;
|
||||||
private Room myRoom = null;
|
private Room myRoom = null;
|
||||||
private List<Player> players;
|
private List<Player> players;
|
||||||
|
public PromptList promptList;
|
||||||
|
|
||||||
public float propositionTime = 60;
|
public float propositionTime = 60;
|
||||||
public float votingTime = 20;
|
public float votingTime = 20;
|
||||||
@ -231,22 +231,41 @@ public void OnPropositionUpdate()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public void GeneratePrompts()
|
||||||
/// Will generate a question with a prompt and two owners
|
|
||||||
/// </summary>
|
|
||||||
public void GenerateQuestion()
|
|
||||||
{
|
{
|
||||||
|
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 });
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
questions.Add(Guid.NewGuid().ToString(), new Question()
|
||||||
/// Generate all the player pairs
|
|
||||||
/// (players should not play against themself.
|
|
||||||
/// (players should not play twice with the same person)
|
|
||||||
/// </summary>
|
|
||||||
public void GenerateCouples()
|
|
||||||
{
|
{
|
||||||
|
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>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user