First version

Import images, videos as backgrounds, all in a drag and drop action.

Scene data import, example from Dungeon Alchemist with wall, doors and light information.

If only image is imported, the module can attempt to align the grid automatically.

This version may contain bugs and issues.
This commit is contained in:
2025-08-17 23:03:27 +02:00
committed by GitHub
parent 3c3f538579
commit 6523b0c0b5
9 changed files with 1477 additions and 2 deletions

View File

@@ -0,0 +1,46 @@
export class QuickBattlemapStorageService {
async ensureDirectoryExists(source, targetDirectoryPath) {
try {
await FilePicker.browse(source, targetDirectoryPath);
} catch (_) {
try {
await FilePicker.createDirectory(source, targetDirectoryPath, {});
} catch (error) {
const message = String(error || '');
if (!message.includes('EEXIST')) throw error;
}
}
}
async uploadBackgroundMedia(media, worldIdentifier) {
try {
let fileObject = media.file;
if (!fileObject) {
const response = await fetch(media.data);
const blob = await response.blob();
const type = blob.type || (media.isVideo ? 'video/webm' : 'image/png');
fileObject = new File([blob], media.filename, {
type
});
}
const source = 'data';
const target = `worlds/${worldIdentifier}/quick-battlemap`;
await this.ensureDirectoryExists(source, target);
const result = await FilePicker.upload(source, target, fileObject, {
overwrite: true
});
return {
path: result?.path
};
} catch (error) {
console.error('Quick Battlemap Importer | Upload failed:', error);
ui.notifications.error(game.i18n.localize('QUICKBATTLEMAP.UploadFailed') + ': ' + (error?.message ?? error));
return null;
}
}
}