Skip to content

Commit 61a1ca5

Browse files
authored
V2.0.2 (#9)
* v2.0.2 * Handle unlinked references * Handle unlinked journal references * Pre-load compendium packs prior to accessing them
1 parent 019cd0e commit 61a1ca5

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v2.0.2
4+
5+
- Load compendium pack data prior to trying to use it to reduce the chance of possible race conditions.
6+
- Journal Pins that are entirely unlinked will no longer throw an error, they'll just be packed up and included as unlinked pins.
7+
38
## v2.0.1
49

510
- Fixed bug where importing from compendiums would sometimes break.

module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "scene-packer",
33
"title": "Library: Scene Packer",
44
"description": "A module to assist with Scene and Adventure packing and unpacking.",
5-
"version": "2.0.1",
5+
"version": "2.0.2",
66
"library": "true",
77
"manifestPlusVersion": "1.0.0",
88
"minimumCoreVersion": "0.7.9",

scripts/scene-packer.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,19 @@ export default class ScenePacker {
614614
return this;
615615
}
616616

617+
/**
618+
* Ensure that each of the packs are loaded
619+
* @returns {Promise<void>}
620+
*/
621+
async loadPacks() {
622+
for (let packName of [...this.packs.journals, ...this.packs.creatures, ...this.packs.macros]) {
623+
const pack = game.packs.get(packName);
624+
if (pack) {
625+
await pack.getIndex();
626+
}
627+
}
628+
}
629+
617630
/**
618631
* PackScene() will write the following information to the Scene data for later retrieval:
619632
* Journal Note Pins
@@ -623,6 +636,8 @@ export default class ScenePacker {
623636
* @returns Promise
624637
*/
625638
async PackScene(scene = game.scenes.get(game.user.viewedScene)) {
639+
await this.loadPacks();
640+
626641
// Remove the flag that tracks what version of the module imported the Scene, as it doesn't make sense to ship that out in the module.
627642
await scene.unsetFlag(this.moduleName, FLAGS_IMPORTED_VERSION);
628643

@@ -675,9 +690,9 @@ export default class ScenePacker {
675690
return mergeObject(
676691
note,
677692
{
678-
sourceId: journalData.getFlag('core', 'sourceId'),
693+
sourceId: journalData?.getFlag('core', 'sourceId'),
679694
compendiumSourceId: compendiumJournal?.uuid,
680-
journalName: journalData.name,
695+
journalName: journalData?.name,
681696
folderName: game.folders.get(journalData?.data?.folder)?.data?.name,
682697
'-=entryId': null,
683698
'-=_id': null,
@@ -798,6 +813,10 @@ export default class ScenePacker {
798813
* @returns {Object|null} The journal in the compendium.
799814
*/
800815
async FindJournalInCompendiums(journal, searchPacks) {
816+
if (!journal) {
817+
return null;
818+
}
819+
801820
const sourceId = journal.getFlag('core', 'sourceId');
802821
if (sourceId && sourceId.startsWith(`Compendium.${this.moduleName}`)) {
803822
const match = fromUuid(sourceId);
@@ -911,6 +930,10 @@ export default class ScenePacker {
911930
* @returns {Object|null} The actor in the compendium.
912931
*/
913932
async FindActorInCompendiums(actor, searchPacks) {
933+
if (!actor) {
934+
return null;
935+
}
936+
914937
const sourceId = actor.getFlag('core', 'sourceId');
915938
if (sourceId && sourceId.startsWith(`Compendium.${this.moduleName}`)) {
916939
const match = fromUuid(sourceId);
@@ -1517,6 +1540,8 @@ export default class ScenePacker {
15171540
* @param {Boolean} showLinkedJournal Whether to show any Journals linked to the Scene.
15181541
*/
15191542
async UnpackScene(scene = game.scenes.get(game.user.viewedScene), {showLinkedJournal = true} = {}) {
1543+
await this.loadPacks();
1544+
15201545
const tokenInfo = scene.getFlag(this.moduleName, FLAGS_TOKENS);
15211546
const journalInfo = scene.getFlag(this.moduleName, FLAGS_JOURNALS);
15221547
const sceneJournalInfo = scene.getFlag(this.moduleName, FLAGS_SCENE_JOURNAL);

0 commit comments

Comments
 (0)