admin portal
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user