feat: starting to work on upload file

This commit is contained in:
Michel Roux 2024-01-28 02:40:12 +01:00
parent a9fd87527e
commit 608926e0f5
6 changed files with 132 additions and 15 deletions

View File

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

View File

@ -33,6 +33,25 @@ public List<Question> GetQuestionList()
return new List<Question>(questions.Values);
}
public List<Question> GetQuestionsByPlayer(Player player)
{
List<Question> questions = new();
foreach (Question question in GetQuestionList())
{
foreach (Proposition proposition in new List<Proposition>(question.propositions.Values))
{
if (proposition.owner.id == player.id)
{
questions.Add(question);
break;
}
}
}
return questions;
}
public List<Proposition> GetPropositionsByPlayer(Player player)
{
List<Proposition> propositions = new();
@ -52,7 +71,7 @@ public List<Proposition> GetPropositionsByPlayer(Player player)
return propositions;
}
public void setPlayersAreReady(int _state)
public void SetPlayersAreReady(int _state)
{
currentState = _state;
}

View File

@ -6,7 +6,6 @@
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters;
/// <summary>
/// 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);
}
}
/// <summary>
@ -290,7 +287,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
{
try
{
if (e!= null)
if (e != null)
{
myRoom = JsonConvert.DeserializeObject<Room>(e.Snapshot.GetRawJsonValue());
@ -362,7 +359,7 @@ private void CheckIfIAmTheFirst(List<Player> 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 =>
{

View File

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

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 02a8e72b27188ad7f8079b04e756e652
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -33,7 +33,7 @@ void Update()
}
public void UploadPhoto()
public void UploadPhoto(string roomCode, string playerId, string questionRef, string propRef)
{
Texture2D photo = gameObject.GetComponent<CameraManager>().GetPhoto();
byte[] photoBytes = ImageConversion.EncodeToJPG(photo);