Skip to content

Commit 7b7578a

Browse files
committed
fix: sort and ID as key options was not working with adventures
1 parent b901f6b commit 7b7578a

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
- Merged options sort document and folders
88

9+
### Fixed
10+
11+
- The sorting option was not working with adventures
12+
- The document ID as key option was not working with adventures
13+
914
[12.2.0] - 2025-03-07
1015

1116
### Added

scripts/exporters/adventure-exporter.mjs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,66 +31,72 @@ export class AdventureExporter extends AbstractExporter {
3131

3232
// Scenes
3333
for (const document of avPack.scenes) {
34-
this.dataset.entries[avPack.name].scenes[document.name] = foundry.utils.mergeObject(
34+
const key = this._getExportKey(document);
35+
this.dataset.entries[avPack.name].scenes[key] = foundry.utils.mergeObject(
3536
exporters.SceneExporter.getDocumentData(document, document),
36-
(this.existingContent[avPack.name]?.scenes ?? {})[document.name] ?? {},
37+
(this.existingContent[avPack.name]?.scenes ?? {})[key] ?? {},
3738
);
3839

3940
this._stepProgressBar();
4041
}
4142

4243
// Macros
4344
for (const document of avPack.macros) {
44-
this.dataset.entries[avPack.name].macros[document.name] = foundry.utils.mergeObject(
45+
const key = this._getExportKey(document);
46+
this.dataset.entries[avPack.name].macros[key] = foundry.utils.mergeObject(
4547
exporters.MacroExporter.getDocumentData(document),
46-
(this.existingContent[avPack.name]?.macros ?? {})[document.name] ?? {},
48+
(this.existingContent[avPack.name]?.macros ?? {})[key] ?? {},
4749
);
4850

4951
this._stepProgressBar();
5052
}
5153

5254
// Playlists
5355
for (const document of avPack.playlists) {
54-
this.dataset.entries[avPack.name].playlists[document.name] = foundry.utils.mergeObject(
56+
const key = this._getExportKey(document);
57+
this.dataset.entries[avPack.name].playlists[key] = foundry.utils.mergeObject(
5558
exporters.PlaylistExporter.getDocumentData(document, document),
56-
(this.existingContent[avPack.name]?.playlists ?? {})[document.name] ?? {},
59+
(this.existingContent[avPack.name]?.playlists ?? {})[key] ?? {},
5760
);
5861

5962
this._stepProgressBar();
6063
}
6164

6265
// Actors
6366
for (const document of avPack.actors) {
64-
this.dataset.entries[avPack.name].actors[document.name] = foundry.utils.mergeObject(
67+
const key = this._getExportKey(document);
68+
this.dataset.entries[avPack.name].actors[key] = foundry.utils.mergeObject(
6569
exporters.ActorExporter.getDocumentData(
6670
document,
6771
document,
6872
this.options.customMapping.actor,
6973
),
70-
(this.existingContent[avPack.name]?.actors ?? {})[document.name] ?? {},
74+
(this.existingContent[avPack.name]?.actors ?? {})[key] ?? {},
7175
);
7276

7377
this._stepProgressBar();
7478
}
7579

7680
// Items
7781
for (const document of avPack.items) {
78-
this.dataset.entries[avPack.name].items[document.name] = foundry.utils.mergeObject(
82+
const key = this._getExportKey(document);
83+
this.dataset.entries[avPack.name].items[key] = foundry.utils.mergeObject(
7984
exporters.ItemExporter.getDocumentData(
8085
document,
8186
this.options.customMapping.item,
8287
),
83-
(this.existingContent[avPack.name]?.items ?? {})[document.name] ?? {},
88+
(this.existingContent[avPack.name]?.items ?? {})[key] ?? {},
8489
);
8590

8691
this._stepProgressBar();
8792
}
8893

8994
// Tables
9095
for (const document of avPack.tables) {
91-
this.dataset.entries[avPack.name].tables[document.name] = foundry.utils.mergeObject(
96+
const key = this._getExportKey(document);
97+
this.dataset.entries[avPack.name].tables[key] = foundry.utils.mergeObject(
9298
exporters.RollTableExporter.getDocumentData(document, document),
93-
(this.existingContent[avPack.name]?.tables ?? {})[document.name] ?? {},
99+
(this.existingContent[avPack.name]?.tables ?? {})[key] ?? {},
94100
);
95101

96102
this._stepProgressBar();
@@ -105,17 +111,19 @@ export class AdventureExporter extends AbstractExporter {
105111

106112
// Journals
107113
for (const document of avPack.journal) {
108-
this.dataset.entries[avPack.name].journals[document.name] = foundry.utils.mergeObject(
114+
const key = this._getExportKey(document);
115+
this.dataset.entries[avPack.name].journals[key] = foundry.utils.mergeObject(
109116
exporters.JournalEntryExporter.getDocumentData(document, document),
110-
(this.existingContent[avPack.name]?.journals ?? {})[document.name] ?? {},
117+
(this.existingContent[avPack.name]?.journals ?? {})[key] ?? {},
111118
);
112119

113120
this._stepProgressBar();
114121
}
115122

116123
// Cards
117124
for (const document of avPack.cards) {
118-
this.dataset.entries[avPack.name].cards[document.name] = foundry.utils.mergeObject(
125+
const key = this._getExportKey(document);
126+
this.dataset.entries[avPack.name].cards[key] = foundry.utils.mergeObject(
119127
exporters.CardsExporter.getDocumentData(document, document),
120128
(this.existingContent[avPack.name]?.cards ?? {})[document.name] ?? {},
121129
);
@@ -127,6 +135,8 @@ export class AdventureExporter extends AbstractExporter {
127135
for (const key in this.dataset.entries[avPack.name]) {
128136
if (0 === Object.keys(this.dataset.entries[avPack.name][key]).length) {
129137
delete this.dataset.entries[avPack.name][key];
138+
} else if (this.options.sortEntries && !['name', 'caption', 'description'].includes(key)) {
139+
this.dataset.entries[avPack.name][key] = this._sortItems(this.dataset.entries[avPack.name][key]);
130140
}
131141
}
132142
});

0 commit comments

Comments
 (0)