admin portal

This commit is contained in:
dingo
2026-01-09 23:28:06 -05:00
parent ee8545b922
commit 8c756cc191
2 changed files with 23 additions and 24 deletions
@@ -650,14 +650,8 @@ function renderTemplates(filterTags = []) {
let html = '';
filtered.forEach(t => {
// Parse TilesJson to get sheetId and frameIndex
let frameIndex = 0;
try {
const tiles = JSON.parse(t.tilesJson || '[]');
if (tiles.length > 0) {
frameIndex = tiles[0].frameIndex;
}
} catch {}
// frameIndex is pre-extracted by the server
const frameIndex = t.frameIndex || 0;
const col = frameIndex % sheet.cols;
const row = Math.floor(frameIndex / sheet.cols);
@@ -27,31 +27,36 @@ public class RoomEditModel : AdminPageModel
/// <summary>
/// TileTemplates serialized as JSON for JavaScript consumption.
/// Grouped by sheetId for efficient lookup.
/// Includes extracted sheetId and frameIndex for direct use.
/// </summary>
public string TileTemplatesJson => JsonSerializer.Serialize(
TileTemplates.Select(t => new {
id = t.Id,
name = t.Name,
category = t.Category.ToString(),
tags = t.Tags,
isWalkable = t.IsWalkable,
blocksMovement = t.BlocksMovement,
tilesJson = t.TilesJson,
weight = t.Weight,
sheetId = ExtractSheetId(t.TilesJson)
TileTemplates.Select(t => {
var (sheetId, frameIndex) = ExtractTileInfo(t.TilesJson);
return new {
id = t.Id,
name = t.Name,
category = t.Category.ToString(),
tags = t.Tags,
isWalkable = t.IsWalkable,
blocksMovement = t.BlocksMovement,
weight = t.Weight,
sheetId = sheetId,
frameIndex = frameIndex
};
}).Where(t => t.sheetId.HasValue)
);
private static int? ExtractSheetId(string? tilesJson)
private static (int? sheetId, int frameIndex) ExtractTileInfo(string? tilesJson)
{
if (string.IsNullOrEmpty(tilesJson)) return null;
if (string.IsNullOrEmpty(tilesJson)) return (null, 0);
try
{
var tiles = JsonSerializer.Deserialize<List<TilePlacement>>(tilesJson);
return tiles?.FirstOrDefault()?.SheetId;
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
var tiles = JsonSerializer.Deserialize<List<TilePlacement>>(tilesJson, options);
var first = tiles?.FirstOrDefault();
return (first?.SheetId, first?.FrameIndex ?? 0);
}
catch { return null; }
catch { return (null, 0); }
}
private class TilePlacement