Refactors, Introduce GameManager, Lobby work

This commit is contained in:
2024-12-23 03:15:16 -08:00
parent 299752bd75
commit 9e2fdafa48
9 changed files with 144 additions and 47 deletions

View File

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

25
code/LobbyManager.cs Normal file
View 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 );
}
}

View File

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

View 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; }
}

View File

@@ -1,27 +0,0 @@
@using System
@inherits PanelComponent
@namespace LuckerParty.UI
<root>
<div class="title">Hello, @_name</div>
</root>
@code
{
private string _name;
protected override void OnAwake()
{
base.OnAwake();
_name = GameObject.GetComponent<Client>().Connection.DisplayName;
}
/// <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 );
}
}