Skip to content

Commit

Permalink
v2.8.1
Browse files Browse the repository at this point in the history
- Support Moulinette v3 new FilePicker
  - Thanks SvenWerlen - closes #149 
- Removed deprecation warnings for v13.
  • Loading branch information
sneat authored Nov 20, 2024
1 parent 7fcc237 commit 77d7026
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v2.8.1

- Support Moulinette v3 new FilePicker
- Thanks SvenWerlen
- Removed deprecation warnings for v13.

## v2.8.0
- Added support for importing partial playlists via the Moulinette importer (and associated zip importer).
- Allows creators to export individual sounds from a playlist and have it be merged into an existing playlist on import.
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "scene-packer",
"title": "Library: Scene Packer",
"description": "A module to assist with Scene and Adventure packing and unpacking.",
"version": "2.8.0",
"version": "2.8.1",
"library": "true",
"manifestPlusVersion": "1.2.0",
"minimumCoreVersion": "0.8.6",
Expand Down
2 changes: 1 addition & 1 deletion scripts/export-import/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function ReplaceCompendiumReferences(context, documents, availableDocumen
let foundEntity;
for (const sourceType of sources) {
for (const source of sourceType.data) {
foundEntity = source.find(e => (foundry.utils.getProperty(e, '_stats.compendiumSource') || foundry.utils.getProperty(e, 'data.flags.core.sourceId') || foundry.utils.getProperty(e, 'flags.core.sourceId')) === relation.uuid);
foundEntity = source.find(e => (foundry.utils.getProperty(e, '_stats.compendiumSource') ?? foundry.utils.getProperty(e, 'flags.core.sourceId') ?? foundry.utils.getProperty(e, 'data.flags.core.sourceId')) === relation.uuid);
if (foundEntity) {
if (!foundEntity.uuid || !foundEntity.documentName || !foundEntity.id) {
foundEntity.documentName = sourceType.type.documentName;
Expand Down
51 changes: 42 additions & 9 deletions scripts/export-import/moulinette-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,15 @@ export default class MoulinetteImporter extends FormApplication {
return entities;
}

const baseURL = await game.moulinette.applications.MoulinetteFileUtil.getBaseURL() || '';
// Moulinette 3.0 and newer
const moulinetteNew = await game.modules.get("moulinette")?.utils?.filemanager;
let baseURL = "";
if (moulinetteNew) {
baseURL = await moulinetteNew.getBaseURL() || "";
} else {
baseURL = await game.moulinette.applications.MoulinetteFileUtil.getBaseURL() || "";
}

const adventureFolder = `${this.scenePackerInfo.author}-${this.scenePackerInfo.name}`.slugify({strict: true}) || 'scene-packer-fallback';
const returnEntities = [];
console.groupCollapsed(
Expand Down Expand Up @@ -837,7 +845,7 @@ export default class MoulinetteImporter extends FormApplication {
needsDownloading = false;
}

const folder = localAsset.substring(0, localAsset.lastIndexOf('/'));
let folder = localAsset.substring(0, localAsset.lastIndexOf('/'));
const filename = asset.split('/').pop();
const newAssetLocation = `${baseURL}${folder}/${encodeURIComponent(filename)}`;

Expand All @@ -852,13 +860,38 @@ export default class MoulinetteImporter extends FormApplication {
continue;
}
const srcURL = new URL(assetURL);
if (!await game.moulinette.applications.MoulinetteFileUtil.downloadFile(srcURL, folder, filename)) {
ScenePacker.logType(this.scenePackerInfo.name, 'error', true,
game.i18n.format('SCENE-PACKER.exporter.progress.download-error', {
error: asset,
}),
);
continue;

if (moulinetteNew) {
// extract uri & pack_path from URL
// https://nyc3.digitaloceanspaces.com/moulinette-scenepacker/beneosbattlemaps/Crystal_Cave_-_01_HD/data/assets/beneos_assets/beneos_battlemaps/map_assets/icons/foundry_battlemap_text.webp?...
// => 1. https://nyc3.digitaloceanspaces.com/moulinette-scenepacker/beneosbattlemaps/Crystal_Cave_-_01_HD/data/assets
// => 2. beneosbattlemaps
// => 3. Crystal_Cave_-_01_HD
// => 4. beneos_assets/beneos_battlemaps/map_assets/icons/foundry_battlemap_text.webp?...
const regex = /^(.*scenepacker\/([^\/]+)\/([^\/]+)\/data\/assets)\/(.+)$/;
const match = srcURL.href.match(regex);
if (match) {
const uri = match[4];
const packPath = match[1];
folder = `${CONSTANTS.MOULINETTE_PATH}/${adventureFolder}`;
if (!await moulinetteNew.downloadFile(uri, packPath, folder)) {
ScenePacker.logType(this.scenePackerInfo.name, "error", true,
game.i18n.format("SCENE-PACKER.exporter.progress.download-error", {
error: asset
})
);
continue;
}
}
} else {
if (!await game.moulinette.applications.MoulinetteFileUtil.downloadFile(srcURL, folder, filename)) {
ScenePacker.logType(this.scenePackerInfo.name, "error", true,
game.i18n.format("SCENE-PACKER.exporter.progress.download-error", {
error: asset
})
);
continue;
}
}
}

Expand Down
Empty file modified scripts/lib/mime/bin/cli.js
100755 → 100644
Empty file.
26 changes: 16 additions & 10 deletions scripts/scene-packer.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,9 @@ export default class ScenePacker {
// Note that the imported version gets set during ProcessScene, but JournalEntries are processed before Scenes,
// so the current version flag won't have been set yet.
if (foundry.utils.isNewerVersion(moduleVersion, importedVersion)) {
let welcomeJournal = game.journal.find(j => j.name === this.welcomeJournal && j.getFlag('core', 'sourceId')
.startsWith(`Compendium.${this.moduleName}.`));
let welcomeJournal = game.journal.find(j => j.name === this.welcomeJournal &&
(j._stats?.compendiumSource ?? j.getFlag('core', 'sourceId'))
?.startsWith(`Compendium.${this.moduleName}.`));
if (welcomeJournal) {
welcomeJournal.sheet.render(true, {sheetMode: 'text'});
}
Expand Down Expand Up @@ -1051,8 +1052,9 @@ export default class ScenePacker {
const moduleVersion = (module?.version ?? module?.data?.version) || '0.0.0';
if (this.welcomeJournal && foundry.utils.isNewerVersion(moduleVersion, importedVersion)) {
// Display the welcome journal once per new module version
const j = game.journal.find(j => j.name === this.welcomeJournal && j.getFlag('core', 'sourceId')
?.startsWith(`Compendium.${this.moduleName}.`));
const j = game.journal.find(j => j.name === this.welcomeJournal &&
(j._stats?.compendiumSource ?? j.getFlag('core', 'sourceId'))
?.startsWith(`Compendium.${this.moduleName}.`));
if (j) {
j.sheet.render(true, {sheetMode: 'text'});
}
Expand Down Expand Up @@ -2961,7 +2963,7 @@ export default class ScenePacker {
if (actorId) {
const tData = tokenWorldData.find(t => t.sourceId === `Actor.${actorId}` && t.compendiumSourceId);
if (tData) {
const actor = game.actors.contents.find(a => (a.getFlag('core', 'sourceId') === tData.compendiumSourceId || a.getFlag(CONSTANTS.MODULE_NAME, 'sourceId') === tData.sourceId) && !a.getFlag(CONSTANTS.MODULE_NAME, 'deprecated'));
const actor = game.actors.contents.find(a => (a._stats?.compendiumSource ?? a.getFlag("core", "sourceId") === tData.compendiumSourceId || a.getFlag(CONSTANTS.MODULE_NAME, "sourceId") === tData.sourceId) && !a.getFlag(CONSTANTS.MODULE_NAME, "deprecated"));
if (actor) {
return actor;
}
Expand Down Expand Up @@ -3083,7 +3085,7 @@ export default class ScenePacker {
return collection.contents.find((a) => {
return (
(a.getFlag(CONSTANTS.MODULE_NAME, 'sourceId') === ref ||
a.getFlag('core', 'sourceId') === ref) &&
(a._stats?.compendiumSource ?? a.getFlag('core', 'sourceId')) === ref) &&
!a.getFlag(CONSTANTS.MODULE_NAME, 'deprecated')
);
});
Expand Down Expand Up @@ -3298,7 +3300,7 @@ export default class ScenePacker {
const hasUuid = !!note.compendiumSourceId;
const hasSourceId = !!note.sourceId;
const existingEntities = game.journal.filter(p => {
return (hasUuid && p.getFlag('core', 'sourceId') === note.compendiumSourceId) ||
return (hasUuid && (p._stats?.compendiumSource ?? p.getFlag('core', 'sourceId')) === note.compendiumSourceId) ||
(hasSourceId && p.getFlag(CONSTANTS.MODULE_NAME, 'sourceId') === note.sourceId);
});
if (existingEntities.length) {
Expand Down Expand Up @@ -3662,7 +3664,11 @@ export default class ScenePacker {
}

if (showUI) {
ui.sidebar.activateTab('scenes');
if (typeof ui.sidebar.changeTab === 'function') {
ui.sidebar.changeTab('scenes', 'primary');
} else {
ui.sidebar.activateTab('scenes');
}
}

/**
Expand Down Expand Up @@ -4093,7 +4099,7 @@ export default class ScenePacker {
return;
}

if (!getProperty(journalData, 'flags.scene-packer')) {
if (!foundry.utils.getProperty(journalData, 'flags.scene-packer')) {
return;
}

Expand Down Expand Up @@ -4403,7 +4409,7 @@ export default class ScenePacker {
// Only support unpacking Compendium references
continue;
}
const match = game.actors.contents.find(a => a.getFlag('core', 'sourceId') === actor.actorID);
const match = game.actors.contents.find(a => (a._stats?.compendiumSource ?? a.getFlag('core', 'sourceId')) === actor.actorID);
if (match) {
updates.push({
type: 'Actor',
Expand Down

0 comments on commit 77d7026

Please sign in to comment.