From a9fd87527e250d17b3ccab3dccc54a9f4e3d9518 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 28 Jan 2024 02:26:57 +0100 Subject: [PATCH 1/2] feat: add GetPropositionsByPlayer --- Assets/Scripts/DatabaseClasses/Room.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Assets/Scripts/DatabaseClasses/Room.cs b/Assets/Scripts/DatabaseClasses/Room.cs index c9f9830..acf0a27 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -33,6 +33,25 @@ public List GetQuestionList() return new List(questions.Values); } + 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; From 608926e0f5ffa5ba6359f2c3fc052cab1fa84976 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 28 Jan 2024 02:40:12 +0100 Subject: [PATCH 2/2] feat: starting to work on upload file --- Assets/Scenes/PhoneView.unity | 24 +++++++-- Assets/Scripts/DatabaseClasses/Room.cs | 21 +++++++- Assets/Scripts/GameManager.cs | 15 +++--- Assets/Scripts/QuestionHandler.cs | 74 ++++++++++++++++++++++++++ Assets/Scripts/QuestionHandler.cs.meta | 11 ++++ Assets/Scripts/StorageManager.cs | 2 +- 6 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 Assets/Scripts/QuestionHandler.cs create mode 100644 Assets/Scripts/QuestionHandler.cs.meta diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index d10c2e9..114fb49 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 acf0a27..cdccfa9 100644 --- a/Assets/Scripts/DatabaseClasses/Room.cs +++ b/Assets/Scripts/DatabaseClasses/Room.cs @@ -33,6 +33,25 @@ public List GetQuestionList() return new List(questions.Values); } + 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(); @@ -52,7 +71,7 @@ public List GetPropositionsByPlayer(Player player) return propositions; } - public void setPlayersAreReady(int _state) + public void SetPlayersAreReady(int _state) { currentState = _state; } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index d1a9992..766e827 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -6,7 +6,6 @@ using Newtonsoft.Json; using TMPro; using UnityEngine; -using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters; /// /// This is the game state manager on the phone side @@ -74,7 +73,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"); @@ -217,12 +216,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; @@ -235,8 +234,6 @@ public void StartGame() { Debug.LogException(ex); } - - } /// @@ -290,10 +287,10 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) { try { - if (e!= null) + if (e != null) { myRoom = JsonConvert.DeserializeObject(e.Snapshot.GetRawJsonValue()); - + } } catch (Exception ex) @@ -362,7 +359,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);