4 Commits

Author SHA1 Message Date
28ddf93a48 add user DotSettings to .gitignore 2024-12-23 04:12:21 -08:00
b998846138 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.
2024-12-23 04:05:37 -08:00
10c6caca0d Merge remote-tracking branch 'origin/master'
# Conflicts:
#	code/UI/Lobby.razor
2024-12-23 03:17:01 -08:00
0fffa21ff1 Refactors, Introduce GameManager, Lobby work, Docs 2024-12-23 03:16:30 -08:00
5 changed files with 94 additions and 24 deletions

1
.gitignore vendored
View File

@@ -11,6 +11,7 @@ bin
Properties/* Properties/*
code/obj/* code/obj/*
code/Properties/* code/Properties/*
*.sln.DotSettings.user
# Auto-generated asset related files # Auto-generated asset related files
.sbox/* .sbox/*

22
code/GameManager.cs Normal file
View 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>();
}
}

View File

@@ -1,3 +1,5 @@
using System.Collections.Immutable;
namespace LuckerParty; namespace LuckerParty;
/// <summary> /// <summary>
@@ -10,11 +12,15 @@ public sealed class NetworkManager : Component, Component.INetworkListener
/// </summary> /// </summary>
private readonly Dictionary<Connection, GameObject> _clientMap = new(); private readonly Dictionary<Connection, GameObject> _clientMap = new();
private readonly List<Client> _clients = new();
/// <summary> /// <summary>
/// A GameObject used for organizational grouping of Clients /// A GameObject used for organizational grouping of Clients
/// </summary> /// </summary>
private GameObject _clientGroup; private GameObject _clientGroup;
public ImmutableList<Client> Clients => _clients.ToImmutableList();
public void OnActive( Connection channel ) public void OnActive( Connection channel )
{ {
// Set up the Client GameObject // Set up the Client GameObject
@@ -25,6 +31,9 @@ public sealed class NetworkManager : Component, Component.INetworkListener
// Spawn it on remote clients // Spawn it on remote clients
gameObject.NetworkSpawn( channel ); gameObject.NetworkSpawn( channel );
_clients.Add( client );
IClientEvent.Post( e => e.OnConnected( client ) );
} }
public void OnDisconnected( Connection channel ) public void OnDisconnected( Connection channel )
@@ -35,8 +44,12 @@ public sealed class NetworkManager : Component, Component.INetworkListener
return; return;
} }
var client = clientGameObject.GetComponent<Client>();
IClientEvent.Post( e => e.OnDisconnected( client ) );
clientGameObject.Destroy(); clientGameObject.Destroy();
_clientMap.Remove( channel ); _clientMap.Remove( channel );
_clients.Remove( client );
} }
protected override void OnAwake() protected override void OnAwake()
@@ -48,4 +61,13 @@ public sealed class NetworkManager : Component, Component.INetworkListener
{ {
_clientGroup.Destroy(); _clientGroup.Destroy();
} }
public interface IClientEvent : ISceneEvent<IClientEvent>
{
void OnConnected( Client client )
{
}
void OnDisconnected( Client client ) { }
}
} }

49
code/UI/Lobby.razor Normal file
View File

@@ -0,0 +1,49 @@
@namespace LuckerParty.UI
@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
{
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 );
}
}

View File

@@ -1,24 +0,0 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AComponent_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6553e8794aae3c475eef751add553eb427babf32c98ad3ab1988efd1485c_003FComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConnection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F02714d79d02643c6a10a82f861205a18263400_003Fde_003Fd5c8baea_003FConnection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConnection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F19abf87070324a24a498e06d51eb783a263600_003F8b_003Fa645f6c8_003FConnection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConnection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4b00eb25dc4a4faab4a2bdf678a7e77c263400_003Ff4_003F6681afe0_003FConnection_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
<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_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>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AModelRenderer_002EAttachments_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fb26ca1467e599f1ba7f72867e56dd242371c9e01e56f4d81dedcf73618d973a_003FModelRenderer_002EAttachments_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AModelRenderer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fd9493723581e2c8a31b40577dacf1686f31933848f3532d945b83a8527f799_003FModelRenderer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetworking_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F19abf87070324a24a498e06d51eb783a263600_003Ff3_003F9c09fbee_003FNetworking_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APanelComponent_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fdfe3022753e9e5aaa3b2d15b5c5d6e3c43b814e0ba32841351d1e1b89c661_003FPanelComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerController_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3f23c368a4d12fb02b7ab5e07a8cc801bbd19279b7215bc49c3bd3528f2b4e4_003FPlayerController_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASceneModel_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F19abf87070324a24a498e06d51eb783a263600_003F73_003F68917622_003FSceneModel_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASceneObject_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4b00eb25dc4a4faab4a2bdf678a7e77c263400_003Fdf_003Ffb83ae92_003FSceneObject_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AScreenPanel_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F7f5dea8cfde9dabf40f4c55f473c8604a3ec722c29ebaa2d466ab10cbd58a98_003FScreenPanel_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASkinnedModelRenderer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F401fb1a56c933b39db4639ec2a82ab1b14c40fea138d04f429c8440a2e7e7_003FSkinnedModelRenderer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATCPClient_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F212760d42b6ac7f5778e2cb7bd6eec0eb5edc15575b9775855c7a77f8363_003FTCPClient_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="D:\SteamLibrary\steamapps\common\sbox\bin\managed\Sandbox.Game.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>