Snaparazzi/Assets/Scripts/QuestionHandler.cs

68 lines
1.8 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;
private int currentQuestion = 0;
void OnEnable()
{
player2questions = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer);
Redraw(++currentQuestion);
}
void OnDisable()
{
player2questions = null;
}
void Redraw(int currentQuestion)
{
Prompt prompt = promptList.prompts.Find(x => x.id == player2questions[currentQuestion - 1].promptId);
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) {
Redraw(++currentQuestion);
} 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()
{
}
}