From 33361b6cf521a367d51b13cc8c0951ac473c0780 Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 31 Jan 2026 20:55:26 -0500 Subject: [PATCH] builder p4 --- Services/Admin/Pages/TileMaps/Edit.cshtml | 76 ++++++++++++++++++++ Services/Admin/Pages/TileMaps/Edit.cshtml.cs | 4 ++ 2 files changed, 80 insertions(+) diff --git a/Services/Admin/Pages/TileMaps/Edit.cshtml b/Services/Admin/Pages/TileMaps/Edit.cshtml index 2e27644..2b8046f 100644 --- a/Services/Admin/Pages/TileMaps/Edit.cshtml +++ b/Services/Admin/Pages/TileMaps/Edit.cshtml @@ -142,6 +142,23 @@ @if (Model.Sheet.Id > 0) { +
+
+
+

Define Tiles (Full Sheet)

+

Click any frame to create or edit its Tile Definition.

+
+
+ + +
+
+
+
+
+
Green border = defined. Red border = not defined.
+
+
@@ -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; } = "";