fix: players can (hopefully) vote
This commit is contained in:
parent
099d717427
commit
edd04888ed
@ -1,5 +1,6 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[JsonObject]
|
[JsonObject]
|
||||||
@ -7,6 +8,32 @@ public class Proposition
|
|||||||
{
|
{
|
||||||
public string photoUrl;
|
public string photoUrl;
|
||||||
public Player owner;
|
public Player owner;
|
||||||
public string[] voters;
|
public List<string> voters;
|
||||||
public double creationDate;
|
public double creationDate;
|
||||||
|
|
||||||
|
[JsonConstructor]
|
||||||
|
public Proposition(string _photoUrl, Player _owner, List<string> _voters, double _creationDate)
|
||||||
|
{
|
||||||
|
photoUrl = _photoUrl;
|
||||||
|
owner = null;
|
||||||
|
voters = _voters;
|
||||||
|
creationDate = _creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Proposition()
|
||||||
|
{
|
||||||
|
photoUrl = string.Empty;
|
||||||
|
owner = null;
|
||||||
|
voters = new List<string>();
|
||||||
|
creationDate = DateTime.Now.ToOADate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Proposition(Player _player)
|
||||||
|
{
|
||||||
|
photoUrl = string.Empty;
|
||||||
|
owner = _player;
|
||||||
|
voters = new List<string>();
|
||||||
|
creationDate = DateTime.Now.ToOADate();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -488,12 +488,21 @@ private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Call this function from the vote button in the scene
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propositionNumber"></param>
|
||||||
public void OnClickProposition(int propositionNumber)
|
public void OnClickProposition(int propositionNumber)
|
||||||
{
|
{
|
||||||
List<string> voters = myRoom.questions[myRoom.currentQuestionId].propositions[propositionNumber].voters.ToList<string>();
|
Debug.Log($"Room has {myRoom.questions.Count} questions. the current Question is Q({myRoom.currentQuestionId}).");
|
||||||
|
Debug.Log($"Q({myRoom.currentQuestionId}) has {myRoom.questions[myRoom.currentQuestionId].propositions.Count} propositions.");
|
||||||
|
Debug.Log($"Player click on proposition {propositionNumber}.");
|
||||||
|
Debug.Log($"it has {myRoom.questions[myRoom.currentQuestionId].propositions[propositionNumber].voters.Count} voters.");
|
||||||
|
|
||||||
|
List<string> voters = myRoom.questions[myRoom.currentQuestionId].propositions[propositionNumber].voters;
|
||||||
voters.Add(currentPlayer.id);
|
voters.Add(currentPlayer.id);
|
||||||
myOnlineRoom.Child("questions").Child(myRoom.currentQuestionId.ToString()).Child("propositions").Child(propositionNumber.ToString()).Child("voters").SetValueAsync(voters);
|
myOnlineRoom.Child("questions").Child(myRoom.currentQuestionId.ToString()).Child("propositions").Child(propositionNumber.ToString()).Child("voters").SetValueAsync(voters);
|
||||||
|
|
||||||
myRoom.currentState = (int)GameState.VoteSent;
|
myRoom.currentState = (int)GameState.VoteSent;
|
||||||
WaitingOtherPlayers.SetActive(true);
|
WaitingOtherPlayers.SetActive(true);
|
||||||
VotePicture.SetActive(false);
|
VotePicture.SetActive(false);
|
||||||
|
@ -181,11 +181,7 @@ public void GeneratePrompts()
|
|||||||
|
|
||||||
for (int j = 0; j < 2; j++)
|
for (int j = 0; j < 2; j++)
|
||||||
{
|
{
|
||||||
propositions.Add(j, new Proposition()
|
propositions.Add(j, new Proposition(players[i + j < players.Count() ? i + j : 0]));
|
||||||
{
|
|
||||||
owner = players[i + j < players.Count() ? i + j : 0],
|
|
||||||
creationDate = DateTime.Now.ToOADate()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
questions.Add(i, new Question()
|
questions.Add(i, new Question()
|
||||||
|
Loading…
Reference in New Issue
Block a user