@@ -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