fix: (i hope) when player vote, it does not display next vote

This commit is contained in:
Fangh 2024-01-29 22:10:52 +01:00
parent 75723a3b06
commit d560dfcee5
4 changed files with 69 additions and 37 deletions

View File

@ -281,8 +281,11 @@ public void StartGame()
private void OnRoomUpdate(object sender, ValueChangedEventArgs e) private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
{ {
Debug.Log("begin OnRoomUpdate"); Debug.Log("begin OnRoomUpdate");
GameState lastState = (GameState)myRoom.currentState;
try try
{ {
if (e?.Snapshot?.GetRawJsonValue() != null) if (e?.Snapshot?.GetRawJsonValue() != null)
{ {
string JSON = e.Snapshot.GetRawJsonValue(); string JSON = e.Snapshot.GetRawJsonValue();
@ -299,6 +302,33 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
Debug.Log("myroom is null"); Debug.Log("myroom is null");
return; return;
} }
if(myRoom.currentState != (int)lastState)
{
OnNewGameState();
}
else
{
//call this every time we are on this state
switch (myRoom.currentState)
{
case (int)GameState.WaitingForOtherPlayersToJoin:
{
CheckIfIAmTheFirst(myRoom.GetPlayerList());
UpdateDisplayedListUser(myRoom.GetPlayerList());
break;
}
default:
break;
}
}
}
/// <summary>
/// Call this when Game state change
/// </summary>
private void OnNewGameState()
{
switch (myRoom.currentState) switch (myRoom.currentState)
{ {
case (int)GameState.EnteringName: case (int)GameState.EnteringName:
@ -309,14 +339,6 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
HomeConnection.SetActive(true); HomeConnection.SetActive(true);
} }
break;
}
case (int)GameState.WaitingForOtherPlayersToJoin:
{
CheckIfIAmTheFirst(myRoom.GetPlayerList());
UpdateDisplayedListUser(myRoom.GetPlayerList());
break; break;
} }
case (int)GameState.Explanation: case (int)GameState.Explanation:
@ -328,7 +350,6 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
WaitingRoom.SetActive(false); WaitingRoom.SetActive(false);
BeforeStart.SetActive(true); BeforeStart.SetActive(true);
endOfViewDate = DateTime.Now.AddSeconds(4); endOfViewDate = DateTime.Now.AddSeconds(4);
break; break;
} }
case (int)GameState.MakeProposition: case (int)GameState.MakeProposition:
@ -338,9 +359,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
BeforeStart.SetActive(false); BeforeStart.SetActive(false);
TakePicture.SetActive(true); TakePicture.SetActive(true);
endOfViewDate = DateTime.Now.AddSeconds(60); endOfViewDate = DateTime.Now.AddSeconds(60);
} }
break; break;
} }
case (int)GameState.PropositionsSent: case (int)GameState.PropositionsSent:
@ -477,7 +496,10 @@ public void onClickNewPlayers()
private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlineValue) private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlineValue)
{ {
Question q = myRoom.questions[onlineValue.Snapshot.Value.ConvertTo<int>()]; int questionId = onlineValue.Snapshot.Value.ConvertTo<int>();
Debug.Log($"new question ! Q{(onlineValue.Snapshot.Value.ConvertTo<int>())}");
Question q = myRoom.questions[questionId];
if (WaitingOtherPlayers.activeInHierarchy) if (WaitingOtherPlayers.activeInHierarchy)
{ {

View File

@ -16,8 +16,11 @@ public class PropositionHandler : MonoBehaviour
public void ShowQuestion(Question currentQuestion) public void ShowQuestion(Question currentQuestion)
{ {
List<Proposition> props = currentQuestion.propositions.Values.ToList(); List<Proposition> props = currentQuestion.propositions.Values.ToList();
promptLabel.text = prompts.GetPromptById(currentQuestion.promptId).en; string enPrompt = prompts.GetPromptById(currentQuestion.promptId).en;
promptLabel.text = enPrompt;
Debug.Log($"Showing Question ({currentQuestion.index}) : {enPrompt}");
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
int index = i; // Capture la valeur de i pour cette itération int index = i; // Capture la valeur de i pour cette itération

View File

@ -2,13 +2,16 @@
using System.Linq; using System.Linq;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
public class QuestionHandler : MonoBehaviour public class QuestionHandler : MonoBehaviour
{ {
public GameObject managers; public GameObject managers;
private GameManager gameManager; public Button submitButton;
public TextMeshProUGUI explainText; public TextMeshProUGUI explainText;
public PromptList promptList; public PromptList promptList;
private GameManager gameManager;
private List<Question> player2questions; private List<Question> player2questions;
private int currentQuestion = 0; private int currentQuestion = 0;
@ -42,11 +45,20 @@ int GetPropRef(Player player)
public void OnSubmitButton() public void OnSubmitButton()
{ {
submitButton.interactable = false;
submitButton.GetComponent<TextMeshProUGUI>().text = "Uploading...";
managers.GetComponent<StorageManager>().UploadPhoto( managers.GetComponent<StorageManager>().UploadPhoto(
gameManager.myRoom.code, gameManager.myRoom.code,
gameManager.currentPlayer.id, gameManager.currentPlayer.id,
currentQuestion, currentQuestion,
GetPropRef(gameManager.currentPlayer)); GetPropRef(gameManager.currentPlayer), succeed =>
{
if(!succeed)
{
Debug.LogError("Photo upload failed. please do something", this);
return;
}
if (currentQuestion == 1) if (currentQuestion == 1)
{ {
@ -56,20 +68,13 @@ public void OnSubmitButton()
} }
else else
{ {
submitButton.interactable = true;
submitButton.GetComponent<TextMeshProUGUI>().text = "Submit";
currentQuestion++; currentQuestion++;
Redraw(currentQuestion); Redraw(currentQuestion);
} }
} });
// Start is called before the first frame update
void Start()
{
} }
// Update is called once per frame
void Update()
{
}
} }

View File

@ -39,7 +39,7 @@ void Update()
} }
public void UploadPhoto(string roomCode, string playerId, int question, int proposition) public void UploadPhoto(string roomCode, string playerId, int question, int proposition, Action<bool> callback_OnPhotoUploaded)
{ {
Texture2D photo = cameraManager.GetPhoto(); Texture2D photo = cameraManager.GetPhoto();
byte[] photoBytes = ImageConversion.EncodeToJPG(photo); byte[] photoBytes = ImageConversion.EncodeToJPG(photo);
@ -53,11 +53,13 @@ public void UploadPhoto(string roomCode, string playerId, int question, int prop
{ {
if (task.IsFaulted || task.IsCanceled) if (task.IsFaulted || task.IsCanceled)
{ {
callback_OnPhotoUploaded?.Invoke(false);
Debug.LogException(task.Exception); Debug.LogException(task.Exception);
// Uh-oh, an error occurred! // Uh-oh, an error occurred!
} }
else else
{ {
callback_OnPhotoUploaded?.Invoke(true);
realtimeDB realtimeDB
.Child("rooms") .Child("rooms")
.Child(roomCode) .Child(roomCode)