Fixing Room Templates

This commit is contained in:
dingo
2026-01-10 09:22:14 -05:00
parent 8c756cc191
commit b987015e67
4 changed files with 44 additions and 9 deletions
+20 -2
View File
@@ -834,6 +834,7 @@ public class DungeonGeneratorV3
X = spawn.X,
Y = spawn.Y,
MobType = mobType,
MobDefinitionId = spawn.MobDefinitionId,
RoomIndex = roomIndex,
IsAlive = true
});
@@ -1079,7 +1080,7 @@ public class DungeonGeneratorV3
{
try
{
var spawns = JsonSerializer.Deserialize<List<BuilderMobSpawn>>(template.MobSpawnsJson);
var spawns = JsonSerializer.Deserialize<List<BuilderMobSpawn>>(template.MobSpawnsJson, _jsonOptions);
if (spawns != null)
{
foreach (var spawn in spawns)
@@ -1089,6 +1090,7 @@ public class DungeonGeneratorV3
X = room.X + spawn.X,
Y = room.Y + spawn.Y,
Type = spawn.Type,
MobDefinitionId = spawn.MobDefinitionId,
Count = spawn.Count
});
}
@@ -1223,6 +1225,15 @@ public class DungeonGeneratorV3
if (x >= 0 && x < MapWidth && cy >= 0 && cy < MapHeight)
{
layout.Walkable[x, cy] = true;
// Clear tile so FillFloorTiles can place a floor tile here
// This handles walls that get carved through for corridors
layout.Tiles[x, cy] = 0;
// Remove any existing tile details at this position
layout.TileDetails.RemoveAll(t => t.X == x && t.Y == cy);
// Clear from placed templates tracking
_placedTemplates.Remove($"{x},{cy}");
}
}
}
@@ -1242,6 +1253,14 @@ public class DungeonGeneratorV3
if (cx >= 0 && cx < MapWidth && y >= 0 && y < MapHeight)
{
layout.Walkable[cx, y] = true;
// Clear tile so FillFloorTiles can place a floor tile here
layout.Tiles[cx, y] = 0;
// Remove any existing tile details at this position
layout.TileDetails.RemoveAll(t => t.X == cx && t.Y == y);
// Clear from placed templates tracking
_placedTemplates.Remove($"{cx},{y}");
}
}
}
@@ -2043,7 +2062,6 @@ public class ConnectionPoint
public int X { get; set; }
public int Y { get; set; }
public string Direction { get; set; } = "north";
public int Width { get; set; }
}
public class TemplateTilePlacement
+1
View File
@@ -6,6 +6,7 @@ public class DungeonMobSpawn
public int X { get; set; }
public int Y { get; set; }
public DungeonMobSpawnType MobType { get; set; }
public int? MobDefinitionId { get; set; } // Specific mob definition, or null for random selection
public int RoomIndex { get; set; }
public bool IsAlive { get; set; } = true;
}
+1
View File
@@ -61,5 +61,6 @@ public class RoomMobSpawn
public int X { get; set; }
public int Y { get; set; }
public string Type { get; set; } = "normal";
public int? MobDefinitionId { get; set; } // Specific mob, or null for random from pool
public int Count { get; set; } = 1;
}
@@ -361,8 +361,10 @@ function loadData() {
function buildGrid() {
const g = document.getElementById('editorGrid');
const cellW = sheet?.tw || 16;
const cellH = sheet?.th || 16;
// Scale factor for grid display (2x for better visibility)
const scale = 2;
const cellW = (sheet?.tw || 16) * scale;
const cellH = (sheet?.th || 16) * scale;
g.style.gridTemplateColumns = `repeat(${gw}, ${cellW}px)`;
g.innerHTML = '';
for (let y = 0; y < gh; y++) {
@@ -390,6 +392,9 @@ function render(x, y) {
if (!c) return;
const k = `${x},${y}`;
// Scale factor for display
const scale = 2;
// Check for floor or wall tile
const floor = floorData[k];
const wall = wallData[k];
@@ -397,8 +402,8 @@ function render(x, y) {
if (tile && sheet && tile.sheetId == sheet.id) {
const col = tile.frameIndex % sheet.cols, row = Math.floor(tile.frameIndex / sheet.cols);
c.style.background = `url('${cdnBase}/${sheet.cdn}') ${-col*sheet.tw}px ${-row*sheet.th}px no-repeat`;
c.style.backgroundSize = `${sheet.sw}px ${sheet.sh}px`;
c.style.background = `url('${cdnBase}/${sheet.cdn}') ${-col*sheet.tw*scale}px ${-row*sheet.th*scale}px no-repeat`;
c.style.backgroundSize = `${sheet.sw*scale}px ${sheet.sh*scale}px`;
} else if (tile) {
c.style.background = wall ? '#4a1a1a' : '#2d3748';
} else {
@@ -549,6 +554,11 @@ function setLayer(l) {
document.querySelectorAll('.mob-select-item').forEach(i => i.classList.remove('selected'));
document.getElementById('selectionInfo').textContent = 'Nothing';
document.getElementById('selectionDetails').textContent = '';
// Refresh templates when switching between floor/wall layers
if (l === 'floor' || l === 'wall') {
renderTemplates();
}
}
function loadTileTemplates() {
@@ -648,6 +658,11 @@ function renderTemplates(filterTags = []) {
return;
}
// Scale factor for palette display (2x for better visibility)
const scale = 2;
const displayW = sheet.tw * scale;
const displayH = sheet.th * scale;
let html = '';
filtered.forEach(t => {
// frameIndex is pre-extracted by the server
@@ -665,12 +680,12 @@ function renderTemplates(filterTags = []) {
data-name="${t.name}"
data-tags="${t.tags || ''}"
title="${t.name}${t.tags ? ' [' + t.tags + ']' : ''}"
style="width:${sheet.tw + 8}px; padding:4px;"
style="width:${displayW + 12}px; padding:6px;"
onclick="selectPaletteItem(this)">
<div style="width:${sheet.tw}px; height:${sheet.th}px; background:url('${cdnBase}/${sheet.cdn}') ${-col*sheet.tw}px ${-row*sheet.th}px no-repeat; background-size:${sheet.sw}px ${sheet.sh}px; position:relative;">
<div style="width:${displayW}px; height:${displayH}px; background:url('${cdnBase}/${sheet.cdn}') ${-col*sheet.tw*scale}px ${-row*sheet.th*scale}px no-repeat; background-size:${sheet.sw*scale}px ${sheet.sh*scale}px; position:relative;">
<div class="walkable-badge ${t.isWalkable ? 'floor' : 'wall'}"></div>
</div>
<div class="template-info mt-1" style="width:${sheet.tw}px;">${t.name}</div>
<div class="template-info mt-1" style="width:${displayW}px;">${t.name}</div>
</div>`;
});