From b987015e679a8f971df3702ed899cda92c1be75f Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 10 Jan 2026 09:22:14 -0500 Subject: [PATCH] Fixing Room Templates --- Game/Dungeon/DungeonGeneratorV3.cs | 22 ++++++++++++-- Game/Dungeon/DungeonMobSpawn.cs | 1 + Game/Dungeon/DungeonRoomV2.cs | 1 + .../Pages/DungeonBuilder/RoomEdit.cshtml | 29 ++++++++++++++----- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Game/Dungeon/DungeonGeneratorV3.cs b/Game/Dungeon/DungeonGeneratorV3.cs index 38a7473..d674227 100644 --- a/Game/Dungeon/DungeonGeneratorV3.cs +++ b/Game/Dungeon/DungeonGeneratorV3.cs @@ -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>(template.MobSpawnsJson); + var spawns = JsonSerializer.Deserialize>(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 diff --git a/Game/Dungeon/DungeonMobSpawn.cs b/Game/Dungeon/DungeonMobSpawn.cs index 4379fe4..a621dcc 100644 --- a/Game/Dungeon/DungeonMobSpawn.cs +++ b/Game/Dungeon/DungeonMobSpawn.cs @@ -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; } diff --git a/Game/Dungeon/DungeonRoomV2.cs b/Game/Dungeon/DungeonRoomV2.cs index 8ea7aa0..e7ebe8e 100644 --- a/Game/Dungeon/DungeonRoomV2.cs +++ b/Game/Dungeon/DungeonRoomV2.cs @@ -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; } diff --git a/Services/Admin/Pages/DungeonBuilder/RoomEdit.cshtml b/Services/Admin/Pages/DungeonBuilder/RoomEdit.cshtml index 8192565..09cf6fb 100644 --- a/Services/Admin/Pages/DungeonBuilder/RoomEdit.cshtml +++ b/Services/Admin/Pages/DungeonBuilder/RoomEdit.cshtml @@ -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)"> -
+
-
${t.name}
+
${t.name}
`; });