feat(backend): add WebSocket wire message DTOs

This commit is contained in:
meelstorm
2026-07-17 17:36:47 +00:00
committed by EugeneTes
parent b17a845ff7
commit 2c21dcfdf9
2 changed files with 47 additions and 0 deletions

View File

@@ -12,4 +12,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Backend.Tests" />
</ItemGroup>
</Project>

43
Backend/WireMessages.cs Normal file
View File

@@ -0,0 +1,43 @@
using System.Text.Json.Serialization;
namespace Backend;
// -------- Client → Server --------
/// <summary>Cursor position update from the browser.</summary>
public sealed class CursorMessage
{
[JsonPropertyName("type")] public string Type { get; set; } = "cursor";
[JsonPropertyName("x")] public float X { get; set; }
[JsonPropertyName("y")] public float Y { get; set; }
}
// -------- Server → Client --------
/// <summary>Sent once on WebSocket open. Tells the client the world dimensions.</summary>
public sealed class InitFrame
{
[JsonPropertyName("type")] public string Type { get; set; } = "init";
[JsonPropertyName("world")] public float[] World { get; set; } = new[] { 1f, 1f };
}
/// <summary>Sent every physics tick with the current ship pose and target.</summary>
public sealed class StateFrame
{
[JsonPropertyName("type")] public string Type { get; set; } = "state";
[JsonPropertyName("x")] public float X { get; set; }
[JsonPropertyName("y")] public float Y { get; set; }
[JsonPropertyName("angle")] public float Angle { get; set; }
[JsonPropertyName("engine")] public int Engine { get; set; }
[JsonPropertyName("target")] public float[] Target { get; set; } = new[] { 0.5f, 0.5f };
[JsonPropertyName("step")] public int Step { get; set; }
}
/// <summary>Source-gen JSON contracts.</summary>
[JsonSourceGenerationOptions(WriteIndented = false)]
[JsonSerializable(typeof(CursorMessage))]
[JsonSerializable(typeof(InitFrame))]
[JsonSerializable(typeof(StateFrame))]
internal partial class WireJsonContext : System.Text.Json.Serialization.JsonSerializerContext
{
}