From 96bc36cf5eaae138c68c145a6f15d413e10be2af Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sat, 27 Jan 2024 21:07:49 +0100 Subject: [PATCH] style: refacto --- Assets/Scripts/GameManager.cs | 32 +++++--------------------------- Assets/Scripts/StorageManager.cs | 8 ++++---- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index a81c231..c3edb8f 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -1,12 +1,9 @@ using System; -using System.Collections; using System.Collections.Generic; using Firebase.Database; using Firebase.Extensions; using TMPro; using UnityEngine; -using UnityEngine.UI; -using UnityEngine.UIElements; /// /// This is the game state manager on the phone side @@ -14,10 +11,9 @@ public class GameManager : MonoBehaviour { private GameState currentState; - private List players = new List(); + private List players = new(); public Player currentPlayer = null; - - + public Question currentQuestion = null; [Header("Other component")] public float explanationTime = 4f; @@ -30,12 +26,10 @@ public class GameManager : MonoBehaviour public TextMeshProUGUI nameError; public UnityEngine.UI.Button submitNewPlayer; - [Header("WaitingRoom Component")] public TextMeshProUGUI listPlayersUI; public GameObject submitStartGame; - [Header("Pages")] public GameObject HomeConnection; public GameObject WaitingRoom; @@ -45,8 +39,6 @@ public class GameManager : MonoBehaviour public GameObject WaitingOtherPlayers; public GameObject EndGame; - - private DatabaseReference realtimeDB; public Room myRoom; private DatabaseReference myOnlineRoom; @@ -63,7 +55,6 @@ private void Start() submitNewPlayer.interactable = false; } - public GameState GetCurrentState() { return currentState; @@ -85,6 +76,7 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) { nameError.gameObject.SetActive(false); roomError.gameObject.SetActive(false); + if (string.IsNullOrEmpty(_name)) { Debug.LogError("Player name is empty", this); @@ -105,6 +97,7 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) //TODO : MARINE : use the error label to explain to the user that they have forget to put a room code return; } + currentPlayer = new Player(_name); //check if the room exists, if not display an error message @@ -123,7 +116,6 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) JoinRoom(() => { //then subscribe to it - myOnlineRoom.ValueChanged += OnRoomUpdate; currentState = GameState.WaitingForOtherPlayersToJoin; players.Add(currentPlayer); @@ -132,14 +124,9 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code) HomeConnection.SetActive(false); UpdateDisplayedListUser(); - - }); } }); - - - } private void CheckIfRoomExists(string _roomCode, Action callback_Room) @@ -192,8 +179,6 @@ private void JoinRoom(Action callback_OnRoomJoined) { Debug.LogException(ex); } - - } /// @@ -201,14 +186,10 @@ private void JoinRoom(Action callback_OnRoomJoined) /// public void StartGame() { - // send Start Game - + // send Start Game currentState = GameState.Explanation; WaitingRoom.SetActive(false); BeforeStart.SetActive(true); - - - } /// @@ -219,8 +200,6 @@ public void StartGame() public void MakeAProposition(Prompt _prompt) { currentState = GameState.MakeProposition; - - } /// @@ -230,7 +209,6 @@ public void MakeAProposition(Prompt _prompt) public void SubmitProposition() { Proposition temp = new Proposition(); - } /// diff --git a/Assets/Scripts/StorageManager.cs b/Assets/Scripts/StorageManager.cs index 289ed34..af1afe6 100644 --- a/Assets/Scripts/StorageManager.cs +++ b/Assets/Scripts/StorageManager.cs @@ -1,3 +1,4 @@ +using Firebase.Database; using Firebase.Storage; using System; using System.Threading.Tasks; @@ -8,6 +9,7 @@ public class StorageManager : MonoBehaviour public GameObject PicturePlayer; public GameObject Canvas; private FirebaseStorage storage; + private DatabaseReference realtimeDB; void Awake() { @@ -18,6 +20,7 @@ void Initialize() { FirebaseInitializer.Instance.onFirebaseReady -= Initialize; storage = FirebaseStorage.DefaultInstance; + realtimeDB = FirebaseDatabase.DefaultInstance.RootReference; } // Start is called before the first frame update @@ -47,16 +50,13 @@ public void UploadPhoto() { if (task.IsFaulted || task.IsCanceled) { - Debug.Log(task.Exception.ToString()); + Debug.LogException(task.Exception); // Uh-oh, an error occurred! } else { // Metadata contains file metadata such as size, content-type, and md5hash. StorageMetadata metadata = task.Result; - string md5Hash = metadata.Md5Hash; - Debug.Log("Finished uploading..."); - Debug.Log("md5 hash = " + md5Hash); } });