React to Client changes and show them in Lobby.razor.
I tested this on Multiplayer and realized pretty much everything is broken and I haven't been thinking about networking enough. Will start fixing tomorrow.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace LuckerParty;
|
||||
|
||||
/// <summary>
|
||||
@@ -10,11 +12,15 @@ public sealed class NetworkManager : Component, Component.INetworkListener
|
||||
/// </summary>
|
||||
private readonly Dictionary<Connection, GameObject> _clientMap = new();
|
||||
|
||||
private readonly List<Client> _clients = new();
|
||||
|
||||
/// <summary>
|
||||
/// A GameObject used for organizational grouping of Clients
|
||||
/// </summary>
|
||||
private GameObject _clientGroup;
|
||||
|
||||
public ImmutableList<Client> Clients => _clients.ToImmutableList();
|
||||
|
||||
public void OnActive( Connection channel )
|
||||
{
|
||||
// Set up the Client GameObject
|
||||
@@ -25,6 +31,9 @@ public sealed class NetworkManager : Component, Component.INetworkListener
|
||||
|
||||
// Spawn it on remote clients
|
||||
gameObject.NetworkSpawn( channel );
|
||||
|
||||
_clients.Add( client );
|
||||
IClientEvent.Post( e => e.OnConnected( client ) );
|
||||
}
|
||||
|
||||
public void OnDisconnected( Connection channel )
|
||||
@@ -35,8 +44,12 @@ public sealed class NetworkManager : Component, Component.INetworkListener
|
||||
return;
|
||||
}
|
||||
|
||||
var client = clientGameObject.GetComponent<Client>();
|
||||
IClientEvent.Post( e => e.OnDisconnected( client ) );
|
||||
|
||||
clientGameObject.Destroy();
|
||||
_clientMap.Remove( channel );
|
||||
_clients.Remove( client );
|
||||
}
|
||||
|
||||
protected override void OnAwake()
|
||||
@@ -48,4 +61,13 @@ public sealed class NetworkManager : Component, Component.INetworkListener
|
||||
{
|
||||
_clientGroup.Destroy();
|
||||
}
|
||||
|
||||
public interface IClientEvent : ISceneEvent<IClientEvent>
|
||||
{
|
||||
void OnConnected( Client client )
|
||||
{
|
||||
}
|
||||
|
||||
void OnDisconnected( Client client ) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,49 @@
|
||||
@namespace LuckerParty.UI
|
||||
@using System
|
||||
@inherits PanelComponent
|
||||
@using System
|
||||
@using System.Collections.Immutable
|
||||
@implements NetworkManager.IClientEvent
|
||||
|
||||
<root>
|
||||
<div class="title">This is the Lobby</div>
|
||||
@foreach ( var client in _clients )
|
||||
{
|
||||
<div>@client.Name</div>
|
||||
}
|
||||
</root>
|
||||
|
||||
@code
|
||||
{
|
||||
public List<Client> Clients { get; set; }
|
||||
private ImmutableList<Client> _clients;
|
||||
private NetworkManager _networkManager;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
_networkManager = Scene.GetComponentInChildren<NetworkManager>();
|
||||
UpdateClients();
|
||||
}
|
||||
|
||||
void NetworkManager.IClientEvent.OnConnected( Client client )
|
||||
{
|
||||
UpdateClients();
|
||||
}
|
||||
|
||||
void NetworkManager.IClientEvent.OnDisconnected( Client client )
|
||||
{
|
||||
UpdateClients();
|
||||
}
|
||||
|
||||
private void UpdateClients()
|
||||
{
|
||||
_clients = _networkManager.Clients.Sort( ( clientA, clientB ) => DateTimeOffset.Compare( clientA.ConnectionTime, clientB.ConnectionTime ) );
|
||||
}
|
||||
|
||||
/// <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( Clients );
|
||||
return HashCode.Combine( _clients );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGameObject_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Faa27c7b340a656c1115d184d1479be2351258530dbcfba1a3ffeff49f3345446_003FGameObject_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGameObjectSystem_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F76b045f8cca7c6eeaa4299eff84149b33e2523235887981e9d901d8c4355d_003FGameObjectSystem_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGame_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F262292e54674e2ebba95aeee93cb92cef46fb49c92f9c6f8cf9773747f3f9cc1_003FGame_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AImmutableList_005F1_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4d717d2cb7d74d9eab97d2c551ed3060188bfccc274693358b72f36430f1a87e_003FImmutableList_005F1_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetworkListener_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3cc5b51c5aea65c42c751f995b276f555b6431d9e7685558d90d3f3d381bc_003FINetworkListener_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetworkListener_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fbdd02fd1a914f886538cdccaadc6c813d1b5badfd9fa44d714323b7978b49fe_003FINetworkListener_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AInterop_002EEngine_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6efc782a71943dcfe1724f2ab146a2cda4ce446a274ef98adb11282191_003FInterop_002EEngine_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIRootPanelComponent_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fd597463440aa64db88ab1120e3352a3274112098fef51ce93761058f53f68_003FIRootPanelComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
|
||||
Reference in New Issue
Block a user