feat(backend): add WebSocket wire message DTOs
This commit is contained in:
@@ -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
43
Backend/WireMessages.cs
Normal 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
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user