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)
{
Debug.Log("begin OnRoomUpdate");
GameState lastState = (GameState)myRoom.currentState;
try
{
if (e?.Snapshot?.GetRawJsonValue() != null)
{
string JSON = e.Snapshot.GetRawJsonValue();
@ -299,6 +302,33 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
Debug.Log("myroom is null");
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)
{
case (int)GameState.EnteringName:
@ -309,14 +339,6 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
HomeConnection.SetActive(true);
}
break;
}
case (int)GameState.WaitingForOtherPlayersToJoin:
{
CheckIfIAmTheFirst(myRoom.GetPlayerList());
UpdateDisplayedListUser(myRoom.GetPlayerList());
break;
}
case (int)GameState.Explanation:
@ -328,7 +350,6 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
WaitingRoom.SetActive(false);
BeforeStart.SetActive(true);
endOfViewDate = DateTime.Now.AddSeconds(4);
break;
}
case (int)GameState.MakeProposition:
@ -338,9 +359,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
BeforeStart.SetActive(false);
TakePicture.SetActive(true);
endOfViewDate = DateTime.Now.AddSeconds(60);
}
break;
}
case (int)GameState.PropositionsSent:
@ -477,7 +496,10 @@ public void onClickNewPlayers()
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)
{

View File

@ -16,8 +16,11 @@ public class PropositionHandler : MonoBehaviour
public void ShowQuestion(Question currentQuestion)
{
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++)
{
int index = i; // Capture la valeur de i pour cette itération

View File

@ -2,13 +2,16 @@
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class QuestionHandler : MonoBehaviour
{
public GameObject managers;
private GameManager gameManager;
public Button submitButton;
public TextMeshProUGUI explainText;
public PromptList promptList;
private GameManager gameManager;
private List<Question> player2questions;
private int currentQuestion = 0;
@ -42,34 +45,36 @@ int GetPropRef(Player player)
public void OnSubmitButton()
{
submitButton.interactable = false;
submitButton.GetComponent<TextMeshProUGUI>().text = "Uploading...";
managers.GetComponent<StorageManager>().UploadPhoto(
gameManager.myRoom.code,
gameManager.currentPlayer.id,
currentQuestion,
GetPropRef(gameManager.currentPlayer));
GetPropRef(gameManager.currentPlayer), succeed =>
{
if(!succeed)
{
Debug.LogError("Photo upload failed. please do something", this);
return;
}
if (currentQuestion == 1)
{
gameManager.myRoom.currentState = (int)GameState.PropositionsSent;
gameManager.WaitForPlayers();
return;
}
else
{
currentQuestion++;
Redraw(currentQuestion);
}
}
// Start is called before the first frame update
void Start()
{
if (currentQuestion == 1)
{
gameManager.myRoom.currentState = (int)GameState.PropositionsSent;
gameManager.WaitForPlayers();
return;
}
else
{
submitButton.interactable = true;
submitButton.GetComponent<TextMeshProUGUI>().text = "Submit";
currentQuestion++;
Redraw(currentQuestion);
}
});
}
// 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();
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)
{
callback_OnPhotoUploaded?.Invoke(false);
Debug.LogException(task.Exception);
// Uh-oh, an error occurred!
}
else
{
callback_OnPhotoUploaded?.Invoke(true);
realtimeDB
.Child("rooms")
.Child(roomCode)