@@ -288,5 +305,64 @@
}
window.location.href = `/admin/tilemaps/tiles/edit?sheetId=@Model.Sheet.Id&frameIndex=${frame}`;
}
+
+ function openTileEditorFromGrid() {
+ const frame = document.getElementById('frameJumpGrid').value;
+ if (frame === '') {
+ alert('Enter a frame index.');
+ return;
+ }
+ window.location.href = `/admin/tilemaps/tiles/edit?sheetId=@Model.Sheet.Id&frameIndex=${frame}`;
+ }
+
+ function buildTileDefGrid() {
+ const grid = document.getElementById('tileDefGrid');
+ if (!grid) return;
+
+ const cols = Math.floor(sheetWidth / tileWidth);
+ const rows = Math.floor(sheetHeight / tileHeight);
+ const total = cols * rows;
+ const cellSize = Math.min(48, Math.floor(600 / cols));
+ const defs = @Html.Raw(Model.TileDefinitionsJson);
+ const defMap = {};
+ defs.forEach(d => defMap[d.frameIndex] = d.id);
+
+ grid.style.gridTemplateColumns = `repeat(${cols}, ${cellSize}px)`;
+ grid.innerHTML = '';
+
+ for (let i = 0; i < total; i++) {
+ const canvas = document.createElement('canvas');
+ canvas.width = cellSize;
+ canvas.height = cellSize;
+ canvas.className = 'tile-cell';
+ canvas.style.borderColor = defMap[i] ? '#22c55e' : '#ef4444';
+ canvas.dataset.frame = i;
+ canvas.onclick = () => {
+ window.location.href = `/admin/tilemaps/tiles/edit?sheetId=@Model.Sheet.Id&frameIndex=${i}`;
+ };
+ grid.appendChild(canvas);
+ }
+
+ const img = document.getElementById('sheetPreview');
+ if (!img) return;
+ const imgEl = new Image();
+ imgEl.src = img.src;
+ imgEl.onload = () => {
+ const ctxs = grid.querySelectorAll('canvas');
+ ctxs.forEach(c => {
+ const frame = parseInt(c.dataset.frame);
+ const col = frame % cols;
+ const row = Math.floor(frame / cols);
+ const ctx = c.getContext('2d');
+ ctx.imageSmoothingEnabled = false;
+ ctx.clearRect(0, 0, cellSize, cellSize);
+ ctx.drawImage(imgEl, col * tileWidth, row * tileHeight, tileWidth, tileHeight, 0, 0, cellSize, cellSize);
+ });
+ };
+ }
+
+ if (@Model.Sheet.Id > 0) {
+ buildTileDefGrid();
+ }
}
diff --git a/Services/Admin/Pages/TileMaps/Edit.cshtml.cs b/Services/Admin/Pages/TileMaps/Edit.cshtml.cs
index 19ccb90..72aa5d6 100644
--- a/Services/Admin/Pages/TileMaps/Edit.cshtml.cs
+++ b/Services/Admin/Pages/TileMaps/Edit.cshtml.cs
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using DataServer.Data;
using DataServer.Data.Entities;
+using System.Text.Json;
namespace GameServices.Admin.Pages.TileMaps;
@@ -21,6 +22,9 @@ public class EditModel : AdminPageModel
public List TileDefinitions { get; set; } = new();
public List TileDefinitionRows { get; set; } = new();
+ public string TileDefinitionsJson => JsonSerializer.Serialize(
+ TileDefinitionRows.Select(r => new { id = r.Id, frameIndex = r.FrameIndex })
+ );
public List CdnImages { get; set; } = new();
public string CdnBaseUrl { get; set; } = "";