Skip to content

Commit

Permalink
Prune and reorganize several areas of spell data (foundryvtt#11026)
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed Nov 10, 2023
1 parent 8739586 commit 82182d2
Show file tree
Hide file tree
Showing 40 changed files with 1,090 additions and 921 deletions.
5 changes: 0 additions & 5 deletions build/lib/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,6 @@ class PackExtractor {
if (!source.system.onlyLevel1) {
delete (source.system as { onlyLevel1?: boolean }).onlyLevel1;
}
} else if (source.type === "spell") {
const components: Record<string, boolean> = source.system.components;
for (const [key, value] of Object.entries(components)) {
if (value === false) delete components[key];
}
} else if (source.type === "spellcastingEntry" && this.#lastActor?.type === "npc") {
delete (source.system as { ability?: unknown }).ability;
}
Expand Down
4 changes: 2 additions & 2 deletions build/run-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { getFilesRecursively } from "./lib/helpers.ts";
import { MigrationBase } from "@module/migration/base.ts";
import { MigrationRunnerBase } from "@module/migration/runner/base.ts";

import { Migration860RMGroup } from "@module/migration/migrations/860-rm-group.ts";
import { Migration862SpecificMagicArmor } from "@module/migration/migrations/862-specific-magic-armor.ts";
import { Migration863FixMisspelledOrganaizationsProperty } from "@module/migration/migrations/863-fix-misspelled-organaizations-property.ts";
import { Migration864RemoveWeaponMAP } from "@module/migration/migrations/864-rm-weapon-map.ts";
Expand All @@ -26,6 +25,7 @@ import { Migration876FeatLevelTaken } from "@module/migration/migrations/876-fea
import { Migration877PublicationData } from "@module/migration/migrations/877-publication-data.ts";
import { Migration878TakeABreather } from "@module/migration/migrations/878-take-a-breather.ts";
import { Migration879DeviseAStratagemAndFriends } from "@module/migration/migrations/879-devise-a-stratagem-and-friends.ts";
import { Migration882SpellDataReorganization } from "@module/migration/migrations/882-spell-data-reorganization.ts";
// ^^^ don't let your IDE use the index in these imports. you need to specify the full path ^^^

const { window } = new JSDOM();
Expand All @@ -35,7 +35,6 @@ globalThis.HTMLParagraphElement = window.HTMLParagraphElement;
globalThis.Text = window.Text;

const migrations: MigrationBase[] = [
new Migration860RMGroup(),
new Migration862SpecificMagicArmor(),
new Migration863FixMisspelledOrganaizationsProperty(),
new Migration864RemoveWeaponMAP(),
Expand All @@ -51,6 +50,7 @@ const migrations: MigrationBase[] = [
new Migration877PublicationData(),
new Migration878TakeABreather(),
new Migration879DeviseAStratagemAndFriends(),
new Migration882SpellDataReorganization(),
];

global.deepClone = <T>(original: T): T => {
Expand Down
1 change: 0 additions & 1 deletion src/module/actor/creature/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ function setImmunitiesFromTraits(actor: CreaturePF2e): void {
"drained",
"fatigued",
"healing",
"necromancy",
"nonlethal-attacks",
"paralyzed",
"poison",
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/sheet/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function onClickCreateSpell(actor: ActorPF2e, data: Record<string, unknown>): vo
rank > 0
? [
game.i18n.format("PF2E.Item.Spell.Rank.Ordinal", { rank: ordinalString(rank) }),
game.i18n.localize(data.location === "rituals" ? "PF2E.SpellCategoryRitual" : "PF2E.SpellLabel"),
game.i18n.localize(data.location === "rituals" ? "PF2E.Item.Spell.Ritual.Label" : "TYPES.Item.spell"),
]
: [null, game.i18n.localize("PF2E.TraitCantrip")];
const source = {
Expand Down
31 changes: 4 additions & 27 deletions src/module/apps/compendium-browser/tabs/spell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@ export class CompendiumBrowserSpellTab extends CompendiumBrowserTab {

/* MiniSearch */
override searchFields = ["name"];
override storeFields = [
"type",
"name",
"img",
"uuid",
"level",
"time",
"category",
"traditions",
"traits",
"rarity",
"source",
];
override storeFields = ["type", "name", "img", "uuid", "level", "time", "traditions", "traits", "rarity", "source"];

constructor(browser: CompendiumBrowser) {
super(browser);
Expand All @@ -41,11 +29,11 @@ export class CompendiumBrowserSpellTab extends CompendiumBrowserTab {
const indexFields = [
"img",
"system.level.value",
"system.category.value",
"system.traditions.value",
"system.traits.traditions",
"system.time",
"system.traits",
"system.publication",
"system.ritual",
"system.source",
];

Expand All @@ -62,10 +50,6 @@ export class CompendiumBrowserSpellTab extends CompendiumBrowserTab {
);
continue;
}
// Set category of cantrips to "cantrip" until migration can be done
if (spellData.system.traits.value.includes("cantrip")) {
spellData.system.category.value = "cantrip";
}

// recording casting times
let time = spellData.system.time.value;
Expand Down Expand Up @@ -101,8 +85,7 @@ export class CompendiumBrowserSpellTab extends CompendiumBrowserTab {
uuid: `Compendium.${pack.collection}.${spellData._id}`,
level: spellData.system.level.value,
time: spellData.system.time,
category: spellData.system.category.value,
traditions: spellData.system.traditions.value,
traditions: spellData.system.traits.traditions,
traits: spellData.system.traits.value.map((t: string) => t.replace(/^hb_/, "")),
rarity: spellData.system.traits.rarity,
source: sourceSlug,
Expand All @@ -114,8 +97,6 @@ export class CompendiumBrowserSpellTab extends CompendiumBrowserTab {
this.indexData = spells;

// Filters
this.filterData.checkboxes.category.options = this.generateCheckboxOptions(CONFIG.PF2E.spellCategories);
this.filterData.checkboxes.category.options.cantrip = { label: "PF2E.TraitCantrip", selected: false };
this.filterData.checkboxes.traditions.options = this.generateCheckboxOptions(CONFIG.PF2E.magicTraditions);
// Special case for spell ranks
for (let rank = 1; rank <= 10; rank++) {
Expand Down Expand Up @@ -151,10 +132,6 @@ export class CompendiumBrowserSpellTab extends CompendiumBrowserTab {
if (selects.timefilter.selected) {
if (!(selects.timefilter.selected === entry.time.value)) return false;
}
// Category
if (checkboxes.category.selected.length) {
if (!checkboxes.category.selected.includes(entry.category)) return false;
}
// Traditions
if (checkboxes.traditions.selected.length) {
if (!this.arrayIncludes(checkboxes.traditions.selected, entry.traditions)) return false;
Expand Down
14 changes: 9 additions & 5 deletions src/module/item/armor/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,17 @@ class ArmorPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Phy
this.prepareRunes();

// Add traits from fundamental runes
const abpEnabled = ABP.isEnabled(this.actor);
const baseTraits = this.system.traits.value;
const fromRunes: ("invested" | "abjuration")[] =
this.system.runes.potency || this.system.runes.resilient ? ["invested", "abjuration"] : [];
const investedTrait =
this.system.runes.potency ||
this.system.runes.resilient ||
(abpEnabled && this.system.runes.property.length > 0)
? "invested"
: null;
const hasTraditionTraits = baseTraits.some((t) => setHasElement(MAGIC_TRADITIONS, t));
const magicTraits: "magical"[] = fromRunes.length > 0 && !hasTraditionTraits ? ["magical"] : [];

this.system.traits.value = R.uniq([baseTraits, fromRunes, magicTraits].flat()).sort();
const magicTrait = investedTrait && !hasTraditionTraits ? "magical" : null;
this.system.traits.value = R.uniq(R.compact([...baseTraits, investedTrait, magicTrait]).sort());
}

override prepareDerivedData(): void {
Expand Down
Loading

0 comments on commit 82182d2

Please sign in to comment.