diff --git a/Backend/Backend.csproj b/Backend/Backend.csproj index 7b58c45..39aad0b 100644 --- a/Backend/Backend.csproj +++ b/Backend/Backend.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/Backend/WireMessages.cs b/Backend/WireMessages.cs new file mode 100644 index 0000000..af0e482 --- /dev/null +++ b/Backend/WireMessages.cs @@ -0,0 +1,43 @@ +using System.Text.Json.Serialization; + +namespace Backend; + +// -------- Client → Server -------- + +/// Cursor position update from the browser. +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 -------- + +/// Sent once on WebSocket open. Tells the client the world dimensions. +public sealed class InitFrame +{ + [JsonPropertyName("type")] public string Type { get; set; } = "init"; + [JsonPropertyName("world")] public float[] World { get; set; } = new[] { 1f, 1f }; +} + +/// Sent every physics tick with the current ship pose and target. +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; } +} + +/// Source-gen JSON contracts. +[JsonSourceGenerationOptions(WriteIndented = false)] +[JsonSerializable(typeof(CursorMessage))] +[JsonSerializable(typeof(InitFrame))] +[JsonSerializable(typeof(StateFrame))] +internal partial class WireJsonContext : System.Text.Json.Serialization.JsonSerializerContext +{ +}