From 98b783ab76ce7b97e5d78392a2982db8a863f5ec Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 28 Jan 2024 13:25:17 +0100 Subject: [PATCH] fix: upload image --- Assets/Scripts/QuestionHandler.cs | 15 ++++----------- Assets/Scripts/RoomManager.cs | 1 + Assets/Scripts/StorageManager.cs | 16 +++++++++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/QuestionHandler.cs b/Assets/Scripts/QuestionHandler.cs index bd9edc5..55e5044 100644 --- a/Assets/Scripts/QuestionHandler.cs +++ b/Assets/Scripts/QuestionHandler.cs @@ -32,26 +32,19 @@ void Redraw(int currentQuestion) cameraManager.WebcamResume(); } - string GetQuestionRef(string promptId) + string GetPropRef(string playerId) { - 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; + return gameManager.myRoom.questions[(currentQuestion - 1).ToString()].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)); + currentQuestion, + GetPropRef(gameManager.currentPlayer.id)); if (currentQuestion < 2) { Redraw(++currentQuestion); diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index 368bfa4..fc732cc 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -322,6 +322,7 @@ public void GeneratePrompts() creationDate = DateTime.Now.ToOADate(), }); } + string JSON = JsonConvert.SerializeObject(questions); realtimeDB.Child("rooms").Child(myRoom.code).Child("questions").SetRawJsonValueAsync(JSON); } diff --git a/Assets/Scripts/StorageManager.cs b/Assets/Scripts/StorageManager.cs index c8921a5..227bf9d 100644 --- a/Assets/Scripts/StorageManager.cs +++ b/Assets/Scripts/StorageManager.cs @@ -33,7 +33,7 @@ void Update() } - public void UploadPhoto(string roomCode, string playerId, string questionRef, string propRef) + public void UploadPhoto(string roomCode, string playerId, int question, string proposition) { Texture2D photo = gameObject.GetComponent().GetPhoto(); byte[] photoBytes = ImageConversion.EncodeToJPG(photo); @@ -41,7 +41,7 @@ public void UploadPhoto(string roomCode, string playerId, string questionRef, st GameManager game = gameObject.GetComponent(); string imageUuid = Guid.NewGuid().ToString(); - StorageReference imageRef = storage.Child($"{game.myRoom.code}/{game.currentPlayer.id}/{imageUuid}.png"); + StorageReference imageRef = storage.Child($"{roomCode}/{playerId}/{imageUuid}.png"); imageRef.PutBytesAsync(photoBytes).ContinueWith((Task task) => { @@ -52,9 +52,15 @@ public void UploadPhoto(string roomCode, string playerId, string questionRef, st } else { - // Metadata contains file metadata such as size, content-type, and md5hash. - StorageMetadata metadata = task.Result; - + realtimeDB + .Child("rooms") + .Child(roomCode) + .Child("questions") + .Child(question.ToString()) + .Child("propositions") + .Child(proposition) + .Child("photoUrl") + .SetValueAsync(imageRef.Path); } });