From 043022186fbf63bb5f349f8cebaca04fc9183e65 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Fri, 19 Apr 2024 13:37:28 +0200 Subject: [PATCH] merge options --- TanksServer/GameLogic/GameRules.cs | 12 ++++++++++++ TanksServer/GameLogic/MoveBullets.cs | 2 +- TanksServer/GameLogic/MoveTanks.cs | 4 ++-- TanksServer/GameLogic/PlayersConfiguration.cs | 8 -------- TanksServer/GameLogic/RotateTanks.cs | 4 ++-- TanksServer/GameLogic/ShootFromTanks.cs | 4 ++-- TanksServer/GameLogic/TankSpawnQueue.cs | 2 +- TanksServer/GameLogic/TanksConfiguration.cs | 9 --------- TanksServer/Program.cs | 4 ---- TanksServer/appsettings.json | 19 ++++++++----------- 10 files changed, 28 insertions(+), 40 deletions(-) delete mode 100644 TanksServer/GameLogic/PlayersConfiguration.cs delete mode 100644 TanksServer/GameLogic/TanksConfiguration.cs diff --git a/TanksServer/GameLogic/GameRules.cs b/TanksServer/GameLogic/GameRules.cs index 77de620..50d79e1 100644 --- a/TanksServer/GameLogic/GameRules.cs +++ b/TanksServer/GameLogic/GameRules.cs @@ -9,4 +9,16 @@ internal sealed class GameRules public int MaxPowerUpCount { get; set; } = int.MaxValue; public int BulletTimeoutMs { get; set; } = int.MaxValue; + + public double MoveSpeed { get; set; } + + public double TurnSpeed { get; set; } + + public double ShootDelayMs { get; set; } + + public double BulletSpeed { get; set; } + + public int SpawnDelayMs { get; set; } + + public int IdleTimeoutMs { get; set; } } diff --git a/TanksServer/GameLogic/MoveBullets.cs b/TanksServer/GameLogic/MoveBullets.cs index aa1d7ff..c9a7f1a 100644 --- a/TanksServer/GameLogic/MoveBullets.cs +++ b/TanksServer/GameLogic/MoveBullets.cs @@ -2,7 +2,7 @@ namespace TanksServer.GameLogic; internal sealed class MoveBullets( MapEntityManager entityManager, - IOptions config + IOptions config ) : ITickStep { public Task TickAsync(TimeSpan delta) diff --git a/TanksServer/GameLogic/MoveTanks.cs b/TanksServer/GameLogic/MoveTanks.cs index 31f11ca..04777ed 100644 --- a/TanksServer/GameLogic/MoveTanks.cs +++ b/TanksServer/GameLogic/MoveTanks.cs @@ -2,11 +2,11 @@ namespace TanksServer.GameLogic; internal sealed class MoveTanks( MapEntityManager entityManager, - IOptions options, + IOptions options, MapService map ) : ITickStep { - private readonly TanksConfiguration _config = options.Value; + private readonly GameRules _config = options.Value; public Task TickAsync(TimeSpan delta) { diff --git a/TanksServer/GameLogic/PlayersConfiguration.cs b/TanksServer/GameLogic/PlayersConfiguration.cs deleted file mode 100644 index c21dd37..0000000 --- a/TanksServer/GameLogic/PlayersConfiguration.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace TanksServer.GameLogic; - -public class PlayersConfiguration -{ - public int SpawnDelayMs { get; set; } - - public int IdleTimeoutMs { get; set; } -} \ No newline at end of file diff --git a/TanksServer/GameLogic/RotateTanks.cs b/TanksServer/GameLogic/RotateTanks.cs index f2c04a1..f7c36bf 100644 --- a/TanksServer/GameLogic/RotateTanks.cs +++ b/TanksServer/GameLogic/RotateTanks.cs @@ -2,11 +2,11 @@ namespace TanksServer.GameLogic; internal sealed class RotateTanks( MapEntityManager entityManager, - IOptions options, + IOptions options, ILogger logger ) : ITickStep { - private readonly TanksConfiguration _config = options.Value; + private readonly GameRules _config = options.Value; public Task TickAsync(TimeSpan delta) { diff --git a/TanksServer/GameLogic/ShootFromTanks.cs b/TanksServer/GameLogic/ShootFromTanks.cs index 5475426..ec93503 100644 --- a/TanksServer/GameLogic/ShootFromTanks.cs +++ b/TanksServer/GameLogic/ShootFromTanks.cs @@ -3,11 +3,11 @@ using System.Diagnostics; namespace TanksServer.GameLogic; internal sealed class ShootFromTanks( - IOptions options, + IOptions options, MapEntityManager entityManager ) : ITickStep { - private readonly TanksConfiguration _config = options.Value; + private readonly GameRules _config = options.Value; public Task TickAsync(TimeSpan _) { diff --git a/TanksServer/GameLogic/TankSpawnQueue.cs b/TanksServer/GameLogic/TankSpawnQueue.cs index c0aadb7..e622748 100644 --- a/TanksServer/GameLogic/TankSpawnQueue.cs +++ b/TanksServer/GameLogic/TankSpawnQueue.cs @@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis; namespace TanksServer.GameLogic; internal sealed class TankSpawnQueue( - IOptions options, + IOptions options, MapEntityManager entityManager ): ITickStep { diff --git a/TanksServer/GameLogic/TanksConfiguration.cs b/TanksServer/GameLogic/TanksConfiguration.cs deleted file mode 100644 index 4c02ff2..0000000 --- a/TanksServer/GameLogic/TanksConfiguration.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace TanksServer.GameLogic; - -public class TanksConfiguration -{ - public double MoveSpeed { get; set; } - public double TurnSpeed { get; set; } - public double ShootDelayMs { get; set; } - public double BulletSpeed { get; set; } -} \ No newline at end of file diff --git a/TanksServer/Program.cs b/TanksServer/Program.cs index 02a959e..b5b4b89 100644 --- a/TanksServer/Program.cs +++ b/TanksServer/Program.cs @@ -86,10 +86,6 @@ public static class Program builder.Services.AddSingleton(sp => sp.GetRequiredService()); - builder.Services.Configure( - builder.Configuration.GetSection("Tanks")); - builder.Services.Configure( - builder.Configuration.GetSection("Players")); builder.Services.Configure(builder.Configuration.GetSection("GameRules")); if (hostConfiguration.EnableServicePointDisplay) diff --git a/TanksServer/appsettings.json b/TanksServer/appsettings.json index 5501994..1ef31e6 100644 --- a/TanksServer/appsettings.json +++ b/TanksServer/appsettings.json @@ -19,24 +19,21 @@ "Hostname": "172.23.42.29", "Port": 2342 }, - "Tanks": { + "GameRules": { + "DestructibleWalls": true, + "PowerUpSpawnChance": 0.1, + "MaxPowerUpCount": 15, + "BulletTimeoutMs": 30000, + "SpawnDelayMs": 3000, + "IdleTimeoutMs": 30000, "MoveSpeed": 37.5, "TurnSpeed": 0.5, "ShootDelayMs": 450, "BulletSpeed": 75 }, - "GameRules": { - "DestructibleWalls": true, - "PowerUpSpawnChance": 0.1, - "MaxPowerUpCount": 15 - }, - "Players": { - "SpawnDelayMs": 3000, - "IdleTimeoutMs": 30000 - }, "Host": { "EnableServicePointDisplay": true, - "ServicePointDisplayMinFrameTimeMs": 25, + "ServicePointDisplayMinFrameTimeMs": 28, "ClientScreenMinFrameTime": 5 } }