separate folders per functionality

This commit is contained in:
Vinzenz Schroeter 2024-04-10 19:25:45 +02:00
parent 7f00160780
commit 0ca6a91a7e
33 changed files with 60 additions and 113 deletions

View file

@ -1,6 +1,4 @@
using TanksServer.Models;
namespace TanksServer.Services;
namespace TanksServer.GameLogic;
internal sealed class BulletManager
{

View file

@ -1,8 +1,4 @@
using TanksServer.Helpers;
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.TickSteps;
namespace TanksServer.GameLogic;
internal sealed class CollideBulletsWithMap(BulletManager bullets, MapService map) : ITickStep
{

View file

@ -1,7 +1,4 @@
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.TickSteps;
namespace TanksServer.GameLogic;
internal sealed class CollideBulletsWithTanks(
BulletManager bullets, TankManager tanks, SpawnQueueProvider spawnQueueProvider

View file

@ -1,9 +1,7 @@
using System.Diagnostics;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TanksServer.TickSteps;
namespace TanksServer.Services;
namespace TanksServer.GameLogic;
internal sealed class GameTickWorker(
IEnumerable<ITickStep> steps,

View file

@ -1,4 +1,4 @@
namespace TanksServer.TickSteps;
namespace TanksServer.GameLogic;
public interface ITickStep
{

View file

@ -1,6 +1,4 @@
using TanksServer.Models;
namespace TanksServer.Services;
namespace TanksServer.GameLogic;
internal sealed class MapService
{

View file

@ -1,7 +1,4 @@
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.TickSteps;
namespace TanksServer.GameLogic;
internal sealed class MoveBullets(BulletManager bullets) : ITickStep
{

View file

@ -1,10 +1,9 @@
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.TickSteps;
namespace TanksServer.GameLogic;
internal sealed class MoveTanks(
TankManager tanks, IOptions<TanksConfiguration> options, MapService map
TankManager tanks,
IOptions<TanksConfiguration> options,
MapService map
) : ITickStep
{
private readonly TanksConfiguration _config = options.Value;

View file

@ -1,7 +1,4 @@
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.TickSteps;
namespace TanksServer.GameLogic;
internal sealed class RotateTanks(TankManager tanks, IOptions<TanksConfiguration> options) : ITickStep
{

View file

@ -1,7 +1,4 @@
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.TickSteps;
namespace TanksServer.GameLogic;
internal sealed class ShootFromTanks(
TankManager tanks,

View file

@ -1,7 +1,4 @@
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.TickSteps;
namespace TanksServer.GameLogic;
internal sealed class SpawnNewTanks(TankManager tanks, MapService map, SpawnQueueProvider queueProvider) : ITickStep
{

View file

@ -1,6 +1,4 @@
using TanksServer.Models;
namespace TanksServer.Services;
namespace TanksServer.GameLogic;
internal sealed class SpawnQueueProvider
{

View file

@ -1,8 +1,6 @@
using System.Collections;
using Microsoft.Extensions.Logging;
using TanksServer.Models;
namespace TanksServer.Services;
namespace TanksServer.GameLogic;
internal sealed class TankManager(ILogger<TankManager> logger) : IEnumerable<Tank>
{

View file

@ -4,4 +4,6 @@ global using System.Collections.Generic;
global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
global using TanksServer.Models;

View file

@ -1,8 +1,7 @@
using TanksServer.Helpers;
using TanksServer.GameLogic;
using TanksServer.ServicePointDisplay;
using TanksServer.Services;
namespace TanksServer.DrawSteps;
namespace TanksServer.Graphics;
internal sealed class BulletDrawer(BulletManager bullets): IDrawStep
{

View file

@ -1,8 +1,7 @@
using TanksServer.DrawSteps;
using TanksServer.GameLogic;
using TanksServer.ServicePointDisplay;
using TanksServer.Services;
namespace TanksServer.TickSteps;
namespace TanksServer.Graphics;
internal sealed class DrawStateToFrame(
IEnumerable<IDrawStep> drawSteps, LastFinishedFrameProvider lastFrameProvider

View file

@ -1,6 +1,6 @@
using TanksServer.ServicePointDisplay;
namespace TanksServer.DrawSteps;
namespace TanksServer.Graphics;
internal interface IDrawStep
{

View file

@ -1,6 +1,6 @@
using TanksServer.ServicePointDisplay;
namespace TanksServer.Services;
namespace TanksServer.Graphics;
internal sealed class LastFinishedFrameProvider
{

View file

@ -1,9 +1,7 @@
using TanksServer.Helpers;
using TanksServer.Models;
using TanksServer.GameLogic;
using TanksServer.ServicePointDisplay;
using TanksServer.Services;
namespace TanksServer.DrawSteps;
namespace TanksServer.Graphics;
internal sealed class MapDrawer(MapService map) : IDrawStep
{

View file

@ -1,10 +1,9 @@
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using TanksServer.Helpers;
using TanksServer.GameLogic;
using TanksServer.ServicePointDisplay;
using TanksServer.Services;
namespace TanksServer.DrawSteps;
namespace TanksServer.Graphics;
internal sealed class TankDrawer : IDrawStep
{

View file

@ -1,7 +1,6 @@
using System.Text.Json.Serialization;
using TanksServer.Models;
namespace TanksServer.Helpers;
namespace TanksServer.Interactivity;
[JsonSerializable(typeof(Player))]
internal sealed partial class AppSerializerContext: JsonSerializerContext;

View file

@ -1,9 +1,8 @@
using System.Diagnostics;
using System.Net.WebSockets;
using System.Threading.Channels;
using Microsoft.Extensions.Logging;
namespace TanksServer.Helpers;
namespace TanksServer.Interactivity;
/// <summary>
/// Hacky class for easier semantics

View file

@ -2,11 +2,9 @@ using System.Diagnostics;
using System.Net.WebSockets;
using System.Threading.Channels;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TanksServer.Helpers;
using TanksServer.ServicePointDisplay;
namespace TanksServer.Servers;
namespace TanksServer.Interactivity;
internal sealed class ClientScreenServer(
ILogger<ClientScreenServer> logger,

View file

@ -1,15 +1,12 @@
using System.Net.WebSockets;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TanksServer.Helpers;
using TanksServer.Models;
namespace TanksServer.Servers;
namespace TanksServer.Interactivity;
internal sealed class ControlsServer(ILogger<ControlsServer> logger, ILoggerFactory loggerFactory)
: IHostedLifecycleService
{
private readonly List<ControlsServerConnection> _connections = new();
private readonly List<ControlsServerConnection> _connections = [];
public Task HandleClient(WebSocket ws, Player player)
{

View file

@ -1,9 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
using TanksServer.Models;
using TanksServer.Services;
using TanksServer.GameLogic;
namespace TanksServer.Servers;
namespace TanksServer.Interactivity;
internal sealed class PlayerServer(ILogger<PlayerServer> logger, SpawnQueueProvider spawnQueueProvider)
{

View file

@ -1,7 +1,7 @@
using TanksServer.Servers;
using TanksServer.Services;
using TanksServer.GameLogic;
using TanksServer.Graphics;
namespace TanksServer.TickSteps;
namespace TanksServer.Interactivity;
internal sealed class SendToClientScreen(
ClientScreenServer clientScreenServer,

View file

@ -1,15 +1,11 @@
using System.Diagnostics;
using TanksServer.Models;
using TanksServer.Services;
using TanksServer.GameLogic;
namespace TanksServer.Helpers;
namespace TanksServer.Models;
internal static class PositionHelpers
{
public static int ToPixelIndex(this PixelPosition position)
{
return position.Y * MapService.PixelsPerRow + position.X;
}
public static int ToPixelIndex(this PixelPosition position) => position.Y * MapService.PixelsPerRow + position.X;
public static PixelPosition GetPixelRelative(this TilePosition position, byte subX, byte subY)
{
@ -31,4 +27,4 @@ internal static class PositionHelpers
X: position.X / MapService.TileSize,
Y: position.Y / MapService.TileSize
);
}
}

View file

@ -1,4 +1,4 @@
using TanksServer.Services;
using TanksServer.GameLogic;
namespace TanksServer.Models;

View file

@ -4,12 +4,10 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using TanksServer.DrawSteps;
using TanksServer.Helpers;
using TanksServer.Servers;
using TanksServer.GameLogic;
using TanksServer.Graphics;
using TanksServer.Interactivity;
using TanksServer.ServicePointDisplay;
using TanksServer.Services;
using TanksServer.TickSteps;
namespace TanksServer;

View file

@ -1,5 +1,3 @@
using TanksServer.Models;
namespace TanksServer.ServicePointDisplay;
internal class DisplayBufferView(byte[] data)

View file

@ -1,6 +1,3 @@
using TanksServer.Helpers;
using TanksServer.Services;
namespace TanksServer.ServicePointDisplay;
internal sealed class PixelDisplayBufferView : DisplayBufferView

View file

@ -1,10 +1,9 @@
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using Microsoft.Extensions.Logging;
using TanksServer.Servers;
using TanksServer.Services;
using TanksServer.TickSteps;
using TanksServer.GameLogic;
using TanksServer.Graphics;
using TanksServer.Interactivity;
namespace TanksServer.ServicePointDisplay;
@ -34,16 +33,19 @@ internal sealed class SendToServicePointDisplay : ITickStep, IDisposable
? new UdpClient(options.Value.Hostname, options.Value.Port)
: null;
_scoresBuffer = new(new(MapService.TilesPerRow, 0), 12, 20);
_scoresBuffer.Rows[0] = "== TANKS! ==";
_scoresBuffer.Rows[1] = "-- scores --";
_scoresBuffer.Rows[17] = "-- join --";
var localIp = GetLocalIp(options.Value.Hostname, options.Value.Port).Split('.');
Debug.Assert(localIp.Length == 4); // were talking legacy ip
_scoresBuffer.Rows[18] = string.Join('.', localIp[..2]);
_scoresBuffer.Rows[19] = string.Join('.', localIp[2..]);
_scoresBuffer = new TextDisplayBuffer(new TilePosition(MapService.TilesPerRow, 0), 12, 20)
{
Rows =
{
[0] = "== TANKS! ==",
[1] = "-- scores --",
[17] = "-- join --",
[18] = string.Join('.', localIp[..2]),
[19] = string.Join('.', localIp[2..])
}
};
}
private static string GetLocalIp(string host, int port)

View file

@ -1,5 +1,3 @@
using TanksServer.Models;
namespace TanksServer.ServicePointDisplay;
internal sealed class TextDisplayBuffer : DisplayBufferView