Room Template fixes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = '<div class="text-gray-500 text-xs p-2">Select a TileMap</div>';
|
||||
document.getElementById('commonTags').innerHTML = '';
|
||||
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();
|
||||
currentSheetId = +opt.value;
|
||||
|
||||
// Filter templates for this sheet (already loaded, no API call)
|
||||
tileTemplates = allTileTemplates.filter(t => t.sheetId === sheet.id);
|
||||
tileTemplates = allTileTemplates.filter(t => t.sheetId === currentSheetId);
|
||||
|
||||
// Collect all tags
|
||||
allTags.clear();
|
||||
@@ -599,6 +627,14 @@ function loadTileTemplates() {
|
||||
|
||||
renderCommonTags();
|
||||
renderTemplates();
|
||||
|
||||
// Don't rebuild grid - just re-render to show existing tiles
|
||||
// Grid dimensions stay the same, tiles from other sheets still display
|
||||
for (let y = 0; y < gh; y++) {
|
||||
for (let x = 0; x < gw; x++) {
|
||||
render(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderCommonTags() {
|
||||
@@ -634,6 +670,12 @@ function filterTemplates() {
|
||||
}
|
||||
|
||||
function renderTemplates(filterTags = []) {
|
||||
const sheet = currentSheetId ? loadedSheets[currentSheetId] : null;
|
||||
if (!sheet) {
|
||||
document.getElementById('tilePalette').innerHTML = '<div class="text-gray-500 text-xs p-2">Select a TileMap</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let filtered = tileTemplates;
|
||||
|
||||
// Filter by current layer (floor vs wall)
|
||||
|
||||
Reference in New Issue
Block a user