diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index 6087da2..8ef0472 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -3385,13 +3385,14 @@ GameObject: m_Component: - component: {fileID: 1181392806} - component: {fileID: 1181392807} + - component: {fileID: 1181392808} m_Layer: 5 m_Name: TakePictureState m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1181392806 RectTransform: m_ObjectHideFlags: 0 @@ -3434,6 +3435,21 @@ MonoBehaviour: freezeButton: {fileID: 223773138} resumeButton: {fileID: 1114535086} photoBox: {fileID: 1316036600} +--- !u!114 &1181392808 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1181392805} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 02a8e72b27188ad7f8079b04e756e652, type: 3} + m_Name: + m_EditorClassIdentifier: + managers: {fileID: 429358648} + explainText: {fileID: 2139867527} + promptList: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2} --- !u!1 &1202782726 GameObject: m_ObjectHideFlags: 0 @@ -6279,9 +6295,9 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 429358652} - m_TargetAssemblyTypeName: StorageManager, Assembly-CSharp - m_MethodName: UploadPhoto + - m_Target: {fileID: 1181392808} + m_TargetAssemblyTypeName: QuestionHandler, Assembly-CSharp + m_MethodName: OnSubmitButton m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index a4c66ce..d8c782a 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -43,7 +43,45 @@ public List GetQuestionList() return new List(questions.Values); } - public void setPlayersAreReady(int _state) + public List GetQuestionsByPlayer(Player player) + { + List questions = new(); + + foreach (Question question in GetQuestionList()) + { + foreach (Proposition proposition in new List(question.propositions.Values)) + { + if (proposition.owner.id == player.id) + { + questions.Add(question); + break; + } + } + } + + return questions; + } + + public List GetPropositionsByPlayer(Player player) + { + List propositions = new(); + + foreach (Question question in GetQuestionList()) + { + foreach (Proposition proposition in new List(question.propositions.Values)) + { + if (proposition.owner.id == player.id) + { + propositions.Add(proposition); + break; + } + } + } + + return propositions; + } + + public void SetPlayersAreReady(int _state) { currentState = _state; } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index a291b06..88a240f 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -7,7 +7,6 @@ using Newtonsoft.Json.Linq; using TMPro; using UnityEngine; -using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters; /// /// This is the game state manager on the phone side @@ -82,7 +81,7 @@ private void OnApplicationQuit() private void Update() { - if (myRoom.currentState == (int)GameState.Explanation && endOfExplanationDate != DateTime.MinValue ) + if (myRoom.currentState == (int)GameState.Explanation && endOfExplanationDate != DateTime.MinValue) { TimeSpan duration = endOfExplanationDate - DateTime.Now; counter.text = ((int)duration.TotalSeconds).ToString("D1"); @@ -220,12 +219,12 @@ private void JoinRoom(Action callback_OnRoomJoined) public void StartGame() { // send Start Game - myRoom.setPlayersAreReady(1); + myRoom.SetPlayersAreReady(1); string JSON = JsonUtility.ToJson(myRoom); Debug.Log(JSON); try { - sendCurrentState(GameState.Explanation, () => + SendCurrentState(GameState.Explanation, () => { Debug.Log($"start the game", this); myRoom.currentState = (int)GameState.Explanation; @@ -238,8 +237,6 @@ public void StartGame() { Debug.LogException(ex); } - - } /// @@ -298,7 +295,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) { string JSON = e.Snapshot.GetRawJsonValue(); myRoom = JsonConvert.DeserializeObject(e.Snapshot.GetRawJsonValue()); - + } } catch (Exception ex) @@ -368,7 +365,7 @@ private void CheckIfIAmTheFirst(List players) submitStartGame.SetActive(true); } } - public void sendCurrentState(GameState state, Action callback_oncCurrentStateSent) + public void SendCurrentState(GameState state, Action callback_oncCurrentStateSent) { myOnlineRoom.Child("currentState").SetValueAsync((int)state).ContinueWithOnMainThread(task => { diff --git a/Assets/Scripts/QuestionHandler.cs b/Assets/Scripts/QuestionHandler.cs new file mode 100644 index 0000000..c313cc2 --- /dev/null +++ b/Assets/Scripts/QuestionHandler.cs @@ -0,0 +1,74 @@ +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 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.WebcamResume(); + } + + string GetQuestionRef(string promptId) + { + return gameManager.myRoom.questions.First(x => x.Value.promptId == promptId).Key; + } + + string GetPropRef(string questionRef, string playerId) + { + return gameManager.myRoom.questions[questionRef].propositions.First(x => x.Value.owner.id == playerId).Key; + } + + public void OnSubmitButton() + { + string questionRef = GetQuestionRef(player2questions[currentQuestion - 1].promptId); + + StorageManager storageManager = managers.GetComponent(); + storageManager.UploadPhoto( + gameManager.myRoom.code, + gameManager.currentPlayer.id, + GetQuestionRef(questionRef), + GetPropRef(questionRef, gameManager.currentPlayer.id)); + + if (currentQuestion < 2) { + Redraw(++currentQuestion); + } else { + gameManager.myRoom.currentState = (int) GameState.PropositionsSent; + } + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/QuestionHandler.cs.meta b/Assets/Scripts/QuestionHandler.cs.meta new file mode 100644 index 0000000..dc2795a --- /dev/null +++ b/Assets/Scripts/QuestionHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 02a8e72b27188ad7f8079b04e756e652 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/StorageManager.cs b/Assets/Scripts/StorageManager.cs index cf1f906..c8921a5 100644 --- a/Assets/Scripts/StorageManager.cs +++ b/Assets/Scripts/StorageManager.cs @@ -33,7 +33,7 @@ void Update() } - public void UploadPhoto() + public void UploadPhoto(string roomCode, string playerId, string questionRef, string propRef) { Texture2D photo = gameObject.GetComponent().GetPhoto(); byte[] photoBytes = ImageConversion.EncodeToJPG(photo);