Dungeon Builder. CONT..

This commit is contained in:
dingo
2026-01-04 14:01:36 -05:00
parent 03353fa338
commit 89e6684288
2 changed files with 19 additions and 14 deletions
@@ -15,8 +15,6 @@
border-radius: 4px;
}
.editor-cell {
width: 32px;
height: 32px;
background: #0f0f1a;
cursor: crosshair;
position: relative;
@@ -274,12 +272,17 @@ function loadData() {
function buildGrid() {
const g = document.getElementById('editorGrid');
g.style.gridTemplateColumns = `repeat(${gw}, 32px)`;
// Use sheet tile dimensions if available, fallback to 32px
const cellW = sheet?.tw || 32;
const cellH = sheet?.th || 32;
g.style.gridTemplateColumns = `repeat(${gw}, ${cellW}px)`;
g.innerHTML = '';
for (let y = 0; y < gh; y++) {
for (let x = 0; x < gw; x++) {
const c = document.createElement('div');
c.className = 'editor-cell';
c.style.width = cellW + 'px';
c.style.height = cellH + 'px';
c.dataset.x = x; c.dataset.y = y;
c.onmousedown = e => { mouseDown = true; paint(x, y); };
c.onmouseenter = () => { document.getElementById('cursorPos').textContent = `(${x}, ${y})`; if (mouseDown) paint(x, y); };
@@ -381,6 +384,10 @@ function loadTilePalette() {
const opt = document.getElementById('tileSheetSelect').selectedOptions[0];
if (!opt?.value) { sheet = null; document.getElementById('tilePalette').innerHTML = '<div class="text-gray-500 text-xs p-2">Select a sheet</div>'; return; }
sheet = { id: +opt.value, cdn: opt.dataset.cdn, cols: +opt.dataset.cols, tw: +opt.dataset.tw, th: +opt.dataset.th, sw: +opt.dataset.sw, sh: +opt.dataset.sh };
// Rebuild grid with correct tile dimensions
buildGrid();
const total = sheet.cols * Math.ceil(sheet.sh / sheet.th);
let html = '';
for (let i = 0; i < total; i++) {
@@ -390,7 +397,6 @@ function loadTilePalette() {
onclick="selectPaletteItem(this)"></div>`;
}
document.getElementById('tilePalette').innerHTML = html;
for (let y = 0; y < gh; y++) for (let x = 0; x < gw; x++) render(x, y);
}
function selectPaletteItem(el) {
@@ -16,8 +16,6 @@
border-radius: 4px;
}
.tile-cell {
width: 32px;
height: 32px;
background: #0f0f1a;
cursor: crosshair;
position: relative;
@@ -307,13 +305,18 @@ function loadExisting() {
function buildTemplateGrid() {
const grid = document.getElementById('templateGrid');
grid.style.gridTemplateColumns = `repeat(${tw}, 32px)`;
// Use sheet tile dimensions if available, fallback to 32px
const cellW = sheet?.tw || 32;
const cellH = sheet?.th || 32;
grid.style.gridTemplateColumns = `repeat(${tw}, ${cellW}px)`;
grid.innerHTML = '';
for (let y = 0; y < th; y++) {
for (let x = 0; x < tw; x++) {
const cell = document.createElement('div');
cell.className = 'tile-cell';
cell.style.width = cellW + 'px';
cell.style.height = cellH + 'px';
cell.dataset.x = x;
cell.dataset.y = y;
cell.onclick = () => paintCell(x, y);
@@ -374,6 +377,9 @@ function loadSheet() {
sh: +opt.dataset.sh
};
// Rebuild template grid with correct tile dimensions
buildTemplateGrid();
const total = sheet.cols * Math.ceil(sheet.sh / sheet.th);
let html = '';
for (let i = 0; i < total; i++) {
@@ -385,13 +391,6 @@ function loadSheet() {
background-size: ${sheet.sw}px ${sheet.sh}px;"></div>`;
}
document.getElementById('palette').innerHTML = html;
// Re-render template with new sheet
for (let y = 0; y < th; y++) {
for (let x = 0; x < tw; x++) {
renderCell(x, y);
}
}
}
function selectTile(frameIndex) {