Skip to content

Commit

Permalink
Recursively propagate feat traits to effect traits (#15105)
Browse files Browse the repository at this point in the history
Recursively propagate to effect traits
  • Loading branch information
CarlosFdez committed Jun 16, 2024
1 parent a0dc318 commit 8a6155e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/module/system/settings/homebrew/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const HOMEBREW_TRAIT_KEYS = [

/** Homebrew elements from some of the above records are propagated to related records */
const TRAIT_PROPAGATIONS = {
actionTraits: ["effectTraits"],
creatureTraits: ["ancestryTraits"],
equipmentTraits: ["armorTraits", "consumableTraits"],
featTraits: ["actionTraits", "effectTraits"],
featTraits: ["actionTraits"],
weaponTraits: ["npcAttackTraits"],
} as const;

Expand Down
21 changes: 11 additions & 10 deletions src/module/system/settings/homebrew/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ class HomebrewElements extends SettingsMenuPF2e {
}
}

#getAllTraitPropagations(listKey: string): ValueOf<typeof TRAIT_PROPAGATIONS>[number][] {
if (!objectHasKey(TRAIT_PROPAGATIONS, listKey)) return [];
return TRAIT_PROPAGATIONS[listKey].flatMap((p) => [p, ...this.#getAllTraitPropagations(p)]);
}

/** Prepare and run a migration for each set of tag deletions from a tag map */
#processDeletions(listKey: HomebrewTraitKey, newTagList: HomebrewTag[]): MigrationBase | null {
const oldTagList = game.settings.get("pf2e", `homebrew.${listKey}`);
Expand All @@ -303,11 +308,9 @@ class HomebrewElements extends SettingsMenuPF2e {
listKey === "baseWeapons" ? CONFIG.PF2E.baseWeaponTypes : CONFIG.PF2E[listKey];
for (const id of deletions) {
delete coreElements[id];
if (objectHasKey(TRAIT_PROPAGATIONS, listKey)) {
for (const recordKey of TRAIT_PROPAGATIONS[listKey]) {
const secondaryRecord: Record<string, string> = CONFIG.PF2E[recordKey];
delete secondaryRecord[id];
}
for (const recordKey of this.#getAllTraitPropagations(listKey)) {
const secondaryRecord: Record<string, string> = CONFIG.PF2E[recordKey];
delete secondaryRecord[id];
}
}

Expand Down Expand Up @@ -396,11 +399,9 @@ class HomebrewElements extends SettingsMenuPF2e {
const coreElements: Record<string, string> = this.#getConfigRecord(listKey);
for (const element of elements) {
coreElements[element.id] = element.value;
if (objectHasKey(TRAIT_PROPAGATIONS, listKey)) {
for (const recordKey of TRAIT_PROPAGATIONS[listKey]) {
const record: Record<string, string> = CONFIG.PF2E[recordKey];
record[element.id] = element.value;
}
for (const recordKey of this.#getAllTraitPropagations(listKey)) {
const record: Record<string, string> = CONFIG.PF2E[recordKey];
record[element.id] = element.value;
}
}
}
Expand Down

0 comments on commit 8a6155e

Please sign in to comment.