diff --git a/Game/Dungeon/DungeonSimulation.cs b/Game/Dungeon/DungeonSimulation.cs index 203ccd7..4281eb3 100644 --- a/Game/Dungeon/DungeonSimulation.cs +++ b/Game/Dungeon/DungeonSimulation.cs @@ -176,7 +176,19 @@ public class DungeonSimulation foreach (var mobSpawn in Layout.MobSpawns) { - var mobDef = SelectMobDefinition(mobSpawn.MobType, rng); + // Use specific mob if MobDefinitionId is set, otherwise select randomly + DungeonMobDefinition? mobDef = null; + if (mobSpawn.MobDefinitionId.HasValue) + { + _mobDefinitions.TryGetValue(mobSpawn.MobDefinitionId.Value, out mobDef); + } + + // Fall back to random selection if no specific mob or mob not found + if (mobDef == null) + { + mobDef = SelectMobDefinition(mobSpawn.MobType, rng); + } + if (mobDef == null) continue; // Use bracket-aware stat scaling diff --git a/Services/Admin/Pages/DungeonBuilder/RoomEdit.cshtml b/Services/Admin/Pages/DungeonBuilder/RoomEdit.cshtml index 09cf6fb..99f6dc6 100644 --- a/Services/Admin/Pages/DungeonBuilder/RoomEdit.cshtml +++ b/Services/Admin/Pages/DungeonBuilder/RoomEdit.cshtml @@ -298,7 +298,11 @@ const cdnBase = '@Model.CdnBaseUrl'; let gw = @Model.Room.Width, gh = @Model.Room.Height; let tool = 'paint', layer = 'floor'; -let sel = null, sheet = null; +let sel = null; +let currentSheetId = null; // Currently selected sheet for painting + +// All loaded sheets (by ID) for rendering tiles from any sheet +const loadedSheets = {}; // Data stores - keyed by "x,y" let floorData = {}; // Floor tiles (walkable) - { templateId, sheetId, frameIndex, isWalkable } @@ -313,7 +317,25 @@ let allTags = new Set(); let mouseDown = false; +// Pre-load all sheet data from the dropdown +function preloadSheets() { + document.querySelectorAll('#tileSheetSelect option').forEach(opt => { + if (opt.value) { + loadedSheets[+opt.value] = { + 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 + }; + } + }); +} + document.addEventListener('DOMContentLoaded', () => { + preloadSheets(); loadData(); buildGrid(); }); @@ -363,8 +385,23 @@ function buildGrid() { const g = document.getElementById('editorGrid'); // Scale factor for grid display (2x for better visibility) const scale = 2; - const cellW = (sheet?.tw || 16) * scale; - const cellH = (sheet?.th || 16) * scale; + + // Get tile size from current sheet or first available sheet or default + let tileW = 16, tileH = 16; + if (currentSheetId && loadedSheets[currentSheetId]) { + tileW = loadedSheets[currentSheetId].tw; + tileH = loadedSheets[currentSheetId].th; + } else { + // Use first available sheet dimensions + const firstSheet = Object.values(loadedSheets)[0]; + if (firstSheet) { + tileW = firstSheet.tw; + tileH = firstSheet.th; + } + } + + const cellW = tileW * scale; + const cellH = tileH * scale; g.style.gridTemplateColumns = `repeat(${gw}, ${cellW}px)`; g.innerHTML = ''; for (let y = 0; y < gh; y++) { @@ -400,10 +437,12 @@ function render(x, y) { const wall = wallData[k]; const tile = floor || wall; - 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*scale}px ${-row*sheet.th*scale}px no-repeat`; - c.style.backgroundSize = `${sheet.sw*scale}px ${sheet.sh*scale}px`; + if (tile && tile.sheetId && loadedSheets[tile.sheetId]) { + const tileSheet = loadedSheets[tile.sheetId]; + const col = tile.frameIndex % tileSheet.cols; + const row = Math.floor(tile.frameIndex / tileSheet.cols); + c.style.background = `url('${cdnBase}/${tileSheet.cdn}') ${-col*tileSheet.tw*scale}px ${-row*tileSheet.th*scale}px no-repeat`; + c.style.backgroundSize = `${tileSheet.sw*scale}px ${tileSheet.sh*scale}px`; } else if (tile) { c.style.background = wall ? '#4a1a1a' : '#2d3748'; } else { @@ -564,28 +603,17 @@ function setLayer(l) { function loadTileTemplates() { const opt = document.getElementById('tileSheetSelect').selectedOptions[0]; if (!opt?.value) { - sheet = null; + currentSheetId = null; tileTemplates = []; document.getElementById('tilePalette').innerHTML = '