New visual style and multifloor support

This commit is contained in:
2026-01-08 05:57:56 +01:00
parent 61fa58fcc3
commit 1a1e36eabd
15 changed files with 998 additions and 49 deletions

View File

@@ -8,7 +8,7 @@
*/
/** Module identifier for console logging */
const MODULE_LOG_PREFIX = 'Quick Battlemap Importer';
const MODULE_LOG_PREFIX = 'Myxeliums Battlemap Importer';
/**
* @typedef {Object} ProcessedImageData

View File

@@ -19,7 +19,7 @@
/** CSS selectors for frequently accessed elements */
const PANEL_SELECTORS = {
PANEL_ROOT: '#quick-battlemap-drop-area',
PANEL_ROOT: '#myxeliums-battlemap-drop-area',
CREATE_BUTTON: '.create-scene-button',
RESET_BUTTON: '.reset-button',
CLOSE_BUTTON: '.header-button.close',
@@ -35,7 +35,7 @@ const PANEL_SELECTORS = {
};
/** LocalStorage key for persisting no-grid preference */
const NO_GRID_STORAGE_KEY = 'quick-battlemap:no-grid';
const NO_GRID_STORAGE_KEY = 'myxeliums-battlemap:no-grid';
/**
* View class that manages the import panel DOM and user interactions.
@@ -83,7 +83,7 @@ export class ImportPanelView {
}
// Remove any existing panel to prevent duplicates
const existingPanel = document.getElementById('quick-battlemap-drop-area');
const existingPanel = document.getElementById('myxeliums-battlemap-drop-area');
if (existingPanel) {
existingPanel.remove();
}
@@ -138,7 +138,7 @@ export class ImportPanelView {
` : '';
return `
<div id="quick-battlemap-drop-area" class="qbi-panel">
<div id="myxeliums-battlemap-drop-area" class="qbi-panel">
<header class="qbi-header">
<div class="qbi-header-title">
<i class="fas fa-map qbi-header-icon"></i>
@@ -378,7 +378,7 @@ export class ImportPanelView {
* @returns {HTMLElement|null} The panel element
*/
getPanelElement() {
return document.getElementById('quick-battlemap-drop-area');
return document.getElementById('myxeliums-battlemap-drop-area');
}
/**

View File

@@ -554,7 +554,7 @@ export class SceneBuilder {
/**
* Create floor tiles for multi-floor scenes using Levels module format.
* Each additional floor is created as an overhead tile with proper elevation.
* Each additional floor is created as a tile with proper elevation.
*
* @param {Scene} scene - The scene to add floor tiles to
* @param {Array} additionalFloors - Array of floor data (excluding base floor)
@@ -582,6 +582,7 @@ export class SceneBuilder {
const rangeTop = elevation + floorHeight * 2 - 1;
// Create tile for this floor with Levels flags
// Using overhead: false and proper Levels flags to avoid fade/zoom behavior
const tileData = {
texture: {
src: floor.uploadedPath
@@ -590,14 +591,17 @@ export class SceneBuilder {
y: 0,
width: baseDimensions.width || scene.width,
height: baseDimensions.height || scene.height,
overhead: true,
overhead: false, // Not overhead - this is a floor tile
roof: false,
occlusion: { mode: 1 }, // Levels uses occlusion mode 1
occlusion: { mode: 0 }, // No occlusion - controlled by Levels
elevation: elevation,
sort: 1000 + (i * 100),
sort: 100 + (i * 10), // Lower sort order for floor tiles
flags: {
levels: {
rangeTop: rangeTop
rangeTop: rangeTop,
showIfAbove: false, // Don't show when above this floor
noCollision: true, // No 3D collision for floor tiles
noFogHide: true // Don't hide in fog
}
}
};

View File

@@ -183,12 +183,61 @@ export class SceneDataNormalizer {
/**
* Normalize an array of wall data to Foundry's Wall document format.
* Filters out regular walls that share exact coordinates with doors to prevent
* duplicate walls blocking door functionality.
*
* @param {Array} wallsArray - Array of raw wall data objects
* @returns {NormalizedWallData[]} Array of normalized wall documents
*/
normalizeWallsData(wallsArray) {
return wallsArray.map(wall => this.normalizeWall(wall));
const normalizedWalls = wallsArray.map(wall => this.normalizeWall(wall));
return this.filterDuplicateWallsAtDoorLocations(normalizedWalls);
}
/**
* Filter out regular walls that have the same coordinates as doors.
* Some map exports include both a wall segment and a door at the same location,
* which causes the door to be blocked by the overlapping wall.
*
* @param {NormalizedWallData[]} walls - Array of normalized wall data
* @returns {NormalizedWallData[]} Filtered array with duplicate walls removed
*/
filterDuplicateWallsAtDoorLocations(walls) {
// Collect coordinates of all doors
const doorCoordinates = new Set();
for (const wall of walls) {
if (wall.door > 0 && Array.isArray(wall.c) && wall.c.length >= 4) {
// Store both forward and reverse coordinate strings to handle different orderings
const coordKey = wall.c.slice(0, 4).join(',');
const reverseKey = [wall.c[2], wall.c[3], wall.c[0], wall.c[1]].join(',');
doorCoordinates.add(coordKey);
doorCoordinates.add(reverseKey);
}
}
// If no doors, return walls as-is
if (doorCoordinates.size === 0) {
return walls;
}
// Filter out regular walls (door === 0) that share coordinates with doors
return walls.filter(wall => {
// Keep all doors
if (wall.door > 0) {
return true;
}
// Check if this regular wall overlaps with a door location
if (Array.isArray(wall.c) && wall.c.length >= 4) {
const coordKey = wall.c.slice(0, 4).join(',');
if (doorCoordinates.has(coordKey)) {
return false; // Remove this wall - there's a door here
}
}
return true;
});
}
/**
@@ -199,16 +248,22 @@ export class SceneDataNormalizer {
*/
normalizeWall(wall) {
const restrictionTypes = this.getWallRestrictionTypes();
const doorType = this.ensureFiniteNumber(wall.door, 0);
// Doors should default to NORMAL restrictions (blocking) when closed,
// while regular walls default to NONE (the source data usually specifies restrictions)
const isDoor = doorType > 0;
const defaultRestriction = isDoor ? restrictionTypes.NORMAL : restrictionTypes.NONE;
return {
c: this.normalizeWallCoordinates(wall.c),
door: this.ensureFiniteNumber(wall.door, 0),
door: doorType,
ds: this.ensureFiniteNumber(wall.ds, 0),
dir: this.ensureFiniteNumber(wall.dir, 0),
move: this.parseRestrictionValue(wall.move, restrictionTypes.NONE, restrictionTypes),
sound: this.parseRestrictionValue(wall.sound, restrictionTypes.NONE, restrictionTypes),
sight: this.parseRestrictionValue(wall.sense ?? wall.sight, restrictionTypes.NONE, restrictionTypes),
light: this.parseRestrictionValue(wall.light, restrictionTypes.NONE, restrictionTypes),
move: this.parseRestrictionValue(wall.move, defaultRestriction, restrictionTypes),
sound: this.parseRestrictionValue(wall.sound, defaultRestriction, restrictionTypes),
sight: this.parseRestrictionValue(wall.sense ?? wall.sight, defaultRestriction, restrictionTypes),
light: this.parseRestrictionValue(wall.light, defaultRestriction, restrictionTypes),
flags: wall.flags ?? {}
};
}

View File

@@ -738,9 +738,10 @@ export class SceneImportController {
}
// Set Levels module scene flags for floor definitions
// Only set sceneLevels - let backgroundElevation default to 0
// This prevents the background from incorrectly hiding/showing
await createdScene.update({
'flags.levels.sceneLevels': sceneLevels,
'flags.levels.backgroundElevation': floorElevations[0]
'flags.levels.sceneLevels': sceneLevels
});
this.cleanupAfterMultiFloorCreation(sceneName);

View File

@@ -0,0 +1,139 @@
/**
* Myxeliums Battlemap Importer - Main Entry Point
*
* This module provides a streamlined way to import battlemaps into Foundry VTT.
* It adds a "Quick import" button to the Scenes sidebar that opens a drag-and-drop
* panel for creating scenes from images/videos and optional JSON configuration files.
*
* @module MyxeliumsBattlemap
* @author Myxelium
* @license MIT
*/
import { SceneImportController } from './lib/scene-import-controller.js';
/** @type {SceneImportController|null} Singleton instance of the import controller */
let sceneImportController = null;
/**
* Module identifier used for logging and namespacing
* @constant {string}
*/
const MODULE_ID = 'Myxeliums Battlemap Importer';
/**
* CSS class name for the quick import button to prevent duplicate insertion
* @constant {string}
*/
const QUICK_IMPORT_BUTTON_CLASS = 'myxeliums-battlemap-quick-import';
/**
* Initialize the module when Foundry is ready.
* Sets up the import controller and registers necessary handlers.
*/
Hooks.once('init', async function () {
console.log(`${MODULE_ID} | Initializing module`);
});
/**
* Complete module setup after Foundry is fully loaded.
* Creates the controller instance and displays a ready notification.
*/
Hooks.once('ready', async function () {
console.log(`${MODULE_ID} | Module ready`);
sceneImportController = new SceneImportController();
sceneImportController.initialize();
ui.notifications.info(game.i18n.localize("QUICKBATTLEMAP.Ready"));
});
/**
* Add the "Quick import" button to the Scenes directory header.
* This hook fires whenever the SceneDirectory is rendered.
*
* @param {Application} _app - The SceneDirectory application instance (unused)
* @param {jQuery|HTMLElement} html - The rendered HTML element
*/
Hooks.on('renderSceneDirectory', (_app, html) => {
// Only GMs can use the quick import feature
if (!game.user?.isGM) {
return;
}
// Handle different HTML element formats across Foundry versions
const rootElement = html?.[0] || html?.element || html;
if (!(rootElement instanceof HTMLElement)) {
return;
}
// Prevent adding duplicate buttons
const existingButton = rootElement.querySelector(`button.${QUICK_IMPORT_BUTTON_CLASS}`);
if (existingButton) {
return;
}
// Find a suitable container for the button
const buttonContainer = findButtonContainer(rootElement);
if (!buttonContainer) {
return;
}
// Create and append the quick import button
const quickImportButton = createQuickImportButton();
buttonContainer.appendChild(quickImportButton);
});
/**
* Find a suitable container element for the quick import button.
* Tries multiple selectors for compatibility across Foundry versions.
*
* @param {HTMLElement} rootElement - The root element to search within
* @returns {HTMLElement|null} The container element or null if not found
*/
function findButtonContainer(rootElement) {
const containerSelectors = [
'.header-actions',
'.action-buttons',
'.directory-header'
];
for (const selector of containerSelectors) {
const container = rootElement.querySelector(selector);
if (container) {
return container;
}
}
return null;
}
/**
* Create the quick import button element with icon and click handler.
*
* @returns {HTMLButtonElement} The configured button element
*/
function createQuickImportButton() {
const button = document.createElement('button');
button.type = 'button';
button.className = QUICK_IMPORT_BUTTON_CLASS;
button.innerHTML = '<i class="fas fa-map"></i> <span>Quick import</span>';
button.addEventListener('click', handleQuickImportClick);
return button;
}
/**
* Handle click events on the quick import button.
* Creates the controller if needed and shows the import panel.
*/
function handleQuickImportClick() {
if (!sceneImportController) {
sceneImportController = new SceneImportController();
sceneImportController.initialize();
}
sceneImportController.showImportPanel();
}

View File

@@ -1,11 +1,11 @@
/**
* Quick Battlemap Importer - Main Entry Point
* Myxeliums Battlemap Importer - Main Entry Point
*
* This module provides a streamlined way to import battlemaps into Foundry VTT.
* It adds a "Quick import" button to the Scenes sidebar that opens a drag-and-drop
* panel for creating scenes from images/videos and optional JSON configuration files.
*
* @module QuickBattlemap
* @module MyxeliumsBattlemap
* @author Myxelium
* @license MIT
*/
@@ -19,13 +19,13 @@ let sceneImportController = null;
* Module identifier used for logging and namespacing
* @constant {string}
*/
const MODULE_ID = 'Quick Battlemap';
const MODULE_ID = 'Myxeliums Battlemap Importer';
/**
* CSS class name for the quick import button to prevent duplicate insertion
* @constant {string}
*/
const QUICK_IMPORT_BUTTON_CLASS = 'quick-battlemap-quick-import';
const QUICK_IMPORT_BUTTON_CLASS = 'myxeliums-battlemap-quick-import';
/**
* Initialize the module when Foundry is ready.