From 4138ba39e7244994242fb8f12bac1d0c12e75ad1 Mon Sep 17 00:00:00 2001 From: dingo Date: Fri, 27 Mar 2026 22:15:31 -0400 Subject: [PATCH] Add empty-tile support to board template builder - SnapshotTile: add IsAbsent flag (JSON: "absent") - BoardShapeGenerator.FromTemplate(): absent tiles are removed from the tiles dict instead of being filled with Void+Void, producing sparse board layouts with genuine missing cells - Builder: Empty swatch in paint palette marks cells as absent (striped crosshatch visual); absent cells are excluded from zone assignment; PureVoid paint clears absent state back to valid void; ApplyModal() also clears IsAbsent; SerializeTiles() includes absent entries so they round-trip correctly through save/load Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../Pages/Game/BoardTemplateBuilderPage.razor | 73 +++++++++++++++---- .../src/SOR.Game/Grid/BoardShapeGenerator.cs | 9 ++- .../SOR.Game/Grid/BoardTemplateSnapshot.cs | 11 +-- 3 files changed, 72 insertions(+), 21 deletions(-) diff --git a/Server/src/SOR.Admin/Components/Pages/Game/BoardTemplateBuilderPage.razor b/Server/src/SOR.Admin/Components/Pages/Game/BoardTemplateBuilderPage.razor index 8745170..2896feb 100644 --- a/Server/src/SOR.Admin/Components/Pages/Game/BoardTemplateBuilderPage.razor +++ b/Server/src/SOR.Admin/Components/Pages/Game/BoardTemplateBuilderPage.razor @@ -142,8 +142,26 @@ else @{ var activeColor = AffinityColor.GetValueOrDefault( ComputeDisplayAffinity(PaintMap[_paintAffinity].B1, PaintMap[_paintAffinity].B2), "#6c757d"); } -
- @_paintAffinity + @if (_paintEmpty) + { +
+ Empty + } + else + { +
+ @_paintAffinity + } + + +
+ Empty
@@ -151,12 +169,12 @@ else { var a = aff; var swatchColor = AffinityColor.GetValueOrDefault(a, "#6c757d"); - var isSelected = _paintAffinity == a; + var isSelected = !_paintEmpty && _paintAffinity == a;
+ @onclick="() => { _paintEmpty = false; _paintAffinity = a; }">
}
@@ -324,6 +342,7 @@ else private string _editMode = "Paint"; private Affinity _paintAffinity = Affinity.PureVoid; + private bool _paintEmpty = false; private int _zonePlayerCount = 2; private int _zoneSeat = 0; private bool _mouseDown; @@ -464,22 +483,38 @@ else private void PaintCell(int x, int y) { - if (!PaintMap.TryGetValue(_paintAffinity, out var bases)) return; var key = TileKey(x, y); + + if (_paintEmpty) + { + // Mark cell as absent — no tile exists at this position. + var tile = GetOrCreateTile(x, y); + tile.IsAbsent = true; + tile.Base1 = Affinity.Void; + tile.Base2 = Affinity.Void; + tile.AffinityOverrideable = false; + return; + } + + if (!PaintMap.TryGetValue(_paintAffinity, out var bases)) return; if (bases.B1 == Affinity.Void && bases.B2 == Affinity.Void) { - _tiles.Remove(key); // reverts to default void, preserves no state + _tiles.Remove(key); // reverts to a valid void tile (also clears absent if present) } else { var tile = GetOrCreateTile(x, y); - tile.Base1 = bases.B1; - tile.Base2 = bases.B2; + tile.IsAbsent = false; // painting over an absent cell restores it + tile.Base1 = bases.B1; + tile.Base2 = bases.B2; } } private void ZoneCell(int x, int y) { + // Don't assign zones to absent (no-tile) cells. + if (_tiles.TryGetValue(TileKey(x, y), out var td) && td.IsAbsent) return; + var key = TileKey(x, y); if (!_zones.ContainsKey(_zonePlayerCount)) _zones[_zonePlayerCount] = new Dictionary>(); @@ -510,6 +545,7 @@ else private void ApplyModal() { var tile = GetOrCreateTile(_modalX, _modalY); + tile.IsAbsent = false; // applying affinity always restores the cell tile.Base1 = (Affinity)_modalBase1Int; tile.Base2 = (Affinity)_modalBase2Int; tile.AffinityOverrideable = _modalOverrideable; @@ -523,6 +559,11 @@ else private string GetCellColor(int x, int y) { var key = TileKey(x, y); + _tiles.TryGetValue(key, out var tile); + + // Absent cells always render as empty space, regardless of edit mode. + if (tile is { IsAbsent: true }) + return "repeating-linear-gradient(45deg,#444 0px,#444 5px,#222 5px,#222 10px)"; if (_editMode == "ZoneEdit" && _zones.TryGetValue(_zonePlayerCount, out var seatMap)) { @@ -531,7 +572,7 @@ else return ZoneColors[s % ZoneColors.Length]; } - if (!_tiles.TryGetValue(key, out var tile)) + if (tile is null) return AffinityColor[Affinity.PureVoid]; var aff = ComputeDisplayAffinity(tile.Base1, tile.Base2); @@ -542,6 +583,7 @@ else { var key = TileKey(x, y); if (!_tiles.TryGetValue(key, out var tile)) return $"({x},{y}) Void"; + if (tile.IsAbsent) return $"({x},{y}) Empty (no tile)"; var aff = ComputeDisplayAffinity(tile.Base1, tile.Base2); var ao = tile.AffinityOverrideable ? " [overrideable]" : ""; return $"({x},{y}) {aff} ({tile.Base1}+{tile.Base2}){ao}"; @@ -571,7 +613,7 @@ else private string SerializeTiles() { var nonDefault = _tiles.Values - .Where(t => t.Base1 != Affinity.Void || t.Base2 != Affinity.Void || t.AffinityOverrideable) + .Where(t => t.IsAbsent || t.Base1 != Affinity.Void || t.Base2 != Affinity.Void || t.AffinityOverrideable) .ToList(); return JsonSerializer.Serialize(nonDefault); } @@ -735,10 +777,11 @@ else private sealed class TileDefinition { - [JsonPropertyName("x")] public int X { get; set; } - [JsonPropertyName("y")] public int Y { get; set; } - [JsonPropertyName("b1")] public Affinity Base1 { get; set; } = Affinity.Void; - [JsonPropertyName("b2")] public Affinity Base2 { get; set; } = Affinity.Void; - [JsonPropertyName("ao")] public bool AffinityOverrideable { get; set; } + [JsonPropertyName("x")] public int X { get; set; } + [JsonPropertyName("y")] public int Y { get; set; } + [JsonPropertyName("b1")] public Affinity Base1 { get; set; } = Affinity.Void; + [JsonPropertyName("b2")] public Affinity Base2 { get; set; } = Affinity.Void; + [JsonPropertyName("ao")] public bool AffinityOverrideable { get; set; } + [JsonPropertyName("absent")] public bool IsAbsent { get; set; } } } diff --git a/Server/src/SOR.Game/Grid/BoardShapeGenerator.cs b/Server/src/SOR.Game/Grid/BoardShapeGenerator.cs index e48c264..a1a8dc3 100644 --- a/Server/src/SOR.Game/Grid/BoardShapeGenerator.cs +++ b/Server/src/SOR.Game/Grid/BoardShapeGenerator.cs @@ -311,7 +311,14 @@ public static class BoardShapeGenerator if (td.X < 0 || td.X >= snapshot.Width || td.Y < 0 || td.Y >= snapshot.Height) continue; - var c = new Coord(td.X, td.Y); + var c = new Coord(td.X, td.Y); + + // Absent tiles are completely removed from the board (sparse layout). + if (td.IsAbsent) + { + tiles.Remove(c.ToKey()); + continue; + } var tile = new Tile { Coord = c }; if (td.AffinityOverrideable && pct > 0 && Random.Shared.Next(100) < pct) diff --git a/Server/src/SOR.Game/Grid/BoardTemplateSnapshot.cs b/Server/src/SOR.Game/Grid/BoardTemplateSnapshot.cs index 51bab03..df0ee7f 100644 --- a/Server/src/SOR.Game/Grid/BoardTemplateSnapshot.cs +++ b/Server/src/SOR.Game/Grid/BoardTemplateSnapshot.cs @@ -26,9 +26,10 @@ public sealed class BoardTemplateSnapshot public sealed class SnapshotTile { - [JsonPropertyName("x")] public int X { get; set; } - [JsonPropertyName("y")] public int Y { get; set; } - [JsonPropertyName("b1")] public Affinity Base1 { get; set; } - [JsonPropertyName("b2")] public Affinity Base2 { get; set; } - [JsonPropertyName("ao")] public bool AffinityOverrideable { get; set; } + [JsonPropertyName("x")] public int X { get; set; } + [JsonPropertyName("y")] public int Y { get; set; } + [JsonPropertyName("b1")] public Affinity Base1 { get; set; } + [JsonPropertyName("b2")] public Affinity Base2 { get; set; } + [JsonPropertyName("ao")] public bool AffinityOverrideable { get; set; } + [JsonPropertyName("absent")] public bool IsAbsent { get; set; } }