Skip to content

Commit

Permalink
Run UUIDs in embedded items through name-to-id conversions (foundryvt…
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed May 30, 2023
1 parent 8874082 commit 79428f3
Show file tree
Hide file tree
Showing 141 changed files with 880 additions and 866 deletions.
17 changes: 14 additions & 3 deletions build/lib/compendium-pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class CompendiumPack {
docSource.system.schema = { version: MigrationRunnerBase.LATEST_SCHEMA_VERSION, lastMigration: null };
for (const item of docSource.items) {
item.system.schema = { version: MigrationRunnerBase.LATEST_SCHEMA_VERSION, lastMigration: null };
CompendiumPack.convertRuleUUIDs(item, { to: "ids", map: CompendiumPack.namesToIds });
}
}

Expand Down Expand Up @@ -257,7 +258,7 @@ class CompendiumPack {
const hasUUIDChoices = (choices: object | string | undefined): choices is Record<string, { value: string }> =>
typeof choices === "object" &&
Object.values(choices ?? {}).every(
(c): c is { value: unknown } => typeof c.value === "string" && c.value.startsWith("Compendium.")
(c): c is { value: unknown } => typeof c.value === "string" && c.value.startsWith("Compendium.pf2e.")
);

const toNameRef = (uuid: string): string => {
Expand All @@ -283,7 +284,14 @@ class CompendiumPack {
}
};

const convert = to === "ids" ? toIDRef : toNameRef;
const convert = (uuid: string): string => {
if (uuid.startsWith("Item.")) {
throw PackError(`World-item UUID found: ${uuid}`);
}
if (!uuid.startsWith("Compendium.pf2e.")) return uuid;
return to === "ids" ? toIDRef(uuid) : toNameRef(uuid);
};

const rules: REMaybeWithUUIDs[] = source.system.rules;

for (const rule of rules) {
Expand All @@ -293,12 +301,15 @@ class CompendiumPack {
effect.uuid = convert(effect.uuid);
}
}
} else if (rule.key === "GrantItem" && typeof rule.uuid === "string" && !rule.uuid.startsWith("{")) {
} else if (rule.key === "GrantItem" && typeof rule.uuid === "string") {
rule.uuid = convert(rule.uuid);
} else if (rule.key === "ChoiceSet" && hasUUIDChoices(rule.choices)) {
for (const [key, choice] of Object.entries(rule.choices)) {
rule.choices[key].value = convert(choice.value);
}
if ("selection" in rule && typeof rule.selection === "string") {
rule.selection = convert(rule.selection);
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion build/lib/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ class PackExtractor {

const sanitized = this.#sanitizeDocument(docSource);
if (isActorSource(sanitized)) {
sanitized.items = sanitized.items.map((itemData) => this.#sanitizeDocument(itemData, { isEmbedded: true }));
sanitized.items = sanitized.items.map((itemData) => {
CompendiumPack.convertRuleUUIDs(itemData, { to: "names", map: this.#idsToNames });
return this.#sanitizeDocument(itemData, { isEmbedded: true });
});
}

if (isItemSource(sanitized)) {
Expand Down
2 changes: 1 addition & 1 deletion packs/data/abomination-vaults-bestiary.db/chafkhem.json
Original file line number Diff line number Diff line change
Expand Up @@ -3153,7 +3153,7 @@
"predicate": [
"target:mode:living"
],
"uuid": "Compendium.pf2e.bestiary-effects.1bOSJ2LbEC28aI9f"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Despair"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@
"predicate": [
"target:trait:drow"
],
"uuid": "Compendium.pf2e.bestiary-effects.iDLu83vhWoNIE7xt"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Commanding Aura (Quara)"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"predicate": [
"target:trait:undead"
],
"uuid": "Compendium.pf2e.bestiary-effects.kjP0J97hhoIhbF3M"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Necrotic Field"
}
],
"key": "Aura",
Expand Down
2 changes: 1 addition & 1 deletion packs/data/age-of-ashes-bestiary.db/nolly-peltry.json
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@
"enter"
],
"includesSelf": false,
"uuid": "Compendium.pf2e.bestiary-effects.UxeoSRmPbD5hjiEi"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Inspiring Presence"
}
],
"key": "Aura",
Expand Down
2 changes: 1 addition & 1 deletion packs/data/blood-lords-bestiary.db/mummy-valet.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"predicate": [
"target:mode:living"
],
"uuid": "Compendium.pf2e.bestiary-effects.1bOSJ2LbEC28aI9f"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Despair"
}
],
"key": "Aura",
Expand Down
2 changes: 1 addition & 1 deletion packs/data/blood-lords-bestiary.db/shabti-votary.json
Original file line number Diff line number Diff line change
Expand Up @@ -3909,7 +3909,7 @@
"predicate": [
"target:trait:undead"
],
"uuid": "Compendium.pf2e.bestiary-effects.mo4IRyv7GGRBJihU"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Discerning Aura"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@
"predicate": [
"target:negative-healing"
],
"uuid": "Compendium.pf2e.bestiary-effects.x8e0MXrPgdRYQqBm"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Field of Undeath"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2655,7 +2655,7 @@
"predicate": [
"target:negative-healing"
],
"uuid": "Compendium.pf2e.bestiary-effects.x8e0MXrPgdRYQqBm"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Field of Undeath"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@
"predicate": [
"target:mode:living"
],
"uuid": "Compendium.pf2e.bestiary-effects.1bOSJ2LbEC28aI9f"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Despair"
}
],
"key": "Aura",
Expand Down
2 changes: 1 addition & 1 deletion packs/data/book-of-the-dead-bestiary.db/ice-mummy.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
"predicate": [
"target:mode:living"
],
"uuid": "Compendium.pf2e.bestiary-effects.1bOSJ2LbEC28aI9f"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Despair"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3309,7 +3309,7 @@
"predicate": [
"target:mode:living"
],
"uuid": "Compendium.pf2e.bestiary-effects.1bOSJ2LbEC28aI9f"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Despair"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"events": [
"enter"
],
"uuid": "Compendium.pf2e.bestiary-effects.YKCsmlMgI0aS7joO"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Silent Aura"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"predicate": [
"target:mode:living"
],
"uuid": "Compendium.pf2e.bestiary-effects.1bOSJ2LbEC28aI9f"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Despair"
}
],
"key": "Aura",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6823,7 +6823,7 @@
"predicate": [
"target:mode:living"
],
"uuid": "Compendium.pf2e.bestiary-effects.ob00D61F0c4PIvj1"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Utter Despair"
}
],
"key": "Aura",
Expand Down
2 changes: 1 addition & 1 deletion packs/data/extinction-curse-bestiary.db/urushil.json
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@
]
}
],
"uuid": "Compendium.pf2e.bestiary-effects.5NSWRxAsJuvwyl0E"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Commander's Aura"
}
],
"key": "Aura",
Expand Down
2 changes: 1 addition & 1 deletion packs/data/gatewalkers-bestiary.db/equendia.json
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@
"predicate": [
"target:mode:living"
],
"uuid": "Compendium.pf2e.bestiary-effects.1bOSJ2LbEC28aI9f"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Despair"
}
],
"key": "Aura",
Expand Down
2 changes: 1 addition & 1 deletion packs/data/gatewalkers-bestiary.db/green-monkey.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
"enter"
],
"includesSelf": false,
"uuid": "Compendium.pf2e.bestiary-effects.xOD3ufpzA8H7W4sP"
"uuid": "Compendium.pf2e.bestiary-effects.Effect: Aura of Good Cheer"
}
],
"key": "Aura",
Expand Down
18 changes: 9 additions & 9 deletions packs/data/iconics.db/amiri-level-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,28 +501,28 @@
},
"choices": [
{
"value": "Compendium.pf2e.classfeatures.0FtzFbUrN56KA67z"
"value": "Compendium.pf2e.classfeatures.Animal Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.VDot7CDcXElxmkkz"
"value": "Compendium.pf2e.classfeatures.Dragon Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.k7M9jedvt31AJ5ZR"
"value": "Compendium.pf2e.classfeatures.Fury Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.JuKD6k7nDwfO0Ckv"
"value": "Compendium.pf2e.classfeatures.Giant Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.TQqv9Q5mB4PW6LH9"
"value": "Compendium.pf2e.classfeatures.Spirit Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.SCYSjUbMmw8JD9P9"
"value": "Compendium.pf2e.classfeatures.Superstition Instinct"
}
],
"flag": "instinct",
"key": "ChoiceSet",
"prompt": "PF2E.SpecificRule.Barbarian.Instinct.Prompt",
"selection": "Compendium.pf2e.classfeatures.JuKD6k7nDwfO0Ckv"
"selection": "Compendium.pf2e.classfeatures.Giant Instinct"
},
{
"flag": "giantInstinct",
Expand Down Expand Up @@ -2408,7 +2408,7 @@
}
],
"reevaluateOnUpdate": true,
"uuid": "Compendium.pf2e.feats-srd.xQMz6eDgX75WX2ce"
"uuid": "Compendium.pf2e.feats-srd.Intimidating Glare"
},
{
"flag": "scareToDeath",
Expand All @@ -2417,7 +2417,7 @@
"skill:itm:rank:4"
],
"reevaluateOnUpdate": true,
"uuid": "Compendium.pf2e.feats-srd.mZttsiWl1ql5NvrH"
"uuid": "Compendium.pf2e.feats-srd.Scare to Death"
}
],
"slug": "raging-intimidation",
Expand Down
18 changes: 9 additions & 9 deletions packs/data/iconics.db/amiri-level-3.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,28 +501,28 @@
},
"choices": [
{
"value": "Compendium.pf2e.classfeatures.0FtzFbUrN56KA67z"
"value": "Compendium.pf2e.classfeatures.Animal Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.VDot7CDcXElxmkkz"
"value": "Compendium.pf2e.classfeatures.Dragon Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.k7M9jedvt31AJ5ZR"
"value": "Compendium.pf2e.classfeatures.Fury Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.JuKD6k7nDwfO0Ckv"
"value": "Compendium.pf2e.classfeatures.Giant Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.TQqv9Q5mB4PW6LH9"
"value": "Compendium.pf2e.classfeatures.Spirit Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.SCYSjUbMmw8JD9P9"
"value": "Compendium.pf2e.classfeatures.Superstition Instinct"
}
],
"flag": "instinct",
"key": "ChoiceSet",
"prompt": "PF2E.SpecificRule.Barbarian.Instinct.Prompt",
"selection": "Compendium.pf2e.classfeatures.JuKD6k7nDwfO0Ckv"
"selection": "Compendium.pf2e.classfeatures.Giant Instinct"
},
{
"flag": "giantInstinct",
Expand Down Expand Up @@ -2835,7 +2835,7 @@
}
],
"reevaluateOnUpdate": true,
"uuid": "Compendium.pf2e.feats-srd.xQMz6eDgX75WX2ce"
"uuid": "Compendium.pf2e.feats-srd.Intimidating Glare"
},
{
"flag": "scareToDeath",
Expand All @@ -2844,7 +2844,7 @@
"skill:itm:rank:4"
],
"reevaluateOnUpdate": true,
"uuid": "Compendium.pf2e.feats-srd.mZttsiWl1ql5NvrH"
"uuid": "Compendium.pf2e.feats-srd.Scare to Death"
}
],
"slug": "raging-intimidation",
Expand Down
18 changes: 9 additions & 9 deletions packs/data/iconics.db/amiri-level-5.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,28 +501,28 @@
},
"choices": [
{
"value": "Compendium.pf2e.classfeatures.0FtzFbUrN56KA67z"
"value": "Compendium.pf2e.classfeatures.Animal Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.VDot7CDcXElxmkkz"
"value": "Compendium.pf2e.classfeatures.Dragon Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.k7M9jedvt31AJ5ZR"
"value": "Compendium.pf2e.classfeatures.Fury Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.JuKD6k7nDwfO0Ckv"
"value": "Compendium.pf2e.classfeatures.Giant Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.TQqv9Q5mB4PW6LH9"
"value": "Compendium.pf2e.classfeatures.Spirit Instinct"
},
{
"value": "Compendium.pf2e.classfeatures.SCYSjUbMmw8JD9P9"
"value": "Compendium.pf2e.classfeatures.Superstition Instinct"
}
],
"flag": "instinct",
"key": "ChoiceSet",
"prompt": "PF2E.SpecificRule.Barbarian.Instinct.Prompt",
"selection": "Compendium.pf2e.classfeatures.JuKD6k7nDwfO0Ckv"
"selection": "Compendium.pf2e.classfeatures.Giant Instinct"
},
{
"flag": "giantInstinct",
Expand Down Expand Up @@ -3146,7 +3146,7 @@
}
],
"reevaluateOnUpdate": true,
"uuid": "Compendium.pf2e.feats-srd.xQMz6eDgX75WX2ce"
"uuid": "Compendium.pf2e.feats-srd.Intimidating Glare"
},
{
"flag": "scareToDeath",
Expand All @@ -3155,7 +3155,7 @@
"skill:itm:rank:4"
],
"reevaluateOnUpdate": true,
"uuid": "Compendium.pf2e.feats-srd.mZttsiWl1ql5NvrH"
"uuid": "Compendium.pf2e.feats-srd.Scare to Death"
}
],
"slug": "raging-intimidation",
Expand Down
Loading

0 comments on commit 79428f3

Please sign in to comment.