Feature: tile spacing gap + 2D placeholder textures
Visual changes (client): - 0.1 gap between all tiles (TILE_SPACING = 1.1) - Placeholder tiles (no 3D model) are now 0.5 height instead of random 0.8-1.0, making undecorated tiles visually distinct - Placeholder tiles load a 2D CDN texture via HTTP and apply it as the albedo on the BoxMesh (same affinity-per-shape lookup as 3D models) - Placeholder tiles also attach a stalagmite bottom model, matching the look of fully-decorated tiles Server: - TileModelBinding.TexturePublicUrl (nullable text) added to entity, migration 20260317000001_AddTileTexture applied to DB - TileModelDto extended with TexturePublicUrl - ContentGetTileModelsHandler includes TexturePublicUrl in response Admin (/content/tile-models): - New "Square Texture" and "Hex Texture" columns in the bindings table - Texture picker modal browses the CDN textures/ prefix and shows image thumbnails; select + assign writes TexturePublicUrl to the binding - Texture can be assigned without a 3D model (creates a binding row with empty model fields) ContentCache: - Caches texturePublicUrl alongside modelPublicUrl from tile_models response - New get_tile_texture_url(affinity, shape) → String accessor 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:
@@ -49,7 +49,9 @@ else
|
||||
<tr>
|
||||
<th style="width:160px">Affinity</th>
|
||||
<th>Square Model</th>
|
||||
<th>Square Texture</th>
|
||||
<th>Hex Model</th>
|
||||
<th>Hex Texture</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -63,9 +65,15 @@ else
|
||||
<td class="align-middle">
|
||||
@ModelCell(squareBinding, affinity, TileShape.Square)
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
@TextureCell(squareBinding, affinity, TileShape.Square)
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
@ModelCell(hexBinding, affinity, TileShape.Hex)
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
@TextureCell(hexBinding, affinity, TileShape.Hex)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
@@ -308,6 +316,75 @@ else
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Texture Picker Modal -->
|
||||
@if (_texPickerOpen)
|
||||
{
|
||||
<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 Texture — <span class="text-primary">@_texPickerAffinity</span>
|
||||
<span class="badge bg-secondary ms-2">@_texPickerShape</span>
|
||||
</h5>
|
||||
<button type="button" class="btn-close" @onclick="CloseTexPicker"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input @bind="_texPickerSearch" @bind:event="oninput"
|
||||
class="form-control form-control-sm font-monospace mb-3"
|
||||
placeholder="Filter textures…" />
|
||||
@if (_texPickerLoading)
|
||||
{
|
||||
<div class="text-muted text-center py-4">
|
||||
<span class="spinner-border spinner-border-sm me-2"></span>Loading CDN textures…
|
||||
</div>
|
||||
}
|
||||
else if (!_texPickerItems.Any())
|
||||
{
|
||||
<div class="text-muted text-center py-4">
|
||||
No image files found in the <code>textures/</code> prefix.
|
||||
Upload textures via the CDN Browser first.
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row g-3">
|
||||
@foreach (var tex in TexPickerFiltered())
|
||||
{
|
||||
var t = tex;
|
||||
var isSel = _texPickerSelected == t.PublicUrl;
|
||||
<div class="col-md-3">
|
||||
<div class="card h-100 @(isSel ? "border-primary" : "")"
|
||||
style="cursor:pointer" @onclick="() => _texPickerSelected = t.PublicUrl">
|
||||
<img src="@t.PublicUrl" alt="@t.ShortName"
|
||||
style="height:120px;object-fit:cover;border-radius:4px 4px 0 0" />
|
||||
<div class="card-body py-1 px-2">
|
||||
<div class="font-monospace small text-break">@t.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="CloseTexPicker">Cancel</button>
|
||||
<button class="btn btn-primary"
|
||||
disabled="@(_texPickerSelected is null || _saving)"
|
||||
@onclick="SaveTextureAsync">
|
||||
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
||||
Assign Selected
|
||||
</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 {
|
||||
@@ -346,6 +423,15 @@ else
|
||||
("Gateways", new[] { Affinity.GatewayLake, Affinity.GatewayHill, Affinity.GatewayForest, Affinity.GatewayField }),
|
||||
};
|
||||
|
||||
// Texture picker state
|
||||
private bool _texPickerOpen;
|
||||
private bool _texPickerLoading;
|
||||
private Affinity _texPickerAffinity;
|
||||
private TileShape _texPickerShape;
|
||||
private string _texPickerSearch = "";
|
||||
private string? _texPickerSelected;
|
||||
private List<TexItem> _texPickerItems = new();
|
||||
|
||||
// Tile bottom models
|
||||
private List<TileBottomModel> _bottomModels = new();
|
||||
private bool _bottomPickerOpen;
|
||||
@@ -495,6 +581,145 @@ else
|
||||
_isError = false;
|
||||
}
|
||||
|
||||
// ── Texture Picker ────────────────────────────────────────────────────────
|
||||
|
||||
private async Task OpenTexPickerAsync(Affinity affinity, TileShape shape)
|
||||
{
|
||||
_texPickerAffinity = affinity;
|
||||
_texPickerShape = shape;
|
||||
_texPickerSelected = _bindings.TryGetValue((affinity, shape), out var b) ? b.TexturePublicUrl : null;
|
||||
_texPickerSearch = "";
|
||||
_texPickerOpen = true;
|
||||
_texPickerLoading = true;
|
||||
await LoadTexPickerItemsAsync();
|
||||
}
|
||||
|
||||
private async Task LoadTexPickerItemsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var options = CdnOptionsAccessor.Value;
|
||||
var request = new ListObjectsV2Request
|
||||
{
|
||||
BucketName = options.BucketName,
|
||||
Prefix = "textures/",
|
||||
MaxKeys = 1000,
|
||||
};
|
||||
var response = await S3.ListObjectsV2Async(request);
|
||||
_texPickerItems = response.S3Objects
|
||||
.Where(o => !o.Key.EndsWith('/') && IsImageKey(o.Key))
|
||||
.Select(o => new TexItem
|
||||
{
|
||||
Key = o.Key,
|
||||
ShortName = o.Key.Contains('/') ? o.Key[(o.Key.LastIndexOf('/') + 1)..] : o.Key,
|
||||
PublicUrl = BuildPublicUrl(options, o.Key),
|
||||
})
|
||||
.OrderBy(t => t.Key)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_message = $"Failed to load CDN textures: {ex.Message}";
|
||||
_isError = true;
|
||||
}
|
||||
finally { _texPickerLoading = false; }
|
||||
}
|
||||
|
||||
private IEnumerable<TexItem> TexPickerFiltered() =>
|
||||
string.IsNullOrWhiteSpace(_texPickerSearch)
|
||||
? _texPickerItems
|
||||
: _texPickerItems.Where(t => t.Key.Contains(_texPickerSearch, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
private void CloseTexPicker()
|
||||
{
|
||||
_texPickerOpen = false;
|
||||
_texPickerItems = new();
|
||||
_texPickerSelected = null;
|
||||
}
|
||||
|
||||
private async Task SaveTextureAsync()
|
||||
{
|
||||
if (_texPickerSelected is null) return;
|
||||
_saving = true;
|
||||
try
|
||||
{
|
||||
var binding = await Db.TileModelBindings
|
||||
.FirstOrDefaultAsync(b => b.Affinity == _texPickerAffinity && b.Shape == _texPickerShape);
|
||||
|
||||
if (binding is null)
|
||||
{
|
||||
// Create a texture-only binding (no 3D model yet).
|
||||
binding = new TileModelBinding
|
||||
{
|
||||
Affinity = _texPickerAffinity,
|
||||
Shape = _texPickerShape,
|
||||
ModelCdnKey = "",
|
||||
ModelPublicUrl = "",
|
||||
};
|
||||
Db.TileModelBindings.Add(binding);
|
||||
}
|
||||
|
||||
binding.TexturePublicUrl = _texPickerSelected;
|
||||
binding.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await Db.SaveChangesAsync();
|
||||
|
||||
_bindings[(_texPickerAffinity, _texPickerShape)] = binding;
|
||||
_message = $"Texture assigned to {_texPickerAffinity} / {_texPickerShape}.";
|
||||
_isError = false;
|
||||
CloseTexPicker();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_message = $"Save failed: {ex.Message}";
|
||||
_isError = true;
|
||||
}
|
||||
finally { _saving = false; }
|
||||
}
|
||||
|
||||
private async Task ClearTextureAsync(Affinity affinity, TileShape shape)
|
||||
{
|
||||
var binding = await Db.TileModelBindings
|
||||
.FirstOrDefaultAsync(b => b.Affinity == affinity && b.Shape == shape);
|
||||
if (binding is null) return;
|
||||
|
||||
binding.TexturePublicUrl = null;
|
||||
binding.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await Db.SaveChangesAsync();
|
||||
_bindings[(affinity, shape)] = binding;
|
||||
_message = $"Texture cleared for {affinity} / {shape}.";
|
||||
_isError = false;
|
||||
}
|
||||
|
||||
private RenderFragment TextureCell(TileModelBinding? binding, Affinity affinity, TileShape shape) => __builder =>
|
||||
{
|
||||
var url = binding?.TexturePublicUrl;
|
||||
if (url is not null)
|
||||
{
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<img src="@url" alt="texture" style="height:40px;width:40px;object-fit:cover;border-radius:4px" />
|
||||
<button class="btn btn-sm btn-outline-warning py-0"
|
||||
@onclick="() => OpenTexPickerAsync(affinity, shape)"
|
||||
title="Change texture"><i class="bi bi-arrow-repeat"></i></button>
|
||||
<button class="btn btn-sm btn-outline-danger py-0"
|
||||
@onclick="() => ClearTextureAsync(affinity, shape)"
|
||||
title="Remove texture"><i class="bi bi-x"></i></button>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-secondary"
|
||||
@onclick="() => OpenTexPickerAsync(affinity, shape)">
|
||||
<i class="bi bi-image me-1"></i>Assign
|
||||
</button>
|
||||
}
|
||||
};
|
||||
|
||||
private static bool IsImageKey(string key) =>
|
||||
key.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) ||
|
||||
key.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) ||
|
||||
key.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||
|
||||
key.EndsWith(".webp", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// ── Tile Bottom Models ────────────────────────────────────────────────────
|
||||
|
||||
private async Task OpenBottomPickerAsync()
|
||||
@@ -608,4 +833,11 @@ else
|
||||
public string ShortName { get; init; } = "";
|
||||
public string PublicUrl { get; init; } = "";
|
||||
}
|
||||
|
||||
private sealed class TexItem
|
||||
{
|
||||
public string Key { get; init; } = "";
|
||||
public string ShortName { get; init; } = "";
|
||||
public string PublicUrl { get; init; } = "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user