Files
2026-07-17 18:23:16 +00:00

44 lines
1.6 KiB
C#

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
{
}