Merge branch 'main' of ssh://patema.crystalyx.net:2222/GameJams/Snaparazzi

This commit is contained in:
Marine 2024-01-29 22:17:25 +01:00
commit f585b53f4f
5 changed files with 72 additions and 39 deletions

View File

@ -2644,8 +2644,8 @@ MonoBehaviour:
m_fontMaterials: [] m_fontMaterials: []
m_fontColor32: m_fontColor32:
serializedVersion: 2 serializedVersion: 2
rgba: 4294967295 rgba: 4278253567
m_fontColor: {r: 1, g: 1, b: 1, a: 1} m_fontColor: {r: 1, g: 0.97053784, b: 0, a: 1}
m_enableVertexGradient: 0 m_enableVertexGradient: 0
m_colorMode: 3 m_colorMode: 3
m_fontColorGradient: m_fontColorGradient:
@ -4193,6 +4193,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
managers: {fileID: 429358648} managers: {fileID: 429358648}
submitButton: {fileID: 885941125}
explainText: {fileID: 2139867527} explainText: {fileID: 2139867527}
promptList: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2} promptList: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2}
--- !u!1 &1202782726 --- !u!1 &1202782726

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)