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 = ''; let html = '';
filtered.forEach(t => { filtered.forEach(t => {
// Parse TilesJson to get sheetId and frameIndex // frameIndex is pre-extracted by the server
let frameIndex = 0; const frameIndex = t.frameIndex || 0;
try {
const tiles = JSON.parse(t.tilesJson || '[]');
if (tiles.length > 0) {
frameIndex = tiles[0].frameIndex;
}
} catch {}
const col = frameIndex % sheet.cols; const col = frameIndex % sheet.cols;
const row = Math.floor(frameIndex / sheet.cols); const row = Math.floor(frameIndex / sheet.cols);
@@ -27,31 +27,36 @@ public class RoomEditModel : AdminPageModel
/// <summary> /// <summary>
/// TileTemplates serialized as JSON for JavaScript consumption. /// TileTemplates serialized as JSON for JavaScript consumption.
/// Grouped by sheetId for efficient lookup. /// Includes extracted sheetId and frameIndex for direct use.
/// </summary> /// </summary>
public string TileTemplatesJson => JsonSerializer.Serialize( public string TileTemplatesJson => JsonSerializer.Serialize(
TileTemplates.Select(t => new { TileTemplates.Select(t => {
id = t.Id, var (sheetId, frameIndex) = ExtractTileInfo(t.TilesJson);
name = t.Name, return new {
category = t.Category.ToString(), id = t.Id,
tags = t.Tags, name = t.Name,
isWalkable = t.IsWalkable, category = t.Category.ToString(),
blocksMovement = t.BlocksMovement, tags = t.Tags,
tilesJson = t.TilesJson, isWalkable = t.IsWalkable,
weight = t.Weight, blocksMovement = t.BlocksMovement,
sheetId = ExtractSheetId(t.TilesJson) weight = t.Weight,
sheetId = sheetId,
frameIndex = frameIndex
};
}).Where(t => t.sheetId.HasValue) }).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 try
{ {
var tiles = JsonSerializer.Deserialize<List<TilePlacement>>(tilesJson); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
return tiles?.FirstOrDefault()?.SheetId; 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 private class TilePlacement