Refactors, Introduce GameManager, Lobby work, Docs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using LuckerParty.UI;
|
||||
using System;
|
||||
|
||||
namespace LuckerParty;
|
||||
|
||||
@@ -10,9 +10,10 @@ public sealed class Client : Component
|
||||
{
|
||||
public Connection Connection { get; set; }
|
||||
|
||||
public string Name => Connection.DisplayName;
|
||||
public DateTimeOffset ConnectionTime => Connection.ConnectionTime;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
GameObject.AddComponent<ScreenPanel>();
|
||||
GameObject.AddComponent<Hud>();
|
||||
}
|
||||
}
|
||||
|
||||
22
code/GameManager.cs
Normal file
22
code/GameManager.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace LuckerParty;
|
||||
|
||||
/// <summary>
|
||||
/// Manages the Game state, which right now is either Lobby or Round.
|
||||
/// Maintains the lifecycle of the Lobby and Round Managers.
|
||||
/// </summary>
|
||||
public sealed class GameManager : Component
|
||||
{
|
||||
public enum State
|
||||
{
|
||||
Lobby,
|
||||
Round
|
||||
}
|
||||
|
||||
public State CurrentState { get; private set; } = State.Lobby;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
// Start Lobby
|
||||
GameObject.AddComponent<LobbyManager>();
|
||||
}
|
||||
}
|
||||
25
code/LobbyManager.cs
Normal file
25
code/LobbyManager.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using LuckerParty.UI;
|
||||
|
||||
namespace LuckerParty;
|
||||
|
||||
public sealed class LobbyManager : Component
|
||||
{
|
||||
private PanelComponent _panelComponent;
|
||||
|
||||
protected override void OnEnabled()
|
||||
{
|
||||
var screenPanel = Scene.Directory.FindByName( "UI Root" ).First();
|
||||
_panelComponent = screenPanel.AddComponent<Lobby>();
|
||||
}
|
||||
|
||||
protected override void OnDisabled()
|
||||
{
|
||||
_panelComponent.Destroy();
|
||||
_panelComponent = null;
|
||||
}
|
||||
|
||||
public interface ILobbyEvent : ISceneEvent<ILobbyEvent>
|
||||
{
|
||||
void OnStartGame( RoundConfiguration roundConfiguration );
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,12 @@ public sealed class NetworkManager : Component, Component.INetworkListener
|
||||
/// <summary>
|
||||
/// A GameObject used for organizational grouping of Clients
|
||||
/// </summary>
|
||||
private GameObject ClientGroup { get; set; }
|
||||
private GameObject _clientGroup;
|
||||
|
||||
public void OnActive( Connection channel )
|
||||
{
|
||||
// Set up the Client GameObject
|
||||
var gameObject = new GameObject( ClientGroup ) { Name = $"{channel.DisplayName} ({channel.SteamId})" };
|
||||
var gameObject = new GameObject( _clientGroup ) { Name = $"{channel.DisplayName} ({channel.SteamId})" };
|
||||
_clientMap.Add( channel, gameObject );
|
||||
var client = gameObject.AddComponent<Client>();
|
||||
client.Connection = channel;
|
||||
@@ -41,11 +41,11 @@ public sealed class NetworkManager : Component, Component.INetworkListener
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
ClientGroup = new GameObject( Scene.Root );
|
||||
_clientGroup = new GameObject( Scene.Root ) { Name = "Clients", NetworkMode = NetworkMode.Object };
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
ClientGroup.Destroy();
|
||||
_clientGroup.Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
9
code/RoundConfiguration.cs
Normal file
9
code/RoundConfiguration.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace LuckerParty;
|
||||
|
||||
/// <summary>
|
||||
/// Contains configuration for a Round, usually created by the host in a Lobby.
|
||||
/// </summary>
|
||||
public class RoundConfiguration
|
||||
{
|
||||
public uint NumberOfMinigames { get; set; }
|
||||
}
|
||||
@@ -1,27 +1,20 @@
|
||||
@namespace LuckerParty.UI
|
||||
@using System
|
||||
@inherits PanelComponent
|
||||
@namespace LuckerParty.UI
|
||||
|
||||
<root>
|
||||
<div class="title">Hello, @_name</div>
|
||||
<div class="title">This is the Lobby</div>
|
||||
</root>
|
||||
|
||||
@code
|
||||
{
|
||||
|
||||
private string _name;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_name = GameObject.GetComponent<Client>().Connection.DisplayName;
|
||||
}
|
||||
public List<Client> Clients { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
|
||||
/// </summary>
|
||||
protected override int BuildHash()
|
||||
{
|
||||
return HashCode.Combine( _name );
|
||||
return HashCode.Combine( Clients );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user