builder p4

This commit is contained in:
dingo
2026-01-31 20:55:26 -05:00
parent e941ddc421
commit 33361b6cf5
2 changed files with 80 additions and 0 deletions
+76
View File
@@ -142,6 +142,23 @@
@if (Model.Sheet.Id > 0)
{
<div class="card p-4 md:p-6 mt-4 md:mt-6">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<h3 class="text-lg font-semibold text-white">Define Tiles (Full Sheet)</h3>
<p class="text-gray-400 text-sm mt-1">Click any frame to create or edit its Tile Definition.</p>
</div>
<div class="flex gap-2">
<input type="number" id="frameJumpGrid" class="input text-sm w-28" min="0" placeholder="Frame #" />
<button type="button" class="btn btn-secondary text-sm" onclick="openTileEditorFromGrid()">Edit Frame</button>
</div>
</div>
<div class="mt-4 overflow-auto bg-gray-900 rounded p-2" style="max-height: 50vh;">
<div id="tileDefGrid" class="grid gap-1"></div>
</div>
<div class="text-xs text-gray-500 mt-2">Green border = defined. Red border = not defined.</div>
</div>
<div class="card p-4 md:p-6 mt-4 md:mt-6">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
@@ -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();
}
</script>
}
@@ -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<TileDefinition> TileDefinitions { get; set; } = new();
public List<TileDefinitionRow> TileDefinitionRows { get; set; } = new();
public string TileDefinitionsJson => JsonSerializer.Serialize(
TileDefinitionRows.Select(r => new { id = r.Id, frameIndex = r.FrameIndex })
);
public List<ClientAsset> CdnImages { get; set; } = new();
public string CdnBaseUrl { get; set; } = "";