Implement board template builder — Phase 1 admin panel

- New BoardTemplate entity (TilesJson/StartingZonesJson as jsonb)
- BoardTemplateIdOverride on CustomLobby, BoardTemplateId on GameRuleSet
- EF migration AddBoardTemplates + applied to pg-forge-01
- Admin list page: /game/board-templates (toggle enable, edit, delete)
- Admin builder: paint canvas (22-affinity palette, drag support),
  zone edit mode (per-player-count seat assignment, erase), tile flags modal
- NavMenu: Board Templates link under Game submenu
- GameRules: BoardShape default changed to "Default"

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:
dingo
2026-03-27 20:49:32 -04:00
co-authored by Claude Happy
parent 8f0ed9d68f
commit 4924f61483
11 changed files with 1591 additions and 1 deletions
@@ -90,6 +90,11 @@
<i class="bi bi-people-fill me-2"></i>Custom Lobbies
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white-50 py-1" href="/game/board-templates">
<i class="bi bi-grid-3x3-gap me-2"></i>Board Templates
</NavLink>
</li>
</ul>
</li>
<li class="nav-item">
@@ -0,0 +1,725 @@
@page "/game/board-templates/new"
@page "/game/board-templates/{Id:guid}"
@using SOR.Database.Entities.Game
@using System.Text.Json.Serialization
@inject GameDbContext GameDb
@inject NavigationManager Nav
<PageTitle>@(_isNew ? "New Board Template" : _template.Name) — SOR Admin</PageTitle>
@if (_loading)
{
<div class="d-flex align-items-center gap-2 text-muted py-4">
<div class="spinner-border spinner-border-sm"></div>Loading…
</div>
}
else
{
<nav aria-label="breadcrumb" class="mb-2">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/game/board-templates">Board Templates</a></li>
<li class="breadcrumb-item active">@(_isNew ? "New" : _template.Name)</li>
</ol>
</nav>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">@(_isNew ? "New Board Template" : _template.Name)</h1>
<button class="btn btn-success" @onclick="SaveAsync" disabled="@_saving">
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
Save
</button>
</div>
@if (_saved)
{
<div class="alert alert-success alert-dismissible">
Saved successfully.
<button type="button" class="btn-close" @onclick="() => _saved = false"></button>
</div>
}
@if (_error is not null)
{
<div class="alert alert-danger alert-dismissible">
@_error
<button type="button" class="btn-close" @onclick="() => _error = null"></button>
</div>
}
<!-- Metadata + Board Size ──────────────────────────────────────────────── -->
<div class="row g-4 mb-4">
<div class="col-lg-6">
<div class="card h-100">
<div class="card-header">Template Details</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label fw-semibold">Name</label>
<input type="text" class="form-control" @bind="_template.Name"
placeholder="e.g. Standard 9×9" />
</div>
<div class="row g-3 mb-3">
<div class="col">
<label class="form-label fw-semibold">Min Players</label>
<input type="number" class="form-control" min="1" max="10"
@bind="_template.MinPlayers" />
</div>
<div class="col">
<label class="form-label fw-semibold">Max Players</label>
<input type="number" class="form-control" min="1" max="10"
@bind="_template.MaxPlayers" />
</div>
</div>
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" role="switch" id="isEnabled"
@bind="_template.IsEnabled" />
<label class="form-check-label" for="isEnabled">Enabled</label>
</div>
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" role="switch" id="isRanked"
@bind="_template.IsAvailableForRanked" />
<label class="form-check-label" for="isRanked">Available for Ranked</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="isCustom"
@bind="_template.IsAvailableForCustom" />
<label class="form-check-label" for="isCustom">Available for Custom Lobbies</label>
</div>
</div>
</div>
</div>
<div class="col-lg-3">
<div class="card h-100">
<div class="card-header">Board Size</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label fw-semibold">Width (columns)</label>
<input type="number" class="form-control" min="1" max="32"
@bind="_pendingWidth" />
</div>
<div class="mb-3">
<label class="form-label fw-semibold">Height (rows)</label>
<input type="number" class="form-control" min="1" max="32"
@bind="_pendingHeight" />
</div>
<button class="btn btn-outline-secondary btn-sm w-100" @onclick="ApplySize">
Apply Size
</button>
<div class="form-text mt-1">
Tiles inside the new bounds are preserved.
</div>
</div>
</div>
</div>
</div>
<!-- Toolbar + Canvas ───────────────────────────────────────────────────── -->
<div class="row g-3">
<!-- Toolbar -->
<div class="col-md-3 col-xl-2">
<div class="card">
<div class="card-header">Tools</div>
<div class="card-body p-2">
<!-- Mode toggle -->
<div class="btn-group w-100 mb-3" role="group">
<input type="radio" class="btn-check" name="editMode" id="modePaint"
checked="@(_editMode == "Paint")"
@onchange='() => _editMode = "Paint"' />
<label class="btn btn-outline-primary btn-sm" for="modePaint">
<i class="bi bi-brush me-1"></i>Paint
</label>
<input type="radio" class="btn-check" name="editMode" id="modeZone"
checked="@(_editMode == "ZoneEdit")"
@onchange='() => _editMode = "ZoneEdit"' />
<label class="btn btn-outline-success btn-sm" for="modeZone">
<i class="bi bi-grid-fill me-1"></i>Zones
</label>
</div>
@if (_editMode == "Paint")
{
<!-- Active paint -->
<div class="mb-2 d-flex align-items-center gap-2">
@{ 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>
</div>
<!-- Affinity palette -->
<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:3px;">
@foreach (var aff in PaletteAffinities)
{
var a = aff;
var swatchColor = AffinityColor.GetValueOrDefault(a, "#6c757d");
var isSelected = _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">
</div>
}
</div>
}
else
{
<!-- Zone edit controls -->
<div class="mb-2">
<label class="form-label fw-semibold small mb-1">Player Count</label>
<select class="form-select form-select-sm" @bind="_zonePlayerCount">
@for (int pc = Math.Max(2, _template.MinPlayers); pc <= Math.Max(_template.MinPlayers, _template.MaxPlayers); pc++)
{
var p = pc;
<option value="@p">@p players</option>
}
</select>
</div>
<div class="mb-2">
<label class="form-label fw-semibold small mb-1">Paint Seat</label>
<select class="form-select form-select-sm" @bind="_zoneSeat">
<option value="-1">✕ Erase</option>
@for (int s = 0; s < _zonePlayerCount; s++)
{
var seat = s;
<option value="@seat">Seat @seat</option>
}
</select>
</div>
@if (_zoneSeat >= 0)
{
<div class="d-flex align-items-center gap-2 mb-2">
<div style="width:20px;height:20px;border-radius:3px;background:@ZoneColors[_zoneSeat % ZoneColors.Length];border:1px solid rgba(0,0,0,0.25)"></div>
<span class="small fw-semibold">Seat @_zoneSeat</span>
</div>
}
else
{
<div class="d-flex align-items-center gap-2 mb-2">
<div style="width:20px;height:20px;border-radius:3px;background:#6c757d;border:1px solid rgba(0,0,0,0.25)"></div>
<span class="small text-muted">Erasing zones</span>
</div>
}
<hr class="my-2" />
<div class="small fw-semibold text-muted mb-1">Coverage:</div>
@for (int s = 0; s < _zonePlayerCount; s++)
{
var seat = s;
var cnt = GetSeatTileCount(_zonePlayerCount, seat);
<div class="d-flex align-items-center gap-2 mb-1">
<div style="width:12px;height:12px;border-radius:2px;background:@ZoneColors[seat % ZoneColors.Length]"></div>
<span class="small">Seat @seat: @cnt tile@(cnt == 1 ? "" : "s")</span>
</div>
}
}
</div>
</div>
</div>
<!-- Canvas -->
<div class="col-md-9 col-xl-10">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<span>Canvas <span class="text-muted small">@_template.Width × @_template.Height</span></span>
<span class="text-muted small d-none d-md-inline">
Click / drag to paint &nbsp;·&nbsp; Double-click for tile flags
</span>
</div>
<div class="card-body p-2" style="overflow:auto;max-height:65vh;">
<div style="display:grid;grid-template-columns:repeat(@_template.Width, 28px);gap:1px;width:fit-content;user-select:none;cursor:crosshair;"
@onmouseup="() => _mouseDown = false"
@onmouseleave="() => _mouseDown = false">
@for (int row = 0; row < _template.Height; row++)
{
@for (int col = 0; col < _template.Width; col++)
{
var r = row; var c = col;
<div style="width:28px;height:28px;background:@GetCellColor(c, r);border:1px solid rgba(0,0,0,0.12);"
title="@GetCellTooltip(c, r)"
@onmousedown="@(() => OnCellMouseDown(c, r))"
@onmouseenter="@(() => OnCellMouseEnter(c, r))"
@ondblclick="@(() => OpenTileModal(c, r))">
</div>
}
}
</div>
</div>
</div>
</div>
</div>
}
<!-- Tile Flags Modal ───────────────────────────────────────────────────────── -->
@if (_showModal)
{
<div class="modal show d-block" tabindex="-1"
style="background:rgba(0,0,0,0.5);" @onclick="CloseModal">
<div class="modal-dialog" @onclick:stopPropagation="true">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Tile (@_modalX, @_modalY)</h5>
<button type="button" class="btn-close" @onclick="CloseModal"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label fw-semibold">Base 1 (primary slot)</label>
<select class="form-select" @bind="_modalBase1Int">
@foreach (var a in Enum.GetValues<Affinity>())
{
<option value="@((int)a)">@a</option>
}
</select>
</div>
<div class="mb-3">
<label class="form-label fw-semibold">Base 2 (secondary slot)</label>
<select class="form-select" @bind="_modalBase2Int">
@foreach (var a in Enum.GetValues<Affinity>())
{
<option value="@((int)a)">@a</option>
}
</select>
</div>
<div class="mb-3 d-flex align-items-center gap-2">
@{ var previewAff = ComputeDisplayAffinity((Affinity)_modalBase1Int, (Affinity)_modalBase2Int);
var previewColor = AffinityColor.GetValueOrDefault(previewAff, "#6c757d"); }
<div style="width:24px;height:24px;border-radius:4px;background:@previewColor;border:1px solid rgba(0,0,0,0.2)"></div>
<span class="small text-muted">Preview: <strong>@previewAff</strong></span>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="modalAo"
@bind="_modalOverrideable" />
<label class="form-check-label" for="modalAo">Affinity Overrideable</label>
<div class="form-text">
When StartingRandomTilePct &gt; 0, only overrideable tiles may have their
affinity randomized at game start. Locked tiles stay fixed as designed.
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" @onclick="CloseModal">Cancel</button>
<button class="btn btn-primary" @onclick="ApplyModal">Apply</button>
</div>
</div>
</div>
</div>
}
@code {
[Parameter] public Guid Id { get; set; }
private bool _isNew => Id == default;
// ── Template + in-memory state ────────────────────────────────────────────
private BoardTemplate _template = new();
private int _pendingWidth = 8;
private int _pendingHeight = 8;
// Only non-default tiles stored; key = "x,y"
private Dictionary<string, TileDefinition> _tiles = new();
// zones[playerCount][seatIndex] = set of "x,y" coordinate strings
private Dictionary<int, Dictionary<int, HashSet<string>>> _zones = new();
// ── Edit state ────────────────────────────────────────────────────────────
private string _editMode = "Paint";
private Affinity _paintAffinity = Affinity.PureVoid;
private int _zonePlayerCount = 2;
private int _zoneSeat = 0;
private bool _mouseDown;
private (int x, int y) _lastPainted = (-1, -1);
// ── Modal state ───────────────────────────────────────────────────────────
private bool _showModal;
private int _modalX, _modalY;
private int _modalBase1Int;
private int _modalBase2Int;
private bool _modalOverrideable;
// ── UI state ──────────────────────────────────────────────────────────────
private bool _loading = true;
private bool _saving;
private bool _saved;
private string? _error;
// ── Lifecycle ─────────────────────────────────────────────────────────────
protected override async Task OnParametersSetAsync()
{
_loading = true;
_error = null;
_tiles.Clear();
_zones.Clear();
if (_isNew)
{
_template = new BoardTemplate { CreatedAt = DateTimeOffset.UtcNow, UpdatedAt = DateTimeOffset.UtcNow };
_pendingWidth = _template.Width;
_pendingHeight = _template.Height;
}
else
{
var t = await GameDb.BoardTemplates.FindAsync(Id);
if (t is null)
{
_error = "Template not found.";
_loading = false;
return;
}
_template = t;
_pendingWidth = t.Width;
_pendingHeight = t.Height;
DeserializeTiles(t.TilesJson);
DeserializeZones(t.StartingZonesJson);
}
_zonePlayerCount = Math.Clamp(
_zonePlayerCount,
Math.Max(2, _template.MinPlayers),
Math.Max(_template.MinPlayers, _template.MaxPlayers));
_loading = false;
}
// ── Save ──────────────────────────────────────────────────────────────────
private async Task SaveAsync()
{
_saving = true;
_error = null;
try
{
_template.TilesJson = SerializeTiles();
_template.StartingZonesJson = SerializeZones();
_template.UpdatedAt = DateTimeOffset.UtcNow;
if (_isNew)
{
_template.CreatedAt = DateTimeOffset.UtcNow;
GameDb.BoardTemplates.Add(_template);
}
await GameDb.SaveChangesAsync();
_saved = true;
if (_isNew)
Nav.NavigateTo($"/game/board-templates/{_template.Id}");
}
catch (Exception ex)
{
_error = ex.Message;
}
finally
{
_saving = false;
}
}
// ── Board sizing ──────────────────────────────────────────────────────────
private void ApplySize()
{
var w = Math.Clamp(_pendingWidth, 1, 32);
var h = Math.Clamp(_pendingHeight, 1, 32);
_template.Width = w;
_template.Height = h;
var toRemoveTiles = _tiles.Keys
.Where(k => { var p = k.Split(','); return int.Parse(p[0]) >= w || int.Parse(p[1]) >= h; })
.ToList();
foreach (var k in toRemoveTiles) _tiles.Remove(k);
foreach (var seatMap in _zones.Values)
foreach (var tileSet in seatMap.Values)
tileSet.RemoveWhere(k =>
{
var p = k.Split(',');
return int.Parse(p[0]) >= w || int.Parse(p[1]) >= h;
});
}
// ── Cell interactions ─────────────────────────────────────────────────────
private void OnCellMouseDown(int x, int y)
{
_mouseDown = true;
_lastPainted = (x, y);
HandleCell(x, y);
}
private void OnCellMouseEnter(int x, int y)
{
if (!_mouseDown) return;
if (_lastPainted == (x, y)) return;
_lastPainted = (x, y);
HandleCell(x, y);
}
private void HandleCell(int x, int y)
{
if (_editMode == "Paint") PaintCell(x, y);
else ZoneCell(x, y);
}
private void PaintCell(int x, int y)
{
if (!PaintMap.TryGetValue(_paintAffinity, out var bases)) return;
var key = TileKey(x, y);
if (bases.B1 == Affinity.Void && bases.B2 == Affinity.Void)
{
_tiles.Remove(key); // reverts to default void, preserves no state
}
else
{
var tile = GetOrCreateTile(x, y);
tile.Base1 = bases.B1;
tile.Base2 = bases.B2;
}
}
private void ZoneCell(int x, int y)
{
var key = TileKey(x, y);
if (!_zones.ContainsKey(_zonePlayerCount))
_zones[_zonePlayerCount] = new Dictionary<int, HashSet<string>>();
var seatMap = _zones[_zonePlayerCount];
// Remove cell from all seats first (ensures each cell belongs to at most one seat)
foreach (var kv in seatMap) kv.Value.Remove(key);
if (_zoneSeat >= 0)
{
if (!seatMap.ContainsKey(_zoneSeat)) seatMap[_zoneSeat] = new HashSet<string>();
seatMap[_zoneSeat].Add(key);
}
}
// ── Modal ─────────────────────────────────────────────────────────────────
private void OpenTileModal(int x, int y)
{
_modalX = x; _modalY = y;
var tile = GetOrCreateTile(x, y);
_modalBase1Int = (int)tile.Base1;
_modalBase2Int = (int)tile.Base2;
_modalOverrideable = tile.AffinityOverrideable;
_showModal = true;
}
private void ApplyModal()
{
var tile = GetOrCreateTile(_modalX, _modalY);
tile.Base1 = (Affinity)_modalBase1Int;
tile.Base2 = (Affinity)_modalBase2Int;
tile.AffinityOverrideable = _modalOverrideable;
_showModal = false;
}
private void CloseModal() => _showModal = false;
// ── Color helpers ─────────────────────────────────────────────────────────
private string GetCellColor(int x, int y)
{
var key = TileKey(x, y);
if (_editMode == "ZoneEdit" && _zones.TryGetValue(_zonePlayerCount, out var seatMap))
{
for (int s = 0; s < _zonePlayerCount; s++)
if (seatMap.TryGetValue(s, out var tileSet) && tileSet.Contains(key))
return ZoneColors[s % ZoneColors.Length];
}
if (!_tiles.TryGetValue(key, out var tile))
return AffinityColor[Affinity.PureVoid];
var aff = ComputeDisplayAffinity(tile.Base1, tile.Base2);
return AffinityColor.GetValueOrDefault(aff, "#6c757d");
}
private string GetCellTooltip(int x, int y)
{
var key = TileKey(x, y);
if (!_tiles.TryGetValue(key, out var tile)) return $"({x},{y}) Void";
var aff = ComputeDisplayAffinity(tile.Base1, tile.Base2);
var ao = tile.AffinityOverrideable ? " [overrideable]" : "";
return $"({x},{y}) {aff} ({tile.Base1}+{tile.Base2}){ao}";
}
private int GetSeatTileCount(int playerCount, int seat) =>
_zones.TryGetValue(playerCount, out var sm) && sm.TryGetValue(seat, out var ts)
? ts.Count : 0;
// ── Tile helpers ──────────────────────────────────────────────────────────
private static string TileKey(int x, int y) => $"{x},{y}";
private TileDefinition GetOrCreateTile(int x, int y)
{
var key = TileKey(x, y);
if (!_tiles.TryGetValue(key, out var tile))
{
tile = new TileDefinition { X = x, Y = y };
_tiles[key] = tile;
}
return tile;
}
// ── Serialization ─────────────────────────────────────────────────────────
private string SerializeTiles()
{
var nonDefault = _tiles.Values
.Where(t => t.Base1 != Affinity.Void || t.Base2 != Affinity.Void || t.AffinityOverrideable)
.ToList();
return JsonSerializer.Serialize(nonDefault);
}
private void DeserializeTiles(string json)
{
if (string.IsNullOrWhiteSpace(json) || json == "[]") return;
var tiles = JsonSerializer.Deserialize<List<TileDefinition>>(json);
if (tiles is null) return;
_tiles = tiles.ToDictionary(t => TileKey(t.X, t.Y));
}
private string SerializeZones()
{
var dict = _zones.ToDictionary(
o => o.Key,
o => o.Value.ToDictionary(i => i.Key, i => i.Value.ToList()));
return JsonSerializer.Serialize(dict);
}
private void DeserializeZones(string json)
{
if (string.IsNullOrWhiteSpace(json) || json == "{}") return;
var dict = JsonSerializer.Deserialize<Dictionary<int, Dictionary<int, List<string>>>>(json);
if (dict is null) return;
_zones = dict.ToDictionary(
o => o.Key,
o => o.Value.ToDictionary(i => i.Key, i => new HashSet<string>(i.Value)));
}
// ── Affinity display ──────────────────────────────────────────────────────
private static Affinity ComputeDisplayAffinity(Affinity b1, Affinity b2)
{
if (b1 == Affinity.Void && b2 == Affinity.Void) return Affinity.PureVoid;
if (b1 == Affinity.Void) return b2 switch
{
Affinity.Lake => Affinity.GatewayLake,
Affinity.Hill => Affinity.GatewayHill,
Affinity.Forest => Affinity.GatewayForest,
Affinity.Field => Affinity.GatewayField,
_ => Affinity.Void
};
if (b2 == Affinity.Void) return b1; // basic single-slot affinity
if (b1 == Affinity.Aether && b2 == Affinity.Aether) return Affinity.PerfectAether;
if (b1 == Affinity.Aether || b2 == Affinity.Aether) return Affinity.UnstableAether;
var lo = (Affinity)Math.Min((int)b1, (int)b2);
var hi = (Affinity)Math.Max((int)b1, (int)b2);
return (lo, hi) switch
{
(Affinity.Lake, Affinity.Lake) => Affinity.Ocean,
(Affinity.Lake, Affinity.Hill) => Affinity.Island,
(Affinity.Lake, Affinity.Forest) => Affinity.Swamp,
(Affinity.Lake, Affinity.Field) => Affinity.Marsh,
(Affinity.Hill, Affinity.Hill) => Affinity.Mountain,
(Affinity.Hill, Affinity.Forest) => Affinity.Fort,
(Affinity.Hill, Affinity.Field) => Affinity.Steppe,
(Affinity.Forest, Affinity.Forest) => Affinity.Jungle,
(Affinity.Forest, Affinity.Field) => Affinity.Grove,
(Affinity.Field, Affinity.Field) => Affinity.Plains,
_ => Affinity.Void
};
}
// ── Static data ───────────────────────────────────────────────────────────
private static readonly Dictionary<Affinity, string> AffinityColor = new()
{
[Affinity.Void] = "#495057",
[Affinity.Aether] = "#9b59b6",
[Affinity.Lake] = "#3498db",
[Affinity.Hill] = "#d4a843",
[Affinity.Forest] = "#27ae60",
[Affinity.Field] = "#f39c12",
[Affinity.Ocean] = "#1565c0",
[Affinity.Island] = "#5dade2",
[Affinity.Marsh] = "#85929e",
[Affinity.Swamp] = "#1a5276",
[Affinity.Mountain] = "#546e7a",
[Affinity.Steppe] = "#d5a229",
[Affinity.Fort] = "#6d4c41",
[Affinity.Plains] = "#f4d03f",
[Affinity.Grove] = "#82e0aa",
[Affinity.Jungle] = "#1b5e20",
[Affinity.UnstableAether] = "#8e44ad",
[Affinity.PerfectAether] = "#d7bde2",
[Affinity.PureVoid] = "#2c3038",
[Affinity.GatewayLake] = "#aed6f1",
[Affinity.GatewayHill] = "#fad7a0",
[Affinity.GatewayForest] = "#a9dfbf",
[Affinity.GatewayField] = "#fde8d8",
};
private static readonly string[] ZoneColors =
{
"#e74c3c", "#3498db", "#27ae60", "#f1c40f",
"#9b59b6", "#e67e22", "#1abc9c", "#e91e63",
"#00bcd4", "#795548"
};
// Palette display order: void / basics / double non-basics / mixed non-basics / aether specials / gateways
private static readonly IReadOnlyList<Affinity> PaletteAffinities = new[]
{
Affinity.PureVoid,
Affinity.Aether,
Affinity.Lake, Affinity.Hill, Affinity.Forest, Affinity.Field,
Affinity.Ocean, Affinity.Mountain, Affinity.Jungle, Affinity.Plains,
Affinity.Island, Affinity.Swamp, Affinity.Marsh,
Affinity.Fort, Affinity.Steppe, Affinity.Grove,
Affinity.UnstableAether, Affinity.PerfectAether,
Affinity.GatewayLake, Affinity.GatewayHill, Affinity.GatewayForest, Affinity.GatewayField,
};
private static readonly Dictionary<Affinity, (Affinity B1, Affinity B2)> PaintMap = new()
{
[Affinity.PureVoid] = (Affinity.Void, Affinity.Void),
[Affinity.Aether] = (Affinity.Aether, Affinity.Void),
[Affinity.Lake] = (Affinity.Lake, Affinity.Void),
[Affinity.Hill] = (Affinity.Hill, Affinity.Void),
[Affinity.Forest] = (Affinity.Forest, Affinity.Void),
[Affinity.Field] = (Affinity.Field, Affinity.Void),
[Affinity.Ocean] = (Affinity.Lake, Affinity.Lake),
[Affinity.Island] = (Affinity.Lake, Affinity.Hill),
[Affinity.Marsh] = (Affinity.Lake, Affinity.Field),
[Affinity.Swamp] = (Affinity.Lake, Affinity.Forest),
[Affinity.Mountain] = (Affinity.Hill, Affinity.Hill),
[Affinity.Steppe] = (Affinity.Hill, Affinity.Field),
[Affinity.Fort] = (Affinity.Hill, Affinity.Forest),
[Affinity.Plains] = (Affinity.Field, Affinity.Field),
[Affinity.Grove] = (Affinity.Field, Affinity.Forest),
[Affinity.Jungle] = (Affinity.Forest, Affinity.Forest),
[Affinity.UnstableAether] = (Affinity.Aether, Affinity.Lake),
[Affinity.PerfectAether] = (Affinity.Aether, Affinity.Aether),
[Affinity.GatewayLake] = (Affinity.Void, Affinity.Lake),
[Affinity.GatewayHill] = (Affinity.Void, Affinity.Hill),
[Affinity.GatewayForest] = (Affinity.Void, Affinity.Forest),
[Affinity.GatewayField] = (Affinity.Void, Affinity.Field),
};
// ── TileDefinition ────────────────────────────────────────────────────────
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; }
}
}
@@ -0,0 +1,152 @@
@page "/game/board-templates"
@using SOR.Database.Entities.Game
@inject GameDbContext GameDb
@inject NavigationManager Nav
@inject IJSRuntime JS
<PageTitle>Board Templates — SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">Board Templates</h1>
<div class="d-flex gap-2">
<button class="btn btn-outline-secondary btn-sm" @onclick="LoadAsync">
<i class="bi bi-arrow-clockwise me-1"></i>Refresh
</button>
<button class="btn btn-primary" @onclick='() => Nav.NavigateTo("/game/board-templates/new")'>
<i class="bi bi-plus-lg me-1"></i>New Template
</button>
</div>
</div>
@if (_error is not null)
{
<div class="alert alert-danger alert-dismissible">
@_error
<button type="button" class="btn-close" @onclick="() => _error = null"></button>
</div>
}
@if (_loading)
{
<div class="d-flex align-items-center gap-2 text-muted">
<div class="spinner-border spinner-border-sm"></div>Loading…
</div>
}
else
{
<div class="table-responsive">
<table class="table table-sm table-hover align-middle">
<thead class="table-dark">
<tr>
<th>Name</th>
<th>Size</th>
<th>Players</th>
<th>Ranked</th>
<th>Custom</th>
<th>Enabled</th>
<th>Created</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var tmpl in _templates)
{
<tr>
<td><strong>@tmpl.Name</strong></td>
<td class="text-muted small">@tmpl.Width × @tmpl.Height</td>
<td class="text-muted small">@tmpl.MinPlayers–@tmpl.MaxPlayers</td>
<td>
@if (tmpl.IsAvailableForRanked)
{ <span class="badge bg-warning text-dark">Ranked</span> }
else
{ <span class="text-muted small">—</span> }
</td>
<td>
@if (tmpl.IsAvailableForCustom)
{ <span class="badge bg-info text-dark">Custom</span> }
else
{ <span class="text-muted small">—</span> }
</td>
<td>
<div class="form-check form-switch mb-0">
<input class="form-check-input" type="checkbox" role="switch"
checked="@tmpl.IsEnabled"
@onchange="() => ToggleEnabledAsync(tmpl)" />
</div>
</td>
<td class="text-muted small">@tmpl.CreatedAt.ToLocalTime().ToString("MM/dd/yy")</td>
<td class="d-flex gap-1">
<button class="btn btn-outline-primary btn-sm"
@onclick='() => Nav.NavigateTo($"/game/board-templates/{tmpl.Id}")'>
<i class="bi bi-pencil"></i>
</button>
<button class="btn btn-outline-danger btn-sm"
@onclick="() => DeleteAsync(tmpl.Id)">
<i class="bi bi-trash"></i>
</button>
</td>
</tr>
}
@if (!_templates.Any())
{
<tr>
<td colspan="8" class="text-center text-muted py-4">
No board templates yet. <a href="/game/board-templates/new">Create one.</a>
</td>
</tr>
}
</tbody>
</table>
</div>
}
@code {
private List<BoardTemplate> _templates = new();
private bool _loading = true;
private string? _error;
protected override async Task OnInitializedAsync() => await LoadAsync();
private async Task LoadAsync()
{
_loading = true;
_error = null;
try
{
_templates = await GameDb.BoardTemplates
.AsNoTracking()
.OrderByDescending(t => t.CreatedAt)
.ToListAsync();
}
catch (Exception ex)
{
_error = ex.Message;
}
finally
{
_loading = false;
}
}
private async Task ToggleEnabledAsync(BoardTemplate tmpl)
{
var entity = await GameDb.BoardTemplates.FindAsync(tmpl.Id);
if (entity is null) return;
entity.IsEnabled = !entity.IsEnabled;
entity.UpdatedAt = DateTimeOffset.UtcNow;
await GameDb.SaveChangesAsync();
tmpl.IsEnabled = entity.IsEnabled;
}
private async Task DeleteAsync(Guid id)
{
var confirmed = await JS.InvokeAsync<bool>("confirm", "Delete this board template? This cannot be undone.");
if (!confirmed) return;
var entity = await GameDb.BoardTemplates.FindAsync(id);
if (entity is null) return;
GameDb.BoardTemplates.Remove(entity);
await GameDb.SaveChangesAsync();
await LoadAsync();
}
}
@@ -29,6 +29,7 @@ public sealed class GameDbContext : DbContext
public DbSet<GameRuleSet> GameRuleSets => Set<GameRuleSet>();
public DbSet<CustomLobby> CustomLobbies => Set<CustomLobby>();
public DbSet<LobbyPreset> LobbyPresets => Set<LobbyPreset>();
public DbSet<BoardTemplate> BoardTemplates => Set<BoardTemplate>();
protected override void OnModelCreating(ModelBuilder builder)
{
@@ -100,5 +101,14 @@ public sealed class GameDbContext : DbContext
e.HasKey(p => p.Id);
e.HasIndex(p => p.OwnerAccountId);
});
builder.Entity<BoardTemplate>(e =>
{
e.ToTable("board_templates");
e.HasKey(b => b.Id);
e.Property(b => b.TilesJson).HasColumnType("jsonb");
e.Property(b => b.StartingZonesJson).HasColumnType("jsonb");
e.HasIndex(b => b.IsEnabled);
});
}
}
@@ -0,0 +1,37 @@
namespace SOR.Database.Entities.Game;
/// <summary>
/// An admin-defined board layout assignable to custom lobbies or ranked matches.
///
/// TilesJson: JSON array of tile objects: {"x":0,"y":0,"b1":2,"b2":0,"ao":false}
/// b1/b2 are integer values of the Affinity enum; ao = AffinityOverrideable.
/// Tiles absent from the array default to Void+Void, ao=false.
///
/// StartingZonesJson: JSON object keyed by player-count string, value is a map of
/// seat-index string → array of "x,y" coordinate strings.
/// Example: {"2":{"0":["0,0","1,0"],"1":["8,8","7,8"]},"3":{...}}
///
/// AffinityOverrideable: when StartingRandomTilePct > 0 for a game rule, only tiles
/// with this flag may have their affinity randomized; locked tiles stay fixed as designed.
/// </summary>
public sealed class BoardTemplate
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Name { get; set; } = string.Empty;
public int Width { get; set; } = 8;
public int Height { get; set; } = 8;
public string TilesJson { get; set; } = "[]";
public string StartingZonesJson { get; set; } = "{}";
public bool IsEnabled { get; set; } = true;
public bool IsAvailableForRanked { get; set; } = false;
public bool IsAvailableForCustom { get; set; } = true;
public int MinPlayers { get; set; } = 2;
public int MaxPlayers { get; set; } = 2;
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
}
@@ -86,6 +86,9 @@ public sealed class CustomLobby
/// </summary>
public string? BoardShapeOverride { get; set; }
/// <summary>When set, use this BoardTemplate instead of generating a board algorithmically.</summary>
public Guid? BoardTemplateIdOverride { get; set; }
/// <summary>Percentage (0–100) of tiles that start with a random basic affinity. 0 = all void.</summary>
public int? StartingRandomTilePctOverride { get; set; }
@@ -94,6 +94,11 @@ public sealed class GameRuleSet
/// </summary>
public int RankDiffOpMultiplierPct { get; set; } = 0;
// ── Board Template ────────────────────────────────────────────────────────
/// <summary>When set, use this BoardTemplate for games created under this ruleset.</summary>
public Guid? BoardTemplateId { get; set; }
// ── Timestamps ───────────────────────────────────────────────────────────
public DateTimeOffset CreatedAt { get; set; }
@@ -0,0 +1,518 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using SOR.Database.Contexts;
#nullable disable
namespace SOR.Database.Migrations.Game
{
[DbContext(typeof(GameDbContext))]
[Migration("20260328004823_AddBoardTemplates")]
partial class AddBoardTemplates
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("game")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SOR.Database.Entities.Game.BoardTemplate", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Height")
.HasColumnType("integer");
b.Property<bool>("IsAvailableForCustom")
.HasColumnType("boolean");
b.Property<bool>("IsAvailableForRanked")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<int>("MinPlayers")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StartingZonesJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("TilesJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Width")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("IsEnabled");
b.ToTable("board_templates", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.CustomLobby", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AdditionalPlayersJson")
.HasColumnType("text")
.HasColumnName("additional_players_json");
b.Property<int?>("BoardHeightOverride")
.HasColumnType("integer");
b.Property<string>("BoardShapeOverride")
.HasColumnType("text");
b.Property<Guid?>("BoardTemplateIdOverride")
.HasColumnType("uuid");
b.Property<int?>("BoardWidthOverride")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<bool?>("DiscardOnMaxHandOverride")
.HasColumnType("boolean");
b.Property<int?>("DrawPerTurnOverride")
.HasColumnType("integer");
b.Property<bool?>("FirstPlayerSkipsDrawOverride")
.HasColumnType("boolean");
b.Property<string>("GameMode")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("FFA")
.HasColumnName("game_mode");
b.Property<Guid?>("GameSessionId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestAccountId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestDeckId")
.HasColumnType("uuid");
b.Property<string>("GuestFirstTurnPref")
.HasColumnType("text");
b.Property<bool>("GuestReady")
.HasColumnType("boolean");
b.Property<int?>("HandSizeCapOverride")
.HasColumnType("integer");
b.Property<Guid>("HostAccountId")
.HasColumnType("uuid");
b.Property<Guid>("HostDeckId")
.HasColumnType("uuid");
b.Property<string>("HostFirstTurnPref")
.HasColumnType("text");
b.Property<bool>("HostReady")
.HasColumnType("boolean");
b.Property<int?>("MaxArchTier1Override")
.HasColumnType("integer");
b.Property<int?>("MaxDeckSizeOverride")
.HasColumnType("integer");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<int?>("MinDeckSizeOverride")
.HasColumnType("integer");
b.Property<int?>("MpBuffOverride")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("OpeningHandSizeOverride")
.HasColumnType("integer");
b.Property<string>("Password")
.HasColumnType("text");
b.Property<int?>("SpAccumulationPerTurnOverride")
.HasColumnType("integer");
b.Property<int?>("SpCapOverride")
.HasColumnType("integer");
b.Property<bool?>("SpHasCapOverride")
.HasColumnType("boolean");
b.Property<int?>("StartingRandomTilePctOverride")
.HasColumnType("integer");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<int>("TeamCount")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(1)
.HasColumnName("team_count");
b.Property<int?>("TimeLimitMinutesOverride")
.HasColumnType("integer");
b.Property<int?>("TurnLimitOverride")
.HasColumnType("integer");
b.Property<int?>("TurnTimerSecondsOverride")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("HostAccountId");
b.HasIndex("Status", "CreatedAt");
b.ToTable("custom_lobbies", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ActionType")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ActorAccountId")
.HasColumnType("uuid");
b.Property<Guid>("GameSessionId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("OccurredAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("PayloadJson")
.HasColumnType("jsonb")
.HasColumnName("payload");
b.Property<string>("ResultJson")
.HasColumnType("jsonb")
.HasColumnName("result");
b.Property<int>("SequenceNumber")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ActorAccountId");
b.HasIndex("GameSessionId", "SequenceNumber")
.IsUnique();
b.ToTable("action_logs", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameRuleSet", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("BoardHeight")
.HasColumnType("integer");
b.Property<Guid?>("BoardTemplateId")
.HasColumnType("uuid");
b.Property<int>("BoardWidth")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<bool>("DiscardOnMaxHand")
.HasColumnType("boolean");
b.Property<int>("DrawPerTurn")
.HasColumnType("integer");
b.Property<bool>("FirstPlayerSkipsDraw")
.HasColumnType("boolean");
b.Property<int>("HandSizeCap")
.HasColumnType("integer");
b.Property<bool>("IsCustomDefault")
.HasColumnType("boolean");
b.Property<bool>("IsRankedDefault")
.HasColumnType("boolean");
b.Property<int>("LoserOpReward")
.HasColumnType("integer");
b.Property<int>("MaxArchTier1")
.HasColumnType("integer");
b.Property<int>("MaxDeckSize")
.HasColumnType("integer");
b.Property<int>("MinDeckSize")
.HasColumnType("integer");
b.Property<int>("MpBuff")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OpeningHandSize")
.HasColumnType("integer");
b.Property<int>("RankDiffOpMultiplierPct")
.HasColumnType("integer");
b.Property<int>("SpAccumulationPerTurn")
.HasColumnType("integer");
b.Property<int>("SpCap")
.HasColumnType("integer");
b.Property<bool>("SpHasCap")
.HasColumnType("boolean");
b.Property<int>("StartingRandomTilePct")
.HasColumnType("integer");
b.Property<int>("TimeLimitMinutes")
.HasColumnType("integer");
b.Property<int>("TurnLimit")
.HasColumnType("integer");
b.Property<int>("TurnTimerSeconds")
.HasColumnType("integer");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("WinnerOpReward")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("IsCustomDefault");
b.HasIndex("IsRankedDefault");
b.ToTable("game_rule_sets", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AdditionalPlayersJson")
.HasColumnType("text")
.HasColumnName("additional_players_json");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("EndedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("GameMode")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("FFA")
.HasColumnName("game_mode");
b.Property<DateTimeOffset?>("LastActionAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("PlayerCount")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(2)
.HasColumnName("player_count");
b.Property<Guid>("PlayerOneAccountId")
.HasColumnType("uuid");
b.Property<Guid>("PlayerOneDeckId")
.HasColumnType("uuid");
b.Property<bool>("PlayerOneReady")
.HasColumnType("boolean");
b.Property<Guid>("PlayerTwoAccountId")
.HasColumnType("uuid");
b.Property<Guid>("PlayerTwoDeckId")
.HasColumnType("uuid");
b.Property<bool>("PlayerTwoReady")
.HasColumnType("boolean");
b.Property<string>("RuleSnapshotJson")
.HasColumnType("jsonb")
.HasColumnName("rule_snapshot");
b.Property<DateTimeOffset?>("StartedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("StateJson")
.HasColumnType("jsonb")
.HasColumnName("state");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<string>("WinCondition")
.HasColumnType("text");
b.Property<Guid?>("WinnerAccountId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("PlayerOneAccountId");
b.HasIndex("PlayerTwoAccountId");
b.HasIndex("Status", "CreatedAt");
b.ToTable("game_sessions", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.LobbyPreset", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("OwnerAccountId")
.HasColumnType("uuid");
b.Property<string>("RulesJson")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("OwnerAccountId");
b.ToTable("lobby_presets", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.MatchmakingEntry", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("AccountId")
.HasColumnType("uuid");
b.Property<Guid>("DeckId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("JoinedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("MatchedGameSessionId")
.HasColumnType("uuid");
b.Property<int>("RankScore")
.HasColumnType("integer");
b.Property<DateTimeOffset?>("ResolvedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AccountId", "Status");
b.HasIndex("Status", "RankScore");
b.ToTable("matchmaking_entries", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
{
b.HasOne("SOR.Database.Entities.Game.GameSession", "Session")
.WithMany("ActionLog")
.HasForeignKey("GameSessionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Session");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
{
b.Navigation("ActionLog");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,77 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SOR.Database.Migrations.Game
{
/// <inheritdoc />
public partial class AddBoardTemplates : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "BoardTemplateId",
schema: "game",
table: "game_rule_sets",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "BoardTemplateIdOverride",
schema: "game",
table: "custom_lobbies",
type: "uuid",
nullable: true);
migrationBuilder.CreateTable(
name: "board_templates",
schema: "game",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Width = table.Column<int>(type: "integer", nullable: false),
Height = table.Column<int>(type: "integer", nullable: false),
TilesJson = table.Column<string>(type: "jsonb", nullable: false),
StartingZonesJson = table.Column<string>(type: "jsonb", nullable: false),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
IsAvailableForRanked = table.Column<bool>(type: "boolean", nullable: false),
IsAvailableForCustom = table.Column<bool>(type: "boolean", nullable: false),
MinPlayers = table.Column<int>(type: "integer", nullable: false),
MaxPlayers = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_board_templates", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_board_templates_IsEnabled",
schema: "game",
table: "board_templates",
column: "IsEnabled");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "board_templates",
schema: "game");
migrationBuilder.DropColumn(
name: "BoardTemplateId",
schema: "game",
table: "game_rule_sets");
migrationBuilder.DropColumn(
name: "BoardTemplateIdOverride",
schema: "game",
table: "custom_lobbies");
}
}
}
@@ -23,6 +23,58 @@ namespace SOR.Database.Migrations.Game
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SOR.Database.Entities.Game.BoardTemplate", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Height")
.HasColumnType("integer");
b.Property<bool>("IsAvailableForCustom")
.HasColumnType("boolean");
b.Property<bool>("IsAvailableForRanked")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<int>("MinPlayers")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StartingZonesJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("TilesJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Width")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("IsEnabled");
b.ToTable("board_templates", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.CustomLobby", b =>
{
b.Property<Guid>("Id")
@@ -39,6 +91,9 @@ namespace SOR.Database.Migrations.Game
b.Property<string>("BoardShapeOverride")
.HasColumnType("text");
b.Property<Guid?>("BoardTemplateIdOverride")
.HasColumnType("uuid");
b.Property<int?>("BoardWidthOverride")
.HasColumnType("integer");
@@ -205,6 +260,9 @@ namespace SOR.Database.Migrations.Game
b.Property<int>("BoardHeight")
.HasColumnType("integer");
b.Property<Guid?>("BoardTemplateId")
.HasColumnType("uuid");
b.Property<int>("BoardWidth")
.HasColumnType("integer");
+1 -1
View File
@@ -57,7 +57,7 @@ public sealed record GameRules
public int StartingRandomTilePct { get; init; } = 0;
/// <summary>Board shape identifier passed to BoardShapeGenerator. "Rectangle" | "Cross".</summary>
public string BoardShape { get; init; } = "Rectangle";
public string BoardShape { get; init; } = "Default";
/// <summary>Number of players in this game. 2 = standard 1v1.</summary>
public int PlayerCount { get; init; } = 2;