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.
46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
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;
|
|
}
|
|
}
|
|
} |