Dungeon builder patch

This commit is contained in:
dingo
2025-12-28 08:37:04 -05:00
parent 3d4607e591
commit 0589ecb783
+12 -4
View File
@@ -207,14 +207,22 @@
const palette = document.getElementById('tilePalette'); const palette = document.getElementById('tilePalette');
const imgUrl = `${cdnBaseUrl}/${sheet.CdnPath}`; const imgUrl = `${cdnBaseUrl}/${sheet.CdnPath}`;
let html = `<div class="grid gap-1" style="grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));">`; // Calculate scale to fit tiles in 32x32 display boxes
const displaySize = 32;
const scale = displaySize / sheet.TileWidth;
const scaledSheetW = sheet.SheetWidth * scale;
const scaledSheetH = sheet.SheetHeight * scale;
let html = `<div class="grid gap-1" style="grid-template-columns: repeat(auto-fill, minmax(${displaySize}px, 1fr));">`;
for (const tile of sheet.Tiles) { for (const tile of sheet.Tiles) {
if (currentFilter !== 'all' && tile.Type !== TileType[currentFilter]) continue; if (currentFilter !== 'all' && tile.Type !== TileType[currentFilter]) continue;
const col = tile.FrameIndex % sheet.Columns; const col = tile.FrameIndex % sheet.Columns;
const row = Math.floor(tile.FrameIndex / sheet.Columns); const row = Math.floor(tile.FrameIndex / sheet.Columns);
const bgPos = `-${col * sheet.TileWidth}px -${row * sheet.TileHeight}px`; // Scale the position too
const bgPosX = col * sheet.TileWidth * scale;
const bgPosY = row * sheet.TileHeight * scale;
const isSelected = selectedTile && selectedTile.id === tile.Id; const isSelected = selectedTile && selectedTile.id === tile.Id;
const borderClass = isSelected ? 'border-yellow-400 border-2' : 'border-gray-600 border'; const borderClass = isSelected ? 'border-yellow-400 border-2' : 'border-gray-600 border';
@@ -222,7 +230,7 @@
html += `<div class="cursor-pointer ${borderClass} hover:border-yellow-300 transition-all" html += `<div class="cursor-pointer ${borderClass} hover:border-yellow-300 transition-all"
onclick="selectTile(${tile.Id}, ${sheet.Id})" onclick="selectTile(${tile.Id}, ${sheet.Id})"
title="${tile.Name || 'Tile ' + tile.FrameIndex} (${TileTypeName[tile.Type]})" title="${tile.Name || 'Tile ' + tile.FrameIndex} (${TileTypeName[tile.Type]})"
style="width: 32px; height: 32px; background-image: url('${imgUrl}'); background-position: ${bgPos}; background-size: ${sheet.SheetWidth}px ${sheet.SheetHeight}px;"> style="width: ${displaySize}px; height: ${displaySize}px; background-image: url('${imgUrl}'); background-position: -${bgPosX}px -${bgPosY}px; background-size: ${scaledSheetW}px ${scaledSheetH}px; image-rendering: pixelated;">
</div>`; </div>`;
} }
@@ -288,7 +296,7 @@
} }
html += `<div class="border border-gray-700/50 hover:border-blue-400 cursor-crosshair" html += `<div class="border border-gray-700/50 hover:border-blue-400 cursor-crosshair"
style="width: ${TILE_DISPLAY_SIZE}px; height: ${TILE_DISPLAY_SIZE}px; ${bgStyle}" style="width: ${TILE_DISPLAY_SIZE}px; height: ${TILE_DISPLAY_SIZE}px; ${bgStyle} image-rendering: pixelated;"
data-x="${x}" data-y="${y}" data-x="${x}" data-y="${y}"
onmousedown="handleTileClick(event, ${x}, ${y})" onmousedown="handleTileClick(event, ${x}, ${y})"
onmouseenter="handleTileHover(event, ${x}, ${y})" onmouseenter="handleTileHover(event, ${x}, ${y})"