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