Tile bindings added to admin portal, CDN improvements

This commit is contained in:
dingo
2026-03-09 10:48:24 -04:00
parent 4fa4c21b6e
commit bb0f7dae91
11 changed files with 1426 additions and 33 deletions
@@ -97,15 +97,27 @@
<i class="bi bi-phone me-2"></i>Client Versions
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white" href="/content/ai-assets" Match="NavLinkMatch.All">
<i class="bi bi-robot me-2"></i>AI Art Tracker
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white" href="/content/cdn" Match="NavLinkMatch.All">
<i class="bi bi-hdd-network me-2"></i>CDN Browser
<i class="bi bi-hdd-network me-2"></i>Content
</NavLink>
<ul class="nav nav-pills flex-column gap-1 ps-3 mt-1">
<li class="nav-item">
<NavLink class="nav-link text-white-50 py-1" href="/content/cdn">
<i class="bi bi-hdd-network me-2"></i>CDN Browser
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white-50 py-1" href="/content/tile-models">
<i class="bi bi-grid-3x3 me-2"></i>Tile Models
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white-50 py-1" href="/content/ai-assets">
<i class="bi bi-robot me-2"></i>AI Art Tracker
</NavLink>
</li>
</ul>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white" href="/support/bug-reports" Match="NavLinkMatch.All">
@@ -156,9 +156,19 @@
<div class="col-lg-8">
<div class="card shadow-sm">
<div class="card-header fw-medium d-flex justify-content-between align-items-center">
<span>Objects <span class="badge bg-secondary ms-1">@_items.Count</span></span>
<small class="text-muted font-monospace">@_activePrefixDisplay</small>
<div class="card-header fw-medium">
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Objects <span class="badge bg-secondary ms-1">@_items.Count</span>
@if (!string.IsNullOrWhiteSpace(_search))
{
<span class="badge bg-info ms-1">@FilteredSorted().Count() shown</span>
}
</span>
<small class="text-muted font-monospace">@_activePrefixDisplay</small>
</div>
<input @bind="_search" @bind:event="oninput"
class="form-control form-control-sm font-monospace"
placeholder="Filter by key name…" />
</div>
<div class="card-body p-0">
@if (_loading && _items.Count == 0)
@@ -175,15 +185,21 @@
<table class="table table-sm table-hover mb-0">
<thead class="sticky-top bg-body">
<tr>
<th>Key</th>
<th style="width:90px">AI</th>
<th style="width:110px">Size</th>
<th style="width:180px">Modified</th>
<th style="width:270px">Actions</th>
<th style="cursor:pointer" @onclick='() => SetSort("Key")'>
Key @SortIcon("Key")
</th>
<th style="width:60px">AI</th>
<th style="width:100px;cursor:pointer" @onclick='() => SetSort("Size")'>
Size @SortIcon("Size")
</th>
<th style="width:160px;cursor:pointer" @onclick='() => SetSort("Modified")'>
Modified @SortIcon("Modified")
</th>
<th style="width:260px">Actions</th>
</tr>
</thead>
<tbody>
@foreach (var item in _items)
@foreach (var item in FilteredSorted())
{
var row = item;
<tr class="@(_replaceTarget?.Key == row.Key ? "table-warning" : "")">
@@ -195,39 +211,48 @@
}
else
{
<span class="text-muted small">No</span>
<span class="text-muted small">—</span>
}
</td>
<td class="align-middle">@FormatBytes(row.Size)</td>
<td class="align-middle text-muted small">@row.LastModified.ToString("yyyy-MM-dd HH:mm UTC")</td>
<td class="align-middle small">@FormatBytes(row.Size)</td>
<td class="align-middle text-muted small">@row.LastModified.ToString("yyyy-MM-dd HH:mm")</td>
<td class="align-middle">
<div class="d-flex flex-wrap gap-1">
<a class="btn btn-sm btn-outline-primary"
href="@row.PublicUrl"
target="_blank"
rel="noopener noreferrer">
<i class="bi bi-eye me-1"></i>View
</a>
@if (IsModel(row.Key))
{
<button class="btn btn-sm btn-outline-info"
@onclick="() => OpenPreview(row.PublicUrl)">
<i class="bi bi-box me-1"></i>3D
</button>
}
else
{
<a class="btn btn-sm btn-outline-primary"
href="@row.PublicUrl"
target="_blank"
rel="noopener noreferrer">
<i class="bi bi-eye me-1"></i>View
</a>
}
<button class="btn btn-sm btn-outline-secondary"
@onclick="() => CopyUrlAsync(row.PublicUrl)">
<i class="bi bi-clipboard me-1"></i>Copy URL
<i class="bi bi-clipboard"></i>
</button>
<button class="btn btn-sm btn-outline-warning"
@onclick="() => SelectReplaceTarget(row)">
<i class="bi bi-arrow-repeat me-1"></i>Replace
<i class="bi bi-arrow-repeat"></i>
</button>
<button class="btn btn-sm btn-outline-danger"
disabled="@(_deletingKey == row.Key)"
@onclick="() => DeleteAsync(row)">
@if (_deletingKey == row.Key)
{
<span class="spinner-border spinner-border-sm me-1"></span>
<span class="spinner-border spinner-border-sm"></span>
}
else
{
<i class="bi bi-trash me-1"></i>
<i class="bi bi-trash"></i>
}
Delete
</button>
</div>
</td>
@@ -250,6 +275,41 @@
</div>
</div>
<!-- 3D Preview Modal -->
@if (_previewUrl is not null)
{
<div class="modal d-block" tabindex="-1" style="background:rgba(0,0,0,0.55)">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="bi bi-box me-2"></i>3D Preview</h5>
<button type="button" class="btn-close" @onclick="() => _previewUrl = null"></button>
</div>
<div class="modal-body p-0" style="background:#f0f0f0">
<model-viewer src="@_previewUrl"
camera-controls
auto-rotate
auto-rotate-delay="1000"
environment-image="neutral"
shadow-intensity="0.8"
style="width:100%;height:520px;background:#f5f5f5">
</model-viewer>
</div>
<div class="modal-footer py-2">
<span class="text-muted small font-monospace me-auto text-break">@_previewUrl</span>
<button class="btn btn-sm btn-outline-secondary"
@onclick="() => CopyUrlAsync(_previewUrl)">
<i class="bi bi-clipboard me-1"></i>Copy URL
</button>
<button class="btn btn-sm btn-secondary" @onclick="() => _previewUrl = null">Close</button>
</div>
</div>
</div>
</div>
}
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js"></script>
@code {
private readonly List<CdnObjectRow> _items = new();
private readonly (string Key, string Label)[] _knownPrefixes =
@@ -278,8 +338,54 @@
private bool _hasMore;
private CdnObjectRow? _replaceTarget;
// Search / sort state
private string _search = "";
private string _sortCol = "Modified";
private bool _sortAsc = false;
// 3D preview
private string? _previewUrl;
private string _activePrefixDisplay => string.IsNullOrEmpty(_activePrefix) ? "/" : $"/{_activePrefix}";
private IEnumerable<CdnObjectRow> FilteredSorted()
{
var q = _items.AsEnumerable();
if (!string.IsNullOrWhiteSpace(_search))
q = q.Where(r => r.Key.Contains(_search, StringComparison.OrdinalIgnoreCase));
q = _sortCol switch
{
"Key" => _sortAsc ? q.OrderBy(r => r.Key) : q.OrderByDescending(r => r.Key),
"Size" => _sortAsc ? q.OrderBy(r => r.Size) : q.OrderByDescending(r => r.Size),
_ => _sortAsc ? q.OrderBy(r => r.LastModified) : q.OrderByDescending(r => r.LastModified),
};
return q;
}
private void SetSort(string col)
{
if (_sortCol == col) _sortAsc = !_sortAsc;
else { _sortCol = col; _sortAsc = true; }
}
private string SortIcon(string col)
{
if (_sortCol != col) return "⇅";
return _sortAsc ? "↑" : "↓";
}
private static bool IsModel(string key) =>
key.EndsWith(".glb", StringComparison.OrdinalIgnoreCase) ||
key.EndsWith(".gltf", StringComparison.OrdinalIgnoreCase);
private void OpenPreview(string url)
{
_previewUrl = url;
}
protected override async Task OnInitializedAsync()
{
var options = CdnOptionsAccessor.Value;
@@ -291,6 +397,7 @@
{
_activePrefix = NormalizePrefix(_prefixInput);
_replaceTarget = null;
_search = "";
await LoadAsync(reset: true);
}
@@ -299,6 +406,7 @@
_prefixInput = prefix;
_activePrefix = NormalizePrefix(prefix);
_replaceTarget = null;
_search = "";
await LoadAsync(reset: true);
}
@@ -0,0 +1,432 @@
@page "/content/tile-models"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@using Amazon.S3
@using Amazon.S3.Model
@using Microsoft.EntityFrameworkCore
@using Microsoft.Extensions.Options
@using SOR.Cdn
@using SOR.Database.Contexts
@using SOR.Database.Entities.Catalog
@using SOR.Database.Enums
@inject CatalogDbContext Db
@inject IAmazonS3 S3
@inject IOptions<CdnOptions> CdnOptionsAccessor
<PageTitle>Tile Models – SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h1 class="mb-0">Tile Model Manager</h1>
<div class="text-muted small">Assign 3D models to tile affinities for Square and Hex grids</div>
</div>
<button class="btn btn-outline-secondary btn-sm" @onclick="LoadAsync" disabled="@_loading">
<i class="bi bi-arrow-clockwise me-1"></i>Refresh
</button>
</div>
@if (_message is not null)
{
<div class="alert @(_isError ? "alert-danger" : "alert-success") alert-dismissible">
@_message
<button type="button" class="btn-close" @onclick='() => _message = null'></button>
</div>
}
@if (_loading)
{
<p class="text-muted">Loading…</p>
}
else
{
<!-- Category sections -->
@foreach (var group in _affinityGroups)
{
<div class="card shadow-sm mb-4">
<div class="card-header fw-medium">@group.Label</div>
<div class="card-body p-0">
<table class="table table-sm table-hover mb-0">
<thead class="table-light">
<tr>
<th style="width:160px">Affinity</th>
<th>Square Model</th>
<th>Hex Model</th>
</tr>
</thead>
<tbody>
@foreach (var affinity in group.Affinities)
{
var squareBinding = _bindings.GetValueOrDefault((affinity, TileShape.Square));
var hexBinding = _bindings.GetValueOrDefault((affinity, TileShape.Hex));
<tr>
<td class="align-middle fw-semibold small">@affinity</td>
<td class="align-middle">
@ModelCell(squareBinding, affinity, TileShape.Square)
</td>
<td class="align-middle">
@ModelCell(hexBinding, affinity, TileShape.Hex)
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
}
<!-- Assign / Picker Modal -->
@if (_pickerOpen)
{
<div class="modal d-block" tabindex="-1" style="background:rgba(0,0,0,0.55)">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
Assign Model — <span class="text-primary">@_pickerAffinity</span>
<span class="badge bg-secondary ms-2">@_pickerShape</span>
</h5>
<button type="button" class="btn-close" @onclick="ClosePicker"></button>
</div>
<div class="modal-body">
<input @bind="_pickerSearch" @bind:event="oninput"
class="form-control form-control-sm font-monospace mb-3"
placeholder="Filter models…" />
@if (_pickerLoading)
{
<div class="text-muted text-center py-4">
<span class="spinner-border spinner-border-sm me-2"></span>Loading CDN models…
</div>
}
else if (!_pickerModels.Any())
{
<div class="text-muted text-center py-4">
No .glb or .gltf files found in the <code>models/</code> prefix.
Upload models via the CDN Browser first.
</div>
}
else
{
<div class="row g-3">
@foreach (var model in PickerFiltered())
{
var m = model;
var isSelected = _pickerSelected == m.Key;
<div class="col-md-4">
<div class="card h-100 @(isSelected ? "border-primary" : "")"
style="cursor:pointer" @onclick="() => _pickerSelected = m.Key">
@if (_pickerPreview == m.Key)
{
<div style="background:#f0f0f0;height:200px">
<model-viewer src="@m.PublicUrl"
camera-controls
auto-rotate
environment-image="neutral"
style="width:100%;height:200px;background:#f5f5f5">
</model-viewer>
</div>
}
else
{
<div class="d-flex justify-content-center align-items-center"
style="height:80px;background:#f8f9fa">
<button class="btn btn-sm btn-outline-info"
@onclick:stopPropagation="true"
@onclick="() => _pickerPreview = m.Key">
<i class="bi bi-box me-1"></i>Preview 3D
</button>
</div>
}
<div class="card-body py-2 px-3">
<div class="font-monospace small text-break">@m.ShortName</div>
<div class="text-muted" style="font-size:0.7rem">@m.Key</div>
</div>
@if (isSelected)
{
<div class="card-footer py-1 bg-primary text-white text-center small">
✓ Selected
</div>
}
</div>
</div>
}
</div>
}
</div>
<div class="modal-footer">
<button class="btn btn-secondary" @onclick="ClosePicker">Cancel</button>
<button class="btn btn-primary"
disabled="@(_pickerSelected is null || _saving)"
@onclick="SaveBindingAsync">
@if (_saving)
{
<span class="spinner-border spinner-border-sm me-1"></span>
}
Assign Selected
</button>
</div>
</div>
</div>
</div>
}
<!-- 3D Preview Modal (standalone) -->
@if (_previewUrl is not null)
{
<div class="modal d-block" tabindex="-1" style="background:rgba(0,0,0,0.55)">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="bi bi-box me-2"></i>3D Preview</h5>
<button type="button" class="btn-close" @onclick="() => _previewUrl = null"></button>
</div>
<div class="modal-body p-0" style="background:#f0f0f0">
<model-viewer src="@_previewUrl"
camera-controls
auto-rotate
environment-image="neutral"
shadow-intensity="0.8"
style="width:100%;height:520px;background:#f5f5f5">
</model-viewer>
</div>
<div class="modal-footer py-2">
<button class="btn btn-sm btn-secondary" @onclick="() => _previewUrl = null">Close</button>
</div>
</div>
</div>
</div>
}
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js"></script>
@code {
// ── State ────────────────────────────────────────────────────────────────
private bool _loading = true;
private string? _message;
private bool _isError;
// Loaded bindings: (Affinity, Shape) → entity
private Dictionary<(Affinity, TileShape), TileModelBinding> _bindings = new();
// Picker state
private bool _pickerOpen;
private bool _pickerLoading;
private bool _saving;
private Affinity _pickerAffinity;
private TileShape _pickerShape;
private string _pickerSearch = "";
private string? _pickerSelected;
private string? _pickerPreview;
private List<ModelItem> _pickerModels = new();
// Standalone 3D preview
private string? _previewUrl;
// ── Affinity groupings ────────────────────────────────────────────────────
private static readonly (string Label, Affinity[] Affinities)[] _affinityGroups =
{
("Basic", new[] { Affinity.Void, Affinity.Aether, Affinity.Lake, Affinity.Hill, Affinity.Forest, Affinity.Field }),
("Non-Basic", new[] { Affinity.Ocean, Affinity.Island, Affinity.Marsh, Affinity.Swamp,
Affinity.Mountain, Affinity.Steppe, Affinity.Fort, Affinity.Plains,
Affinity.Grove, Affinity.Jungle }),
("Aether / Void", new[] { Affinity.UnstableAether, Affinity.PerfectAether, Affinity.PureVoid }),
("Gateways", new[] { Affinity.GatewayLake, Affinity.GatewayHill, Affinity.GatewayForest, Affinity.GatewayField }),
};
// ── Lifecycle ─────────────────────────────────────────────────────────────
protected override async Task OnInitializedAsync() => await LoadAsync();
private async Task LoadAsync()
{
_loading = true;
var all = await Db.TileModelBindings.ToListAsync();
_bindings = all.ToDictionary(b => (b.Affinity, b.Shape));
_loading = false;
}
// ── Picker ────────────────────────────────────────────────────────────────
private async Task OpenPickerAsync(Affinity affinity, TileShape shape)
{
_pickerAffinity = affinity;
_pickerShape = shape;
_pickerSelected = null;
_pickerPreview = null;
_pickerSearch = "";
_pickerOpen = true;
_pickerLoading = true;
// Pre-select existing binding if any
if (_bindings.TryGetValue((affinity, shape), out var existing))
_pickerSelected = existing.ModelCdnKey;
await LoadPickerModelsAsync();
}
private async Task LoadPickerModelsAsync()
{
try
{
var options = CdnOptionsAccessor.Value;
var request = new ListObjectsV2Request
{
BucketName = options.BucketName,
Prefix = "models/",
MaxKeys = 1000,
};
var response = await S3.ListObjectsV2Async(request);
_pickerModels = response.S3Objects
.Where(o => !o.Key.EndsWith('/') &&
(o.Key.EndsWith(".glb", StringComparison.OrdinalIgnoreCase) ||
o.Key.EndsWith(".gltf", StringComparison.OrdinalIgnoreCase)))
.Select(o => new ModelItem
{
Key = o.Key,
ShortName = o.Key.Contains('/') ? o.Key[(o.Key.LastIndexOf('/') + 1)..] : o.Key,
PublicUrl = BuildPublicUrl(options, o.Key),
})
.OrderBy(m => m.Key)
.ToList();
}
catch (Exception ex)
{
_message = $"Failed to load CDN models: {ex.Message}";
_isError = true;
}
finally
{
_pickerLoading = false;
}
}
private IEnumerable<ModelItem> PickerFiltered()
{
if (string.IsNullOrWhiteSpace(_pickerSearch))
return _pickerModels;
return _pickerModels.Where(m =>
m.Key.Contains(_pickerSearch, StringComparison.OrdinalIgnoreCase));
}
private void ClosePicker()
{
_pickerOpen = false;
_pickerModels = new();
_pickerSelected = null;
_pickerPreview = null;
}
private async Task SaveBindingAsync()
{
if (_pickerSelected is null) return;
_saving = true;
try
{
var options = CdnOptionsAccessor.Value;
var publicUrl = BuildPublicUrl(options, _pickerSelected);
var binding = await Db.TileModelBindings
.FirstOrDefaultAsync(b => b.Affinity == _pickerAffinity && b.Shape == _pickerShape);
if (binding is null)
{
binding = new TileModelBinding { Affinity = _pickerAffinity, Shape = _pickerShape };
Db.TileModelBindings.Add(binding);
}
binding.ModelCdnKey = _pickerSelected;
binding.ModelPublicUrl = publicUrl;
binding.UpdatedAt = DateTimeOffset.UtcNow;
await Db.SaveChangesAsync();
_bindings[(_pickerAffinity, _pickerShape)] = binding;
_message = $"Assigned {_pickerSelected} → {_pickerAffinity} / {_pickerShape}.";
_isError = false;
ClosePicker();
}
catch (Exception ex)
{
_message = $"Save failed: {ex.Message}";
_isError = true;
}
finally
{
_saving = false;
}
}
private async Task ClearBindingAsync(Affinity affinity, TileShape shape)
{
var binding = await Db.TileModelBindings
.FirstOrDefaultAsync(b => b.Affinity == affinity && b.Shape == shape);
if (binding is not null)
{
Db.TileModelBindings.Remove(binding);
await Db.SaveChangesAsync();
}
_bindings.Remove((affinity, shape));
_message = $"Cleared {affinity} / {shape}.";
_isError = false;
}
// ── Helpers ───────────────────────────────────────────────────────────────
private RenderFragment ModelCell(TileModelBinding? binding, Affinity affinity, TileShape shape) => __builder =>
{
if (binding is not null)
{
<div class="d-flex align-items-center gap-2">
<span class="font-monospace small text-break flex-grow-1">
@(binding.ModelCdnKey.Contains('/') ? binding.ModelCdnKey[(binding.ModelCdnKey.LastIndexOf('/') + 1)..] : binding.ModelCdnKey)
</span>
<button class="btn btn-sm btn-outline-info py-0"
@onclick="() => _previewUrl = binding.ModelPublicUrl"
title="Preview 3D model">
<i class="bi bi-box"></i>
</button>
<button class="btn btn-sm btn-outline-warning py-0"
@onclick="() => OpenPickerAsync(affinity, shape)"
title="Change model">
<i class="bi bi-arrow-repeat"></i>
</button>
<button class="btn btn-sm btn-outline-danger py-0"
@onclick="() => ClearBindingAsync(affinity, shape)"
title="Remove binding">
<i class="bi bi-x"></i>
</button>
</div>
}
else
{
<button class="btn btn-sm btn-outline-secondary"
@onclick="() => OpenPickerAsync(affinity, shape)">
<i class="bi bi-plus me-1"></i>Assign
</button>
}
};
private static string BuildPublicUrl(CdnOptions options, string key)
{
var baseUrl = options.PublicBaseUrl.TrimEnd('/');
var bucketSegment = options.BucketName.Trim('/');
return baseUrl.EndsWith("/" + bucketSegment, StringComparison.OrdinalIgnoreCase)
? $"{baseUrl}/{key}"
: $"{baseUrl}/{bucketSegment}/{key}";
}
private sealed class ModelItem
{
public string Key { get; init; } = "";
public string ShortName { get; init; } = "";
public string PublicUrl { get; init; } = "";
}
}
@@ -1,6 +1,7 @@
@page "/game/sessions/{Id:guid}"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@using Microsoft.EntityFrameworkCore
@using System.Text.Json
@using SOR.Database.Contexts
@using SOR.Database.Enums
@inject GameDbContext Db
@@ -127,7 +128,7 @@ else
{
<tr>
<td colspan="6" class="p-0">
<pre class="m-0 p-3 bg-light small" style="white-space:pre-wrap;word-break:break-all;max-height:300px;overflow:auto">@log.Payload</pre>
<pre class="m-0 p-3 bg-light small" style="white-space:pre-wrap;word-break:break-all;max-height:400px;overflow:auto;color:#000">@log.Payload</pre>
</td>
</tr>
}
@@ -135,7 +136,7 @@ else
{
<tr>
<td colspan="6" class="p-0">
<pre class="m-0 p-3 bg-light small" style="white-space:pre-wrap;word-break:break-all;max-height:300px;overflow:auto">@log.Result</pre>
<pre class="m-0 p-3 bg-light small" style="white-space:pre-wrap;word-break:break-all;max-height:400px;overflow:auto;color:#000">@log.Result</pre>
</td>
</tr>
}
@@ -249,8 +250,8 @@ else
ActorId = l.ActorAccountId.ToString(),
ActorName = ActorName(l.ActorAccountId),
ActionType = l.ActionType,
Payload = l.PayloadJson,
Result = l.ResultJson,
Payload = PrettyJson(l.PayloadJson),
Result = PrettyJson(l.ResultJson),
}).ToList();
_loading = false;
@@ -280,4 +281,20 @@ else
nameof(GameSessionStatus.Abandoned) => "bg-secondary",
_ => "bg-light text-dark",
};
private static readonly JsonSerializerOptions _prettyOpts = new() { WriteIndented = true };
private static string? PrettyJson(string? raw)
{
if (raw is null) return null;
try
{
using var doc = JsonDocument.Parse(raw);
return JsonSerializer.Serialize(doc, _prettyOpts);
}
catch
{
return raw;
}
}
}
@@ -26,6 +26,7 @@ public sealed class CatalogDbContext : DbContext
public DbSet<CardAsset> CardAssets => Set<CardAsset>();
public DbSet<CardAnimationBinding> AnimationBindings => Set<CardAnimationBinding>();
public DbSet<CdnUploadRecord> CdnUploadRecords => Set<CdnUploadRecord>();
public DbSet<TileModelBinding> TileModelBindings => Set<TileModelBinding>();
protected override void OnModelCreating(ModelBuilder builder)
{
@@ -127,5 +128,17 @@ public sealed class CatalogDbContext : DbContext
e.HasIndex(r => r.Prefix);
e.HasIndex(r => r.IsAiGenerated);
});
builder.Entity<TileModelBinding>(e =>
{
e.ToTable("tile_model_bindings");
e.HasKey(t => t.Id);
e.Property(t => t.Affinity).HasConversion<string>().IsRequired();
e.Property(t => t.Shape).HasConversion<string>().IsRequired();
e.Property(t => t.ModelCdnKey).IsRequired();
e.Property(t => t.ModelPublicUrl).IsRequired();
// One model per affinity+shape pair.
e.HasIndex(t => new { t.Affinity, t.Shape }).IsUnique();
});
}
}
@@ -0,0 +1,26 @@
namespace SOR.Database.Entities.Catalog;
using SOR.Database.Enums;
/// <summary>
/// Maps a (Affinity × TileShape) combination to a 3D model hosted on the CDN.
/// The client uses this to render the correct tile mesh for each affinity/shape.
/// </summary>
public sealed class TileModelBinding
{
public Guid Id { get; set; } = Guid.NewGuid();
/// <summary>Tile affinity this binding applies to.</summary>
public Affinity Affinity { get; set; }
/// <summary>Tile grid shape this binding applies to (Square or Hex).</summary>
public TileShape Shape { get; set; }
/// <summary>S3 object key for the 3D model, e.g. "models/tiles/forest_square.glb".</summary>
public string ModelCdnKey { get; set; } = string.Empty;
/// <summary>Publicly accessible CDN URL for the model file.</summary>
public string ModelPublicUrl { get; set; } = string.Empty;
public DateTimeOffset UpdatedAt { get; set; }
}
@@ -0,0 +1,7 @@
namespace SOR.Database.Enums;
public enum TileShape
{
Square,
Hex,
}
@@ -0,0 +1,406 @@
// <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.Catalog
{
[DbContext(typeof(CatalogDbContext))]
[Migration("20260309100000_AddTileModelBindings")]
partial class AddTileModelBindings
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("catalog")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAnimationBinding", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ActionName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("AnimationCdnUrl")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("CardDefinitionId")
.HasColumnType("uuid");
b.Property<bool>("IsAiGenerated")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("CardDefinitionId", "ActionName")
.IsUnique();
b.ToTable("card_animation_bindings", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAsset", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AssetType")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("CardDefinitionId")
.HasColumnType("uuid");
b.Property<string>("CdnUrl")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsAiGenerated")
.HasColumnType("boolean");
b.Property<string>("MimeType")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("CardDefinitionId", "AssetType");
b.ToTable("card_assets", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AbilitiesJson")
.HasColumnType("jsonb")
.HasColumnName("abilities");
b.Property<string>("Affinity")
.IsRequired()
.HasColumnType("text");
b.Property<string>("AttackType")
.HasColumnType("text");
b.Property<bool?>("CanAttack")
.HasColumnType("boolean");
b.Property<bool?>("CanBeAttacked")
.HasColumnType("boolean");
b.Property<bool?>("CanBeBlocked")
.HasColumnType("boolean");
b.Property<bool?>("CanBeObstructed")
.HasColumnType("boolean");
b.Property<bool?>("CanBeSacrificed")
.HasColumnType("boolean");
b.Property<bool?>("CanDefend")
.HasColumnType("boolean");
b.Property<bool?>("CanMove")
.HasColumnType("boolean");
b.Property<bool?>("CanUseAbility")
.HasColumnType("boolean");
b.Property<string>("CardType")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("CollectorNumber")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int?>("Damage")
.HasColumnType("integer");
b.Property<long>("DefinitionVersion")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasDefaultValue(0L);
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("EffectsJson")
.HasColumnType("jsonb")
.HasColumnName("effects");
b.Property<string[]>("Genus")
.HasColumnType("text[]");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<bool>("IsRetired")
.HasColumnType("boolean");
b.Property<int?>("MaxAttackRange")
.HasColumnType("integer");
b.Property<int?>("MaxChannelRange")
.HasColumnType("integer");
b.Property<int?>("MaxDefense")
.HasColumnType("integer");
b.Property<int?>("MaxHealth")
.HasColumnType("integer");
b.Property<int?>("MinAttackRange")
.HasColumnType("integer");
b.Property<int?>("MinChannelRange")
.HasColumnType("integer");
b.Property<int?>("MovementPoints")
.HasColumnType("integer");
b.Property<string>("MovementType")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("OtherCostsJson")
.HasColumnType("jsonb")
.HasColumnName("other_costs");
b.Property<Guid?>("PreviousTierId")
.HasColumnType("uuid");
b.Property<string>("Rarity")
.IsRequired()
.HasColumnType("text");
b.Property<bool?>("RequiresLos")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("RetiredAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("SetId")
.HasColumnType("uuid");
b.Property<int>("SpCost")
.HasColumnType("integer");
b.Property<int>("StCost")
.HasColumnType("integer");
b.Property<string>("TerramorphaMode")
.HasColumnType("text");
b.Property<int?>("Tier")
.HasColumnType("integer");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("Affinity");
b.HasIndex("CardType");
b.HasIndex("DefinitionVersion");
b.HasIndex("Name");
b.HasIndex("PreviousTierId");
b.HasIndex("Rarity");
b.HasIndex("SetId");
b.HasIndex("IsPublished", "SetId");
b.ToTable("card_definitions", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardSet", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsActive")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<DateOnly?>("ReleaseDate")
.HasColumnType("date");
b.HasKey("Id");
b.HasIndex("Code")
.IsUnique();
b.ToTable("card_sets", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CdnUploadRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ContentType")
.HasColumnType("text");
b.Property<bool>("IsAiGenerated")
.HasColumnType("boolean");
b.Property<string>("ObjectKey")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Prefix")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PublicUrl")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("UploadedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("IsAiGenerated");
b.HasIndex("ObjectKey")
.IsUnique();
b.HasIndex("Prefix");
b.ToTable("cdn_upload_records", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.TileModelBinding", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Affinity")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Shape")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ModelCdnKey")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ModelPublicUrl")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("Affinity", "Shape")
.IsUnique();
b.ToTable("tile_model_bindings", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAnimationBinding", b =>
{
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "CardDefinition")
.WithMany("AnimationBindings")
.HasForeignKey("CardDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CardDefinition");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAsset", b =>
{
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "CardDefinition")
.WithMany("Assets")
.HasForeignKey("CardDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CardDefinition");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
{
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "PreviousTier")
.WithMany()
.HasForeignKey("PreviousTierId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("SOR.Database.Entities.Catalog.CardSet", "Set")
.WithMany("Cards")
.HasForeignKey("SetId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("PreviousTier");
b.Navigation("Set");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
{
b.Navigation("AnimationBindings");
b.Navigation("Assets");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardSet", b =>
{
b.Navigation("Cards");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,39 @@
namespace SOR.Database.Migrations.Catalog;
using System;
using Microsoft.EntityFrameworkCore.Migrations;
public partial class AddTileModelBindings : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "tile_model_bindings",
schema: "catalog",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Affinity = table.Column<string>(type: "text", nullable: false),
Shape = table.Column<string>(type: "text", nullable: false),
ModelCdnKey = table.Column<string>(type: "text", nullable: false),
ModelPublicUrl = table.Column<string>(type: "text", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
},
constraints: table =>
{
table.PrimaryKey("PK_tile_model_bindings", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_tile_model_bindings_Affinity_Shape",
schema: "catalog",
table: "tile_model_bindings",
columns: new[] { "Affinity", "Shape" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(name: "tile_model_bindings", schema: "catalog");
}
}
@@ -314,6 +314,39 @@ namespace SOR.Database.Migrations.Catalog
b.ToTable("cdn_upload_records", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.TileModelBinding", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Affinity")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Shape")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ModelCdnKey")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ModelPublicUrl")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("Affinity", "Shape")
.IsUnique();
b.ToTable("tile_model_bindings", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAnimationBinding", b =>
{
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "CardDefinition")
@@ -0,0 +1,300 @@
// <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("20260309000000_AddActionLogResult")]
partial class AddActionLogResult
{
/// <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.CustomLobby", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int?>("DrawPerTurnOverride")
.HasColumnType("integer");
b.Property<bool?>("FirstPlayerSkipsDrawOverride")
.HasColumnType("boolean");
b.Property<Guid?>("GameSessionId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestAccountId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestDeckId")
.HasColumnType("uuid");
b.Property<Guid>("HostAccountId")
.HasColumnType("uuid");
b.Property<Guid>("HostDeckId")
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("OpeningHandSizeOverride")
.HasColumnType("integer");
b.Property<int?>("SpAccumulationPerTurnOverride")
.HasColumnType("integer");
b.Property<int?>("SpCapOverride")
.HasColumnType("integer");
b.Property<bool?>("SpHasCapOverride")
.HasColumnType("boolean");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
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<int>("BoardWidth")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("DrawPerTurn")
.HasColumnType("integer");
b.Property<bool>("FirstPlayerSkipsDraw")
.HasColumnType("boolean");
b.Property<bool>("IsCustomDefault")
.HasColumnType("boolean");
b.Property<bool>("IsRankedDefault")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OpeningHandSize")
.HasColumnType("integer");
b.Property<int>("SpAccumulationPerTurn")
.HasColumnType("integer");
b.Property<int>("SpCap")
.HasColumnType("integer");
b.Property<bool>("SpHasCap")
.HasColumnType("boolean");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
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<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("EndedAt")
.HasColumnType("timestamp with time zone");
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.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
}
}
}