Snaparazzi/Assets/Scripts/QuestionHandler.cs

73 lines
1.9 KiB
C#
Raw Normal View History

2024-01-28 01:40:12 +00:00
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
public class QuestionHandler : MonoBehaviour
{
public GameObject managers;
private GameManager gameManager;
public TextMeshProUGUI explainText;
public PromptList promptList;
private List<Question> player2questions;
2024-01-28 15:19:30 +00:00
private int currentQuestion = 1;
2024-01-28 01:40:12 +00:00
void OnEnable()
{
player2questions = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer);
2024-01-28 15:19:30 +00:00
Debug.Log(currentQuestion);
Debug.Log(JsonUtility.ToJson(player2questions));
Redraw(currentQuestion);
2024-01-28 01:40:12 +00:00
}
void OnDisable()
{
player2questions = null;
2024-01-28 15:19:30 +00:00
currentQuestion = 1;
2024-01-28 01:40:12 +00:00
}
void Redraw(int currentQuestion)
{
Prompt prompt = promptList.prompts.Find(x => x.id == player2questions[currentQuestion - 1].promptId);
2024-01-28 15:19:30 +00:00
Debug.Log(JsonUtility.ToJson(prompt));
2024-01-28 01:40:12 +00:00
explainText.SetText(prompt.en);
CameraManager cameraManager = gameObject.GetComponent<CameraManager>();
cameraManager.WebcamResume();
}
2024-01-28 14:42:32 +00:00
int GetPropRef(Player player)
2024-01-28 01:40:12 +00:00
{
2024-01-28 14:42:32 +00:00
return gameManager.myRoom.questions[currentQuestion - 1].propositions.First(x => x.Value.owner.id == player.id).Key;
2024-01-28 01:40:12 +00:00
}
public void OnSubmitButton()
{
StorageManager storageManager = managers.GetComponent<StorageManager>();
storageManager.UploadPhoto(
gameManager.myRoom.code,
gameManager.currentPlayer.id,
2024-01-28 12:25:17 +00:00
currentQuestion,
2024-01-28 14:42:32 +00:00
GetPropRef(gameManager.currentPlayer));
2024-01-28 01:40:12 +00:00
if (currentQuestion < 2) {
2024-01-28 15:19:30 +00:00
currentQuestion++;
Redraw(currentQuestion);
2024-01-28 01:40:12 +00:00
} else {
gameManager.myRoom.currentState = (int) GameState.PropositionsSent;
}
}
// Start is called before the first frame update
void Start()
{
2024-01-28 01:53:11 +00:00
gameManager = managers.GetComponent<GameManager>();
2024-01-28 01:40:12 +00:00
}
// Update is called once per frame
void Update()
{
}
}