Separate polygon sides from board radius for hex templates; fix template IsInBounds
- HexSides now stores radius+1 (for hex coordinate math); HexPolygonSides stores the corner count (3–10) - Board.IsTemplateBased: template boards use tile existence for IsInBounds/GetNeighbors instead of the hexagonal formula, so N-gon and other custom shapes work correctly - HexGrid.AllNeighbors: unfiltered 6-neighbor generator for template board use - ApplyHexConfig: generates a regular N-gon on the hex canvas — tiles outside the polygon are marked absent; N corner zones auto-generated for each player count 2..N - Admin builder UI: separate "Polygon Sides" (3–10 corners) and "Radius (tiles)" inputs - BoardTemplate entity and migration: HexPolygonSides column added to board_templates - BoardTemplateDto exposes HexPolygonSides to client 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:
Submodule
+1
Submodule .claude/worktrees/agent-ac72c5f4 added at c756b9cffa
@@ -102,13 +102,19 @@ else
|
||||
@if (_template.GridType == "Hexagon")
|
||||
{
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Hex Sides (N)</label>
|
||||
<label class="form-label fw-semibold">Polygon Sides</label>
|
||||
<input type="number" class="form-control" min="3" max="10"
|
||||
@bind="_pendingHexSides" />
|
||||
<div class="form-text">Diameter = 2N−1. Tiles: 3N²−3N+1.</div>
|
||||
@bind="_pendingHexPolySides" />
|
||||
<div class="form-text">Number of corners / player slots. 3 = triangle, 6 = hexagon, 10 = decagon.</div>
|
||||
</div>
|
||||
<button class="btn btn-outline-secondary btn-sm w-100" @onclick="ApplyHexSides">
|
||||
Apply Hex Sides
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold">Radius (tiles)</label>
|
||||
<input type="number" class="form-control" min="2" max="15"
|
||||
@bind="_pendingHexRadius" />
|
||||
<div class="form-text">Board radius from center to corner. Diameter = 2R+1.</div>
|
||||
</div>
|
||||
<button class="btn btn-outline-secondary btn-sm w-100" @onclick="ApplyHexConfig">
|
||||
Apply
|
||||
</button>
|
||||
}
|
||||
else
|
||||
@@ -260,8 +266,9 @@ else
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
@if (_template.GridType == "Hexagon")
|
||||
{
|
||||
int _hn = _template.HexSides > 0 ? _template.HexSides : _pendingHexSides;
|
||||
<span>Canvas <span class="text-muted small">N=@_hn hex (@(2*_hn-1)×@(2*_hn-1))</span></span>
|
||||
int _hpoly = _template.HexPolygonSides > 0 ? _template.HexPolygonSides : _pendingHexPolySides;
|
||||
int _hradius = _template.HexSides > 1 ? _template.HexSides - 1 : _pendingHexRadius;
|
||||
<span>Canvas <span class="text-muted small">@_hpoly-gon, R=@_hradius (@(2*_hradius+1)×@(2*_hradius+1))</span></span>
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -276,7 +283,8 @@ else
|
||||
{
|
||||
const double HexR = 16.0;
|
||||
const double HexPad = 12.0;
|
||||
int hexN = _template.HexSides > 0 ? _template.HexSides : Math.Max(3, _pendingHexSides);
|
||||
// hexN = radius + 1 (for HexGrid coordinate math)
|
||||
int hexN = _template.HexSides > 0 ? _template.HexSides : (_pendingHexRadius + 1);
|
||||
int hexDim = 2 * hexN - 1;
|
||||
double svgW = HexR * Math.Sqrt(3) * (hexDim - 1) + 2 * HexR + 2 * HexPad;
|
||||
double svgH = HexR * 1.5 * (hexDim - 1) + 2 * HexR + 2 * HexPad;
|
||||
@@ -393,9 +401,10 @@ else
|
||||
// ── Template + in-memory state ────────────────────────────────────────────
|
||||
|
||||
private BoardTemplate _template = new();
|
||||
private int _pendingWidth = 8;
|
||||
private int _pendingHeight = 8;
|
||||
private int _pendingHexSides = 5;
|
||||
private int _pendingWidth = 8;
|
||||
private int _pendingHeight = 8;
|
||||
private int _pendingHexPolySides = 6; // polygon corner count (3–10)
|
||||
private int _pendingHexRadius = 5; // board radius in tiles (2–15)
|
||||
|
||||
// Only non-default tiles stored; key = "x,y"
|
||||
private Dictionary<string, TileDefinition> _tiles = new();
|
||||
@@ -439,10 +448,11 @@ else
|
||||
|
||||
if (_isNew)
|
||||
{
|
||||
_template = new BoardTemplate { CreatedAt = DateTimeOffset.UtcNow, UpdatedAt = DateTimeOffset.UtcNow };
|
||||
_pendingWidth = _template.Width;
|
||||
_pendingHeight = _template.Height;
|
||||
_pendingHexSides = 5;
|
||||
_template = new BoardTemplate { CreatedAt = DateTimeOffset.UtcNow, UpdatedAt = DateTimeOffset.UtcNow };
|
||||
_pendingWidth = _template.Width;
|
||||
_pendingHeight = _template.Height;
|
||||
_pendingHexPolySides = 6;
|
||||
_pendingHexRadius = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -453,10 +463,11 @@ else
|
||||
_loading = false;
|
||||
return;
|
||||
}
|
||||
_template = t;
|
||||
_pendingWidth = t.Width;
|
||||
_pendingHeight = t.Height;
|
||||
_pendingHexSides = t.HexSides > 0 ? t.HexSides : 5;
|
||||
_template = t;
|
||||
_pendingWidth = t.Width;
|
||||
_pendingHeight = t.Height;
|
||||
_pendingHexPolySides = t.HexPolygonSides > 0 ? t.HexPolygonSides : 6;
|
||||
_pendingHexRadius = t.HexSides > 1 ? t.HexSides - 1 : 5;
|
||||
DeserializeTiles(t.TilesJson);
|
||||
DeserializeZones(t.StartingZonesJson);
|
||||
}
|
||||
@@ -525,27 +536,87 @@ else
|
||||
});
|
||||
}
|
||||
|
||||
private void ApplyHexSides()
|
||||
/// <summary>
|
||||
/// Generate a regular N-gon of hex tiles and N corner starting zones.
|
||||
/// HexSides is stored as radius+1 (for HexGrid coordinate math).
|
||||
/// HexPolygonSides is stored as N (the corner count / polygon shape).
|
||||
/// </summary>
|
||||
private void ApplyHexConfig()
|
||||
{
|
||||
var n = Math.Clamp(_pendingHexSides, 3, 10);
|
||||
_pendingHexSides = n;
|
||||
_template.HexSides = n;
|
||||
int dim = 2 * n - 1;
|
||||
_template.Width = dim;
|
||||
_template.Height = dim;
|
||||
int N = Math.Clamp(_pendingHexPolySides, 3, 10);
|
||||
int R = Math.Clamp(_pendingHexRadius, 2, 15);
|
||||
int sides = R + 1; // HexGrid "sides" parameter = radius + 1
|
||||
int dim = 2 * R + 1;
|
||||
|
||||
var toRemoveTiles = _tiles.Keys
|
||||
.Where(k => { var p = k.Split(','); return !IsHexInBounds(int.Parse(p[0]), int.Parse(p[1]), n); })
|
||||
.ToList();
|
||||
foreach (var k in toRemoveTiles) _tiles.Remove(k);
|
||||
_pendingHexPolySides = N;
|
||||
_pendingHexRadius = R;
|
||||
_template.HexSides = sides;
|
||||
_template.HexPolygonSides = N;
|
||||
_template.Width = dim;
|
||||
_template.Height = dim;
|
||||
|
||||
foreach (var seatMap in _zones.Values)
|
||||
foreach (var tileSet in seatMap.Values)
|
||||
tileSet.RemoveWhere(k =>
|
||||
_tiles.Clear();
|
||||
_zones.Clear();
|
||||
|
||||
// Mark every tile that is inside the hexagonal arrangement but outside the N-gon as absent.
|
||||
// Tiles inside the N-gon are left as default (no entry = void tile = present).
|
||||
for (int x = 0; x < dim; x++)
|
||||
for (int y = 0; y < dim; y++)
|
||||
{
|
||||
int q = x - R, r = y - R;
|
||||
if (Math.Max(Math.Abs(q), Math.Max(Math.Abs(r), Math.Abs(q + r))) > R)
|
||||
continue; // outside hex bounding circle — not rendered
|
||||
|
||||
double cx = q + r * 0.5;
|
||||
double cy = r * Math.Sqrt(3.0) / 2.0;
|
||||
if (!NPolyInside(cx, cy, N, R))
|
||||
{
|
||||
var tile = GetOrCreateTile(x, y);
|
||||
tile.IsAbsent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// N vertex positions (scaled hex Cartesian)
|
||||
var verts = new (double vx, double vy)[N];
|
||||
for (int k = 0; k < N; k++)
|
||||
{
|
||||
double angle = Math.PI / 2.0 + 2.0 * Math.PI * k / N;
|
||||
verts[k] = (R * Math.Cos(angle), R * Math.Sin(angle));
|
||||
}
|
||||
|
||||
// For each player count 2..N, pick evenly-spaced corners.
|
||||
int half = Math.Max(1, R / 4);
|
||||
for (int playerCount = 2; playerCount <= N; playerCount++)
|
||||
{
|
||||
var seatMap = new Dictionary<int, HashSet<string>>();
|
||||
for (int seat = 0; seat < playerCount; seat++)
|
||||
{
|
||||
int ci = (int)Math.Round((double)seat * N / playerCount) % N;
|
||||
var (vx, vy) = verts[ci];
|
||||
var zone = new HashSet<string>();
|
||||
|
||||
// Corner tile
|
||||
var corner = FindNearestNgonTile(vx, vy, R);
|
||||
zone.Add(TileKey(corner.x, corner.y));
|
||||
|
||||
// Edge tiles toward adjacent vertices
|
||||
for (int step = 1; step <= half; step++)
|
||||
{
|
||||
var p = k.Split(',');
|
||||
return !IsHexInBounds(int.Parse(p[0]), int.Parse(p[1]), n);
|
||||
});
|
||||
double t = (double)step / (half + 1);
|
||||
int nextCi = (ci + 1) % N;
|
||||
int prevCi = (ci - 1 + N) % N;
|
||||
var n1 = FindNearestNgonTile(vx + (verts[nextCi].vx - vx) * t,
|
||||
vy + (verts[nextCi].vy - vy) * t, R);
|
||||
var n2 = FindNearestNgonTile(vx + (verts[prevCi].vx - vx) * t,
|
||||
vy + (verts[prevCi].vy - vy) * t, R);
|
||||
zone.Add(TileKey(n1.x, n1.y));
|
||||
zone.Add(TileKey(n2.x, n2.y));
|
||||
}
|
||||
|
||||
seatMap[seat] = zone;
|
||||
}
|
||||
_zones[playerCount] = seatMap;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGridTypeChanged()
|
||||
@@ -554,27 +625,71 @@ else
|
||||
_zones.Clear();
|
||||
if (_template.GridType == "Hexagon")
|
||||
{
|
||||
_template.HexSides = _pendingHexSides;
|
||||
int dim = 2 * _pendingHexSides - 1;
|
||||
_template.Width = dim;
|
||||
_template.Height = dim;
|
||||
_template.HexSides = _pendingHexRadius + 1;
|
||||
_template.HexPolygonSides = _pendingHexPolySides;
|
||||
int dim = 2 * _pendingHexRadius + 1;
|
||||
_template.Width = dim;
|
||||
_template.Height = dim;
|
||||
}
|
||||
else
|
||||
{
|
||||
_template.HexSides = 0;
|
||||
_template.Width = _pendingWidth;
|
||||
_template.Height = _pendingHeight;
|
||||
_template.HexSides = 0;
|
||||
_template.HexPolygonSides = 6;
|
||||
_template.Width = _pendingWidth;
|
||||
_template.Height = _pendingHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Hex geometry helpers ──────────────────────────────────────────────────
|
||||
|
||||
private static bool IsHexInBounds(int x, int y, int N)
|
||||
/// <summary>
|
||||
/// True when offset coordinate (x,y) is within the hex grid of radius R=sides−1.
|
||||
/// Used for the SVG canvas to skip cells outside the bounding circle.
|
||||
/// </summary>
|
||||
private static bool IsHexInBounds(int x, int y, int sides)
|
||||
{
|
||||
int q = x - (N - 1);
|
||||
int r = y - (N - 1);
|
||||
int s = -q - r;
|
||||
return Math.Max(Math.Abs(q), Math.Max(Math.Abs(r), Math.Abs(s))) <= N - 1;
|
||||
int R = sides - 1;
|
||||
int q = x - R, r = y - R;
|
||||
return Math.Max(Math.Abs(q), Math.Max(Math.Abs(r), Math.Abs(q + r))) <= R;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True when scaled hex-Cartesian point (cx,cy) is inside a regular N-gon with
|
||||
/// circumradius R. Uses cross-product test on each CCW edge (slightly expanded to
|
||||
/// include boundary tiles).
|
||||
/// </summary>
|
||||
private static bool NPolyInside(double cx, double cy, int N, double R)
|
||||
{
|
||||
double Rexp = R * 1.02; // slight expansion to include perimeter tiles
|
||||
for (int k = 0; k < N; k++)
|
||||
{
|
||||
double a1 = Math.PI / 2.0 + 2.0 * Math.PI * k / N;
|
||||
double a2 = Math.PI / 2.0 + 2.0 * Math.PI * (k + 1) / N;
|
||||
double v1x = Rexp * Math.Cos(a1), v1y = Rexp * Math.Sin(a1);
|
||||
double v2x = Rexp * Math.Cos(a2), v2y = Rexp * Math.Sin(a2);
|
||||
double cross = (v2x - v1x) * (cy - v1y) - (v2y - v1y) * (cx - v1x);
|
||||
if (cross < -1e-9) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Find the nearest non-absent hex tile (in offset coords) to scaled-Cartesian (vx,vy).</summary>
|
||||
private (int x, int y) FindNearestNgonTile(double vx, double vy, int R)
|
||||
{
|
||||
(int x, int y) best = (R, R);
|
||||
double bestDist = double.MaxValue;
|
||||
for (int q = -R; q <= R; q++)
|
||||
for (int r = -R; r <= R; r++)
|
||||
{
|
||||
if (Math.Abs(q + r) > R) continue;
|
||||
int ox = q + R, oy = r + R;
|
||||
if (_tiles.TryGetValue(TileKey(ox, oy), out var td) && td.IsAbsent) continue;
|
||||
double tcx = q + r * 0.5;
|
||||
double tcy = r * Math.Sqrt(3.0) / 2.0;
|
||||
double d = (tcx - vx) * (tcx - vx) + (tcy - vy) * (tcy - vy);
|
||||
if (d < bestDist) { bestDist = d; best = (ox, oy); }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private static double HexCellX(int x, int y, int N, double R, double pad)
|
||||
|
||||
@@ -209,8 +209,9 @@ public sealed record BoardTemplateDto(
|
||||
bool IsAvailableForCustom,
|
||||
string TilesJson,
|
||||
string StartingZonesJson,
|
||||
string GridType = "Square",
|
||||
int HexSides = 0);
|
||||
string GridType = "Square",
|
||||
int HexSides = 0,
|
||||
int HexPolygonSides = 6);
|
||||
|
||||
// ── BGM config ───────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ internal sealed class ContentBoardTemplatesHandler : IMessageHandler
|
||||
t.TilesJson,
|
||||
t.StartingZonesJson,
|
||||
t.GridType,
|
||||
t.HexSides))
|
||||
t.HexSides,
|
||||
t.HexPolygonSides))
|
||||
.ToListAsync(ct);
|
||||
|
||||
return ServerMessage.Reply(
|
||||
|
||||
@@ -32,8 +32,11 @@ public sealed class BoardTemplate
|
||||
public int MinPlayers { get; set; } = 2;
|
||||
public int MaxPlayers { get; set; } = 2;
|
||||
|
||||
public string GridType { get; set; } = "Square";
|
||||
public int HexSides { get; set; } = 0;
|
||||
public string GridType { get; set; } = "Square";
|
||||
/// <summary>Radius + 1: used for hex coordinate math. 0 = square grid.</summary>
|
||||
public int HexSides { get; set; } = 0;
|
||||
/// <summary>Number of polygon sides/corners (3–10). 6 = regular hexagon. Only meaningful when GridType = "Hexagon".</summary>
|
||||
public int HexPolygonSides { get; set; } = 6;
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
Generated
+541
@@ -0,0 +1,541 @@
|
||||
// <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("20260402023622_AddBoardTemplateHexPolygonSides")]
|
||||
partial class AddBoardTemplateHexPolygonSides
|
||||
{
|
||||
/// <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<string>("GridType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Height")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("HexPolygonSides")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("HexSides")
|
||||
.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<int?>("HexSidesOverride")
|
||||
.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<string>("TeamAssignmentsJson")
|
||||
.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<string>("GridType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("HandSizeCap")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("HexSides")
|
||||
.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
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Game
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddBoardTemplateHexPolygonSides : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "HexPolygonSides",
|
||||
schema: "game",
|
||||
table: "board_templates",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HexPolygonSides",
|
||||
schema: "game",
|
||||
table: "board_templates");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,9 @@ namespace SOR.Database.Migrations.Game
|
||||
b.Property<int>("Height")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("HexPolygonSides")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("HexSides")
|
||||
.HasColumnType("integer");
|
||||
|
||||
|
||||
@@ -22,11 +22,18 @@ public sealed class Board
|
||||
public Dictionary<int, HashSet<Coord>> StartingZones { get; init; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// When > 0, this board uses hex grid rules with the given number of sides (N).
|
||||
/// Diameter = 2N−1. 0 = square grid.
|
||||
/// When > 0, this board uses hex grid rules. Value = radius + 1, used for
|
||||
/// axial-coordinate math (ToAxial center offset). 0 = square grid.
|
||||
/// </summary>
|
||||
public int HexSides { get; init; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// True when this board was built from a stored template whose tile set defines
|
||||
/// the exact board shape (which may be a non-hexagonal polygon).
|
||||
/// IsInBounds and GetNeighbors use tile existence rather than the hex formula.
|
||||
/// </summary>
|
||||
public bool IsTemplateBased { get; init; } = false;
|
||||
|
||||
// Base1 pool: elemental basics + Aether (never Void — Base1 always carries a real affinity).
|
||||
private static readonly Affinity[] _base1Pool =
|
||||
[Affinity.Lake, Affinity.Hill, Affinity.Forest, Affinity.Field, Affinity.Aether];
|
||||
@@ -81,9 +88,13 @@ public sealed class Board
|
||||
}
|
||||
|
||||
public bool IsInBounds(Coord c)
|
||||
=> HexSides > 0
|
||||
? HexGrid.IsInBounds(c, HexSides)
|
||||
: c.X >= 0 && c.X < Width && c.Y >= 0 && c.Y < Height;
|
||||
{
|
||||
if (IsTemplateBased)
|
||||
return Tiles.ContainsKey(c.ToKey());
|
||||
if (HexSides > 0)
|
||||
return HexGrid.IsInBounds(c, HexSides);
|
||||
return c.X >= 0 && c.X < Width && c.Y >= 0 && c.Y < Height;
|
||||
}
|
||||
|
||||
public Tile? GetTile(Coord c)
|
||||
=> Tiles.TryGetValue(c.ToKey(), out var t) ? t : null;
|
||||
@@ -100,9 +111,17 @@ public sealed class Board
|
||||
/// For hex boards uses the six axial directions; for square boards uses four orthogonal directions.
|
||||
/// </summary>
|
||||
public IEnumerable<Coord> GetNeighbors(Coord c)
|
||||
=> HexSides > 0
|
||||
? HexGrid.Neighbors(c, HexSides)
|
||||
: c.OrthogonalNeighbors().Where(IsInBounds);
|
||||
{
|
||||
if (HexSides > 0)
|
||||
{
|
||||
// Template boards: all 6 hex neighbours filtered by tile existence.
|
||||
// Procedural boards: filtered by the hexagonal formula in HexGrid.Neighbors.
|
||||
return IsTemplateBased
|
||||
? HexGrid.AllNeighbors(c, HexSides).Where(IsInBounds)
|
||||
: HexGrid.Neighbors(c, HexSides);
|
||||
}
|
||||
return c.OrthogonalNeighbors().Where(IsInBounds);
|
||||
}
|
||||
|
||||
public Coord? FindOccupant(string instanceId)
|
||||
{
|
||||
|
||||
@@ -531,11 +531,12 @@ public static class BoardShapeGenerator
|
||||
|
||||
return new Board
|
||||
{
|
||||
Width = snapshot.Width,
|
||||
Height = snapshot.Height,
|
||||
HexSides = snapshot.HexSides,
|
||||
Tiles = tiles,
|
||||
StartingZones = zones,
|
||||
Width = snapshot.Width,
|
||||
Height = snapshot.Height,
|
||||
HexSides = snapshot.HexSides,
|
||||
IsTemplateBased = snapshot.HexSides > 0, // use tile-existence bounds for non-square templates
|
||||
Tiles = tiles,
|
||||
StartingZones = zones,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,18 @@ public static class HexGrid
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All six hex neighbours of c without any bounds filter.
|
||||
/// Use when the caller supplies its own in-bounds check (e.g. template boards
|
||||
/// that rely on tile existence rather than the hexagonal formula).
|
||||
/// </summary>
|
||||
public static IEnumerable<Coord> AllNeighbors(Coord c, int sides)
|
||||
{
|
||||
var (q, r) = ToAxial(c, sides);
|
||||
foreach (var (dq, dr) in Directions)
|
||||
yield return FromAxial(q + dq, r + dr, sides);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if there is unobstructed LOS from <paramref name="from"/> to
|
||||
/// <paramref name="to"/> on a hex board. Uses cube-coordinate linear interpolation
|
||||
|
||||
Reference in New Issue
Block a user