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 <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -142,8 +142,26 @@ else
|
||||
@{ var activeColor = AffinityColor.GetValueOrDefault(
|
||||
ComputeDisplayAffinity(PaintMap[_paintAffinity].B1, PaintMap[_paintAffinity].B2),
|
||||
"#6c757d"); }
|
||||
<div style="width:20px;height:20px;border-radius:3px;background:@activeColor;border:1px solid rgba(0,0,0,0.25)"></div>
|
||||
<span class="small fw-semibold">@_paintAffinity</span>
|
||||
@if (_paintEmpty)
|
||||
{
|
||||
<div style="width:20px;height:20px;border-radius:3px;background:repeating-linear-gradient(45deg,#444 0px,#444 5px,#222 5px,#222 10px);border:1px solid rgba(0,0,0,0.25)"></div>
|
||||
<span class="small fw-semibold">Empty</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div style="width:20px;height:20px;border-radius:3px;background:@activeColor;border:1px solid rgba(0,0,0,0.25)"></div>
|
||||
<span class="small fw-semibold">@_paintAffinity</span>
|
||||
}
|
||||
</div>
|
||||
<!-- Empty swatch (removes tile from board entirely) -->
|
||||
<div style="height:24px;background:repeating-linear-gradient(45deg,#444 0px,#444 5px,#222 5px,#222 10px);
|
||||
cursor:pointer;border-radius:3px;margin-bottom:4px;
|
||||
border:@(_paintEmpty ? "2px solid #fff" : "1px solid rgba(0,0,0,0.15)");
|
||||
box-shadow:@(_paintEmpty ? "0 0 0 1px #333" : "none");
|
||||
display:flex;align-items:center;justify-content:center;"
|
||||
title="Empty — removes this cell from the board"
|
||||
@onclick="() => _paintEmpty = true">
|
||||
<span style="font-size:9px;color:#aaa;user-select:none;pointer-events:none;">Empty</span>
|
||||
</div>
|
||||
<!-- Affinity palette -->
|
||||
<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:3px;">
|
||||
@@ -151,12 +169,12 @@ else
|
||||
{
|
||||
var a = aff;
|
||||
var swatchColor = AffinityColor.GetValueOrDefault(a, "#6c757d");
|
||||
var isSelected = _paintAffinity == a;
|
||||
var isSelected = !_paintEmpty && _paintAffinity == a;
|
||||
<div style="height:24px;background:@swatchColor;cursor:pointer;border-radius:3px;
|
||||
border:@(isSelected ? "2px solid #fff" : "1px solid rgba(0,0,0,0.15)");
|
||||
box-shadow:@(isSelected ? "0 0 0 1px #333" : "none");"
|
||||
title="@a"
|
||||
@onclick="() => _paintAffinity = a">
|
||||
@onclick="() => { _paintEmpty = false; _paintAffinity = a; }">
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -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<int, HashSet<string>>();
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user