Skip to content
Snippets Groups Projects
Commit 34215a8a authored by Palnit's avatar Palnit
Browse files

Clean Code WIP

parent fe4ecd5c
No related branches found
No related tags found
1 merge request!41Visibility again
Pipeline #48186 passed
......@@ -15,24 +15,47 @@ namespace Logic.Managers
{
public class GameNetworkManager : NetworkBehaviour
{
/// <summary>
/// Length of a turn got from lobby
/// </summary>
public float turnTime;
/// <summary>
/// Number of turn got from lobby
/// </summary>
public int turnCount;
/// <summary>
/// Counts the number of connected players
/// </summary>
[FormerlySerializedAs("_connectedCounter")] public ulong connectedCounter = 0;
/// <summary>
/// Players id to their name and team
/// </summary>
public Dictionary<ulong,KeyValuePair<string,string>> _nameToIDDictionary;
/// <summary>
/// Check to get data from lobby only once
/// </summary>
private bool _gotDataFromLobby = false;
/// <summary>
/// Check for a spectator player
/// </summary>
public bool isSpec = false;
public int NumberOfPlayer => _nameToIDDictionary.Count;
/// <summary>
/// Current input data from input system
/// </summary>
public List<InputData> CurrentInputDatas { get; private set; }
public static event Action<Dictionary<ulong,KeyValuePair<string,string>>> OnReady;
/// <summary>
/// Singleton instance
/// </summary>
public static GameNetworkManager Instance { get; private set; }
private void Awake()
......@@ -48,7 +71,10 @@ namespace Logic.Managers
GameManager.OnGameStateChanged += GameManagerOnGameStateChanged;
}
/// <summary>
/// Handel GameState change to clear data
/// </summary>
/// <param name="state">Game state</param>
private void GameManagerOnGameStateChanged(GameState state)
{
if (state == GameState.Turn)
......@@ -57,6 +83,10 @@ namespace Logic.Managers
}
}
/// <summary>
/// Handel Spectator players
/// </summary>
/// <param name="clientRpcParams">Default client rpc params</param>
[ClientRpc]
public void SetSpecClientRpc(ClientRpcParams clientRpcParams = default)
{
......@@ -64,6 +94,9 @@ namespace Logic.Managers
GameEventSystem.OnSetSpec();
}
/// <summary>
/// Gets data from lobby
/// </summary>
private void GetData()
{
string time = LobbyManager.Instance._hostLobby.Data["TurnTime"].Value;
......@@ -94,16 +127,29 @@ namespace Logic.Managers
};
}
/// <summary>
/// Raises event when to set up scene after a load
/// </summary>
public void SetUpScene()
{
OnReady?.Invoke(_nameToIDDictionary);
}
/// <summary>
/// Starts loading next scene
/// </summary>
private void LoadNextScene()
{
SceneLoader.Instance.LoadScene();
}
/// <summary>
/// Gets each clients name and team that are stored local to server
/// </summary>
/// <param name="playerName">the name of the player</param>
/// <param name="team">the team of the player</param>
/// <param name="serverRpcParams">server rpc params</param>
[ServerRpc(RequireOwnership = false)]
private void SendNameServerRpc(string playerName, string team, ServerRpcParams serverRpcParams = default)
{
......@@ -115,6 +161,9 @@ namespace Logic.Managers
}
}
/// <summary>
/// Gives command to clients to send their names trough the SendNameServerRpc
/// </summary>
[ClientRpc]
private void GetNameClientRpc()
{
......@@ -123,11 +172,17 @@ namespace Logic.Managers
}
/// <summary>
/// Clears turn data
/// </summary>
public void ClearTurnData()
{
CurrentInputDatas.Clear();
}
/// <summary>
/// Debuging utility
/// </summary>
[DevCommands("List")]
public void ListCurrentInputData()
{
......@@ -137,6 +192,14 @@ namespace Logic.Managers
}
}
/// <summary>
/// Sends input data to server for validation
/// </summary>
/// <param name="playerObject">the player object of the sender</param>
/// <param name="inputs">the input locations of the sender</param>
/// <param name="type">the type of action</param>
/// <param name="serverRpcParams">server rpc params</param>
[ServerRpc(RequireOwnership = false)]
public void SendDataServerRpc(NetworkObjectReference playerObject , Vector3[] inputs, ActionType type ,ServerRpcParams serverRpcParams = default)
{
......@@ -149,6 +212,10 @@ namespace Logic.Managers
}
}
/// <summary>
/// Input data struct to handel input data
/// </summary>
public struct InputData : IComparable<InputData>
{
public ulong Invoker;
......
......@@ -7,6 +7,9 @@ namespace Logic.MultiPlayer
{
public class Authentication : MonoBehaviour
{
/// <summary>
/// Singleton Instance
/// </summary>
public static Authentication Instance { get; private set; }
void Awake()
......
......@@ -11,8 +11,15 @@ using UnityEngine;
namespace Logic.MultiPlayer.LobbyScripts
{
public class LobbyManager : MonoBehaviour
{
{
/// <summary>
/// Singleton Instance
/// </summary>
public static LobbyManager Instance { get; private set; }
/// <summary>
/// Event to handel when the list of lobbies changed
/// </summary>
public event EventHandler<LobbyEventArgs> LobbyListChangedEvent;
public event EventHandler<LobbyEventArgs> LobbyChangedEvent;
......
......@@ -11,6 +11,9 @@ namespace Logic.MultiPlayer.Relay
{
public class RelayManager : MonoBehaviour
{
/// <summary>
/// Singleton Instance
/// </summary>
public static RelayManager Instance { get; private set; }
......@@ -27,6 +30,12 @@ namespace Logic.MultiPlayer.Relay
DontDestroyOnLoad(this);
}
/// <summary>
/// Async function for the creation of a relay allocation
/// </summary>
/// <param name="maxPlayers">max number of players for the relay</param>
/// <returns>the join code of the relay</returns>
public async Task<string> CreateRelay(int maxPlayers)
{
try
......@@ -51,7 +60,10 @@ namespace Logic.MultiPlayer.Relay
}
/// <summary>
/// async join function to a relay trough join code
/// </summary>
/// <param name="joinCode">the join code of the relay someone wishes to join</param>
public async void JoinRelay(string joinCode)
{
try
......
......@@ -10,6 +10,9 @@ namespace Logic.MultiPlayer
{
public class SceneLoader : NetworkBehaviour
{
/// <summary>
/// Singleton Instance
/// </summary>
public static SceneLoader Instance {get; private set; }
private void Awake()
......@@ -23,17 +26,27 @@ namespace Logic.MultiPlayer
GameEventSystem.CountDownFinished += CountDownFinished;
}
/// <summary>
/// When the count down finished updates game state to turn to start the game
/// </summary>
private void CountDownFinished()
{
GameManager.Instance.UpdateGameState(GameState.Turn);
}
/// <summary>
/// Starts loading the Game scene
/// </summary>
public void LoadScene()
{
Debug.Log("<color=yellow>Loading Scene</color>");
NetworkManager.Singleton.SceneManager.LoadScene("gameScene",LoadSceneMode.Single);
}
/// <summary>
/// Coroutine to handel loading progression and raising event to display it on the screen
/// </summary>
/// <param name="asyncOperation">async operator of loading progress </param>
private IEnumerator GetLoadingProgress(AsyncOperation asyncOperation)
{
GameEventSystem.OnIsLoading(true);
......@@ -44,6 +57,9 @@ namespace Logic.MultiPlayer
}
}
/// <summary>
/// Coroutine to handel loading progression of the map setup
/// </summary>
IEnumerator GetMapProgeress()
{
while (!MapManager.Instance.isDone.Value)
......@@ -53,6 +69,9 @@ namespace Logic.MultiPlayer
}
}
/// <summary>
/// Coroutine waiter for the different kind of coroutines that make up the whole loading progress
/// </summary>
IEnumerator CorutinWaiter()
{
yield return StartCoroutine(GetMapProgeress());
......@@ -64,7 +83,10 @@ namespace Logic.MultiPlayer
/// <summary>
/// callback function for the Scene event types
/// </summary>
/// <param name="sceneEvent">the current scene Loading event</param>
public void SceneEventCallback(SceneEvent sceneEvent)
{
Debug.Log(sceneEvent.SceneEventType);
......
using System.Threading.Tasks;
using Logic.MultiPlayer;
using Logic.MultiPlayer.LobbyScripts;
using UI.LobbyScripts;
......@@ -17,10 +18,7 @@ public class QuickStart : MonoBehaviour
if (Input.GetKeyDown(host))
{
await Authentication.Instance.Authenticate("asd");
LobbyManager.Instance.CreateLobby("Quick Start Lobby",2,"02:00","10000");
JoinedLobbyUI.Instance.gameObject.SetActive(true);
await StartHost();
}
if (Input.GetKeyDown(join))
......@@ -34,4 +32,12 @@ public class QuickStart : MonoBehaviour
}
}
public async Task StartHost()
{
await Authentication.Instance.Authenticate("asd");
LobbyManager.Instance.CreateLobby("Quick Start Lobby",2,"02:00","10000");
JoinedLobbyUI.Instance.gameObject.SetActive(true);
}
}
{
"name": "main",
"rootNamespace": "",
"references": [
"GUID:3b8ed52f1b5c64994af4c4e0aa4b6c4b",
"GUID:1491147abca9d7d4bb7105af628b223e",
"GUID:5540e30183c82e84b954c033c388e06c",
"GUID:a7bd734826f425647b50738e89d1cf9c",
"GUID:84dd41370e50e46aa84025cec29abd60",
"GUID:4c3f49d89436d478ea78315c03159dcc",
"GUID:52d45d90aeae1ee489a3b5765d20127a"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
\ No newline at end of file
fileFormatVersion: 2
guid: ab108d9737afe6a4897e78fed9e4d9b4
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment