Feature: tile height variation + stalagmite bottoms + live content refresh

## Tile height variation (fix)
Tile tops now visibly vary (0.8–1.0) from a fixed bottom at world Y=0.
Previously the top was fixed and the variation was only visible underneath.
Heights are seeded by tile coordinate so they're deterministic per board.
Unit y_offsets and highlight positions update to match per-tile height.

## Stalagmite tile bottoms
Server: new TileBottomModel entity + migration (catalog.tile_bottom_models),
content.tile_bottoms handler returns all active CDN URLs.
Admin: "Tile Bottom Models" section in the Tile Model Manager page —
  add/toggle active/delete entries with CDN picker.
Client: ContentCache fetches + disk-caches the URL pool; _try_load_tile_model
  picks a random URL and attaches it flipped below the tile model as a
  stalagmite using the existing _fit_model_to_tile scale logic.

## Live content refresh
ContentCache schedules start_sync() every 5 minutes after sync_complete so
card definitions, tile models, and bottom models are refreshed in the
background without restarting the 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:
dingo
2026-03-16 15:05:48 -04:00
co-authored by Claude Happy
parent 977d150a46
commit 51f3ee23d4
9 changed files with 419 additions and 20 deletions
@@ -75,6 +75,59 @@ else
}
}
<!-- ── Tile Bottoms (stalagmite undersides) ── -->
<div class="card shadow-sm mb-4">
<div class="card-header fw-medium d-flex justify-content-between align-items-center">
<span>Tile Bottom Models <span class="text-muted small fw-normal">(stalagmites, randomly selected per tile)</span></span>
<button class="btn btn-sm btn-outline-primary" @onclick="OpenBottomPickerAsync">
<i class="bi bi-plus me-1"></i>Add
</button>
</div>
<div class="card-body p-0">
@if (_bottomModels.Count == 0)
{
<div class="text-muted text-center py-3 small">No bottom models yet — upload GLBs and add them here.</div>
}
else
{
<table class="table table-sm table-hover mb-0">
<thead class="table-light">
<tr>
<th>Model</th>
<th style="width:80px">Active</th>
<th style="width:100px"></th>
</tr>
</thead>
<tbody>
@foreach (var bottom in _bottomModels)
{
var b = bottom;
<tr>
<td class="align-middle font-monospace small text-break">
@(b.CdnKey.Contains('/') ? b.CdnKey[(b.CdnKey.LastIndexOf('/') + 1)..] : b.CdnKey)
</td>
<td class="align-middle">
<input type="checkbox" class="form-check-input" checked="@b.IsActive"
@onchange="e => ToggleBottomActiveAsync(b, (bool)e.Value!)" />
</td>
<td class="align-middle text-end pe-2">
<button class="btn btn-sm btn-outline-info py-0 me-1"
@onclick="() => _previewUrl = b.PublicUrl" title="Preview">
<i class="bi bi-box"></i>
</button>
<button class="btn btn-sm btn-outline-danger py-0"
@onclick="() => DeleteBottomAsync(b)" title="Delete">
<i class="bi bi-trash"></i>
</button>
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
<!-- Assign / Picker Modal -->
@if (_pickerOpen)
{
@@ -198,6 +251,63 @@ else
</div>
}
<!-- Bottom Model Picker Modal -->
@if (_bottomPickerOpen)
{
<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">Add Tile Bottom Model</h5>
<button type="button" class="btn-close" @onclick="() => _bottomPickerOpen = false"></button>
</div>
<div class="modal-body">
<input @bind="_bottomPickerSearch" @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
{
<div class="row g-3">
@foreach (var model in BottomPickerFiltered())
{
var m = model;
var isSel = _bottomPickerSelected == m.Key;
<div class="col-md-4">
<div class="card h-100 @(isSel ? "border-primary" : "")"
style="cursor:pointer" @onclick="() => _bottomPickerSelected = m.Key">
<div class="card-body py-2 px-3">
<div class="font-monospace small text-break">@m.ShortName</div>
</div>
@if (isSel)
{
<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="() => _bottomPickerOpen = false">Cancel</button>
<button class="btn btn-primary"
disabled="@(_bottomPickerSelected is null || _saving)"
@onclick="SaveBottomAsync">
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
Add
</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 {
@@ -236,6 +346,12 @@ else
("Gateways", new[] { Affinity.GatewayLake, Affinity.GatewayHill, Affinity.GatewayForest, Affinity.GatewayField }),
};
// Tile bottom models
private List<TileBottomModel> _bottomModels = new();
private bool _bottomPickerOpen;
private string _bottomPickerSearch = "";
private string? _bottomPickerSelected;
// ── Lifecycle ─────────────────────────────────────────────────────────────
protected override async Task OnInitializedAsync() => await LoadAsync();
@@ -245,6 +361,7 @@ else
_loading = true;
var all = await Db.TileModelBindings.ToListAsync();
_bindings = all.ToDictionary(b => (b.Affinity, b.Shape));
_bottomModels = await Db.TileBottomModels.OrderBy(m => m.CdnKey).ToListAsync();
_loading = false;
}
@@ -378,6 +495,68 @@ else
_isError = false;
}
// ── Tile Bottom Models ────────────────────────────────────────────────────
private async Task OpenBottomPickerAsync()
{
_bottomPickerSelected = null;
_bottomPickerSearch = "";
_bottomPickerOpen = true;
_pickerLoading = true;
await LoadPickerModelsAsync();
}
private IEnumerable<ModelItem> BottomPickerFiltered()
{
if (string.IsNullOrWhiteSpace(_bottomPickerSearch))
return _pickerModels;
return _pickerModels.Where(m =>
m.Key.Contains(_bottomPickerSearch, StringComparison.OrdinalIgnoreCase));
}
private async Task SaveBottomAsync()
{
if (_bottomPickerSelected is null) return;
_saving = true;
try
{
var options = CdnOptionsAccessor.Value;
var publicUrl = BuildPublicUrl(options, _bottomPickerSelected);
var model = new TileBottomModel
{
CdnKey = _bottomPickerSelected,
PublicUrl = publicUrl,
IsActive = true,
UpdatedAt = DateTimeOffset.UtcNow,
};
Db.TileBottomModels.Add(model);
await Db.SaveChangesAsync();
_bottomModels.Add(model);
_bottomModels = _bottomModels.OrderBy(m => m.CdnKey).ToList();
_bottomPickerOpen = false;
}
catch (Exception ex)
{
_message = $"Save failed: {ex.Message}";
_isError = true;
}
finally { _saving = false; }
}
private async Task ToggleBottomActiveAsync(TileBottomModel model, bool active)
{
model.IsActive = active;
model.UpdatedAt = DateTimeOffset.UtcNow;
await Db.SaveChangesAsync();
}
private async Task DeleteBottomAsync(TileBottomModel model)
{
Db.TileBottomModels.Remove(model);
await Db.SaveChangesAsync();
_bottomModels.Remove(model);
}
// ── Helpers ───────────────────────────────────────────────────────────────
private RenderFragment ModelCell(TileModelBinding? binding, Affinity affinity, TileShape shape) => __builder =>
@@ -19,6 +19,9 @@ public sealed record GetCardDefinitionRequest(Guid Id);
/// <summary>Fetch all tile model bindings (affinity × shape → CDN URL).</summary>
public sealed record GetTileModelsRequest;
/// <summary>Fetch all active tile bottom (stalagmite) model URLs.</summary>
public sealed record GetTileBottomsRequest;
// ── Response / DTO types (server → client) ────────────────────────────────────
public sealed record SyncCardDefinitionsResponse(
@@ -32,6 +35,8 @@ public sealed record GetCardDefinitionResponse(CardDefinitionDto? Card);
public sealed record GetTileModelsResponse(IEnumerable<TileModelDto> Bindings);
public sealed record GetTileBottomsResponse(IEnumerable<string> Urls);
public sealed record TileModelDto(
string Affinity,
string Shape,
@@ -0,0 +1,39 @@
namespace SOR.Content.Handlers;
using Microsoft.EntityFrameworkCore;
using SOR.Database.Contexts;
using SOR.Networking.Abstractions.Messaging;
using SOR.Networking.Abstractions.Transport;
using SOR.Shared.Networking;
/// <summary>
/// content.tile_bottoms — returns CDN URLs for all active tile-bottom (stalagmite) models.
/// The client randomly picks from this list when attaching an underside mesh to a tile.
/// </summary>
internal sealed class ContentGetTileBottomsHandler : IMessageHandler
{
private readonly IMessageSerializer _serializer;
private readonly CatalogDbContext _catalogDb;
public ContentGetTileBottomsHandler(IMessageSerializer serializer, CatalogDbContext catalogDb)
{
_serializer = serializer;
_catalogDb = catalogDb;
}
public string MessageType => "content.tile_bottoms";
public async Task<IServerMessage?> HandleAsync(
IClientMessage message,
AuthenticatedConnection connection,
CancellationToken ct)
{
var urls = await _catalogDb.TileBottomModels
.Where(m => m.IsActive)
.Select(m => m.PublicUrl)
.ToListAsync(ct);
return ServerMessage.Reply("content.tile_bottoms.ack", message.Seq,
new GetTileBottomsResponse(urls));
}
}
@@ -22,6 +22,7 @@ public static class ServiceRegistration
services.AddTransient<IMessageHandler, ContentGetCardSetsHandler>();
services.AddTransient<IMessageHandler, ContentGetCardDefinitionHandler>();
services.AddTransient<IMessageHandler, ContentGetTileModelsHandler>();
services.AddTransient<IMessageHandler, ContentGetTileBottomsHandler>();
services.AddTransient<IMessageHandler, ContentGetAudioConfigHandler>();
return services;
@@ -27,7 +27,8 @@ public sealed class CatalogDbContext : DbContext
public DbSet<CardAnimationBinding> AnimationBindings => Set<CardAnimationBinding>();
public DbSet<CdnUploadRecord> CdnUploadRecords => Set<CdnUploadRecord>();
public DbSet<TileModelBinding> TileModelBindings => Set<TileModelBinding>();
public DbSet<GameAudioConfig> AudioConfigs => Set<GameAudioConfig>();
public DbSet<TileBottomModel> TileBottomModels => Set<TileBottomModel>();
public DbSet<GameAudioConfig> AudioConfigs => Set<GameAudioConfig>();
protected override void OnModelCreating(ModelBuilder builder)
{
@@ -142,6 +143,15 @@ public sealed class CatalogDbContext : DbContext
e.HasIndex(t => new { t.Affinity, t.Shape }).IsUnique();
});
builder.Entity<TileBottomModel>(e =>
{
e.ToTable("tile_bottom_models");
e.HasKey(t => t.Id);
e.Property(t => t.CdnKey).IsRequired();
e.Property(t => t.PublicUrl).IsRequired();
e.HasIndex(t => t.IsActive);
});
builder.Entity<GameAudioConfig>(e =>
{
e.ToTable("game_audio_configs");
@@ -0,0 +1,21 @@
namespace SOR.Database.Entities.Catalog;
/// <summary>
/// A stalagmite / underside 3D model that the client attaches below tile models.
/// The client randomly picks from all active records each time a tile loads.
/// </summary>
public sealed class TileBottomModel
{
public Guid Id { get; set; } = Guid.NewGuid();
/// <summary>S3 object key, e.g. "models/tiles/bottoms/stalactite_01.glb".</summary>
public string CdnKey { get; set; } = string.Empty;
/// <summary>Publicly accessible CDN URL for the model file.</summary>
public string PublicUrl { get; set; } = string.Empty;
/// <summary>When false the model is excluded from the pool returned to clients.</summary>
public bool IsActive { get; set; } = true;
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
}
@@ -0,0 +1,45 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SOR.Database.Migrations.Catalog
{
/// <inheritdoc />
public partial class AddTileBottomModels : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "tile_bottom_models",
schema: "catalog",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
CdnKey = table.Column<string>(type: "text", nullable: false),
PublicUrl = table.Column<string>(type: "text", nullable: false),
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
},
constraints: table =>
{
table.PrimaryKey("PK_tile_bottom_models", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_tile_bottom_models_IsActive",
schema: "catalog",
table: "tile_bottom_models",
column: "IsActive");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "tile_bottom_models",
schema: "catalog");
}
}
}