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_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
rgba: 4278253567
m_fontColor: {r: 1, g: 0.97053784, b: 0, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
@ -4193,6 +4193,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
managers: {fileID: 429358648}
submitButton: {fileID: 885941125}
explainText: {fileID: 2139867527}
promptList: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2}
--- !u!1 &1202782726

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)