fix: upload image

This commit is contained in:
Michel Roux 2024-01-28 13:25:17 +01:00
parent 92337afda7
commit 98b783ab76
3 changed files with 16 additions and 16 deletions

View File

@ -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>();
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);

View File

@ -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);
}

View File

@ -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<CameraManager>().GetPhoto();
byte[] photoBytes = ImageConversion.EncodeToJPG(photo);
@ -41,7 +41,7 @@ public void UploadPhoto(string roomCode, string playerId, string questionRef, st
GameManager game = gameObject.GetComponent<GameManager>();
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<StorageMetadata> 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);
}
});