feat: client configuration file added
This commit is contained in:
11
Platforms/Desktop/ClientConfiguration.cs
Normal file
11
Platforms/Desktop/ClientConfiguration.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
public class ClientConfiguration
|
||||
{
|
||||
public bool Host = false;
|
||||
public int HostPort = 8888;
|
||||
|
||||
public string ServerAddress = "localhost";
|
||||
public int ServerPort = 8888;
|
||||
|
||||
public int windowWidth = 1024;
|
||||
public int windowHeight = 576;
|
||||
}
|
@@ -39,6 +39,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../Shared/Shared.csproj" />
|
||||
<ProjectReference Include="..\..\Engine\Engine.Serializers\Engine.Serializers.Yaml\Engine.Serializers.Yaml.csproj" />
|
||||
</ItemGroup>
|
||||
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
|
||||
<Message Text="Restoring dotnet tools" Importance="High" />
|
||||
|
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
using Pong;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Debug;
|
||||
using Syntriax.Engine.Core.Serialization;
|
||||
@@ -24,21 +21,34 @@ logger = new LoggerWrapper(logger, new ConsoleLogger());
|
||||
|
||||
universe.InstantiateUniverseObject().SetUniverseObject("Logger").BehaviourController.AddBehaviour<LoggerContainer>().Logger = logger;
|
||||
|
||||
bool isServerEnabled = Environment.GetCommandLineArgs().FirstOrDefault(x => x.CompareTo("--server") == 0) is not null;
|
||||
string settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.yaml");
|
||||
ClientConfiguration clientConfiguration;
|
||||
try
|
||||
{
|
||||
clientConfiguration = serializer.Deserialize<ClientConfiguration>(File.ReadAllText(settingsPath));
|
||||
logger.Log(clientConfiguration, $"{settingsPath} read");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
clientConfiguration = new();
|
||||
logger.LogError(serializer, $"Error loading {settingsPath}. Creating new settings file");
|
||||
logger.LogException(serializer, exception);
|
||||
File.WriteAllText(settingsPath, serializer.Serialize(clientConfiguration));
|
||||
}
|
||||
|
||||
if (isServerEnabled)
|
||||
PongUniverse.ApplyPongServer(universe, 8888);
|
||||
if (clientConfiguration.Host)
|
||||
Pong.PongUniverse.ApplyPongServer(universe, clientConfiguration.HostPort);
|
||||
|
||||
PongUniverse.ApplyPongClient(universe, "localhost", 8888);
|
||||
PongUniverse.ApplyPongUniverse(universe);
|
||||
Pong.PongUniverse.ApplyPongClient(universe, clientConfiguration.ServerAddress, clientConfiguration.ServerPort);
|
||||
Pong.PongUniverse.ApplyPongUniverse(universe);
|
||||
|
||||
universe.InstantiateUniverseObject().SetUniverseObject("Desktop HO")
|
||||
.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
||||
|
||||
using MonoGameWindow monoGameWindow = new(universe);
|
||||
|
||||
monoGameWindow.Graphics.PreferredBackBufferWidth = 1024;
|
||||
monoGameWindow.Graphics.PreferredBackBufferHeight = 576;
|
||||
monoGameWindow.Graphics.PreferredBackBufferWidth = clientConfiguration.windowWidth;
|
||||
monoGameWindow.Graphics.PreferredBackBufferHeight = clientConfiguration.windowHeight;
|
||||
monoGameWindow.Graphics.GraphicsProfile = GraphicsProfile.HiDef;
|
||||
|
||||
monoGameWindow.Run();
|
||||
|
Reference in New Issue
Block a user