Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove most category getters from non-document spellcasting entries #17977

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/module/actor/creature/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ abstract class CreaturePF2e<
// PC1 p.298, When you gain an innate spell, you become trained in the spell attack modifier
// and spell DC statistics. At 12th level, these proficiencies increase to expert.
const actualSpellcasting = this.spellcasting.filter((e) => e.system && !e.system?.proficiency.slug);
if (actualSpellcasting.some((e) => e.isInnate)) {
if (actualSpellcasting.some((e) => e.category === "innate")) {
spellcasting.rank = Math.max(spellcasting.rank, this.level >= 12 ? 2 : 1) as ZeroToFour;
} else if (actualSpellcasting.length) {
// If you can cast spells using spellcasting prof, you logically need to be at least trained
Expand All @@ -392,10 +392,8 @@ abstract class CreaturePF2e<
}

protected override prepareDataFromItems(): void {
this.spellcasting = new ActorSpellcasting(this, [
...this.itemTypes.spellcastingEntry,
new RitualSpellcasting(this),
]);
this.spellcasting ??= new ActorSpellcasting(this);
this.spellcasting.initialize([...this.itemTypes.spellcastingEntry, new RitualSpellcasting(this)]);

super.prepareDataFromItems();
}
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/creature/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ abstract class CreatureSheetPF2e<TActor extends CreaturePF2e> extends ActorSheet
// Confirm whether this is a swap and execute if so
const { collectionId, groupId, slotIndex } = spellFrom;
const collection = this.actor.spellcasting.collections.get(spellFrom.collectionId, { strict: true });
const isPrepared = collection.entry.isPrepared;
const isPrepared = collection.entry.category === "prepared";
const collectionEl = htmlClosest(event.target, "[data-container-id]");
const sameCollectionId = collectionId === collectionEl?.dataset.containerId;

Expand Down
13 changes: 11 additions & 2 deletions src/module/actor/spellcasting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ export class ActorSpellcasting<TActor extends ActorPF2e> extends DelegatedCollec
/** Cache of trick magic item entries */
#trickEntries: Record<string, BaseSpellcastingEntry<TActor> | undefined> = {};

constructor(actor: TActor, entries: BaseSpellcastingEntry<TActor>[]) {
super(entries.map((entry) => [entry.id, entry]));
constructor(actor: TActor) {
super();
this.actor = actor;
}

/** Initializes spellcasting data. Must be called every data preparation */
initialize(entries: BaseSpellcastingEntry<TActor>[]): void {
this.clear();
for (const entry of entries) {
this.set(entry.id, entry);
}

this.collections.clear();
for (const entry of entries) {
if (entry.spells) this.collections.set(entry.spells.id, entry.spells);
}
Expand Down
6 changes: 3 additions & 3 deletions src/module/apps/compendium-browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class CompendiumBrowser extends SvelteApplicationMixin(foundry.applications.api.
filter.checkboxes.category.selected.push(category);
}

if (entry.isRitual || entry.isFocusPool) {
if (entry.category === "ritual" || entry.isFocusPool) {
filter.checkboxes.category.options[entry.category].selected = true;
filter.checkboxes.category.selected.push(entry.category);
}
Expand All @@ -247,13 +247,13 @@ class CompendiumBrowser extends SvelteApplicationMixin(foundry.applications.api.
filter.checkboxes.rank.options[rank].selected = true;
filter.checkboxes.rank.selected.push(rank);
}
if ((entry.isPrepared || entry.isSpontaneous || entry.isInnate) && !category) {
if (["prepared", "spontaneous", "innate"].includes(entry.category) && !category) {
filter.checkboxes.category.options["spell"].selected = true;
filter.checkboxes.category.selected.push("spell");
}
}

if (entry.tradition && !entry.isFocusPool && !entry.isRitual) {
if (entry.tradition && !entry.isFocusPool && entry.category !== "ritual") {
traditions.options[entry.tradition].selected = true;
traditions.selected.push(entry.tradition);
}
Expand Down
6 changes: 3 additions & 3 deletions src/module/item/spell/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class SpellPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Ite
}

override prepareSiblingData(this: SpellPF2e<ActorPF2e>): void {
if (this.spellcasting?.isInnate) {
if (this.spellcasting?.category === "innate") {
fu.mergeObject(this.system.location, { uses: { value: 1, max: 1 } }, { overwrite: false });
}
}
Expand Down Expand Up @@ -706,7 +706,7 @@ class SpellPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Ite
spellOptions.add(`${prefix}:trait:${spellcasting.tradition}`);
}

const entryHasSlots = !!(spellcasting?.isPrepared || spellcasting?.isSpontaneous);
const entryHasSlots = ["prepared", "spontaneous"].includes(spellcasting?.category ?? "");
if (entryHasSlots && !this.isCantrip && !this.parentItem) {
spellOptions.add(`${prefix}:spell-slot`);
}
Expand All @@ -725,7 +725,7 @@ class SpellPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Ite
spellOptions.add(`${prefix}:frequency:limited`);
}

if (spellcasting?.isSpontaneous && this.system.location.signature) {
if (spellcasting?.category === "spontaneous" && this.system.location.signature) {
spellOptions.add(`${prefix}:signature`);
}

Expand Down
9 changes: 5 additions & 4 deletions src/module/item/spellcasting-entry/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SpellCollection<TActor extends ActorPF2e> extends Collection<SpellPF2e<TAc
}

const isStandardSpell = !(spell.isCantrip || spell.isFocusSpell || spell.isRitual);
const canHeighten = isStandardSpell && (this.entry.isSpontaneous || this.entry.isInnate);
const canHeighten = isStandardSpell && ["innate", "spontaneous"].includes(this.entry.category);

// Only allow a different slot rank if the spell can heighten
const groupId = options?.groupId;
Expand Down Expand Up @@ -246,6 +246,7 @@ class SpellCollection<TActor extends ActorPF2e> extends Collection<SpellPF2e<TAc
// Everything else (Innate/Spontaneous/Ritual)
const alwaysShowHeader = !this.entry.isRitual;
const spellsByRank = groupBy(spells, (spell) => (spell.isCantrip ? 0 : spell.rank));
const isInnate = this.entry.category === "innate";
for (let rank = 0 as ZeroToTen; rank <= this.highestRank; rank++) {
const data = this.entry.system.slots[`slot${rank}`];
const spells = spellsByRank.get(rank) ?? [];
Expand All @@ -254,8 +255,8 @@ class SpellCollection<TActor extends ActorPF2e> extends Collection<SpellPF2e<TAc
this.entry.isSpontaneous && rank !== 0 ? { value: data.value, max: data.max } : undefined;
const active = spells.map((spell) => ({
spell,
expended: this.entry.isInnate && !spell.system.location.uses?.value,
uses: this.entry.isInnate && !spell.atWill ? spell.system.location.uses : undefined,
expended: isInnate && !spell.system.location.uses?.value,
uses: isInnate && !spell.atWill ? spell.system.location.uses : undefined,
}));

// These entries hide if there are no active spells at that level, or if there are no spell slots
Expand Down Expand Up @@ -349,7 +350,7 @@ class SpellCollection<TActor extends ActorPF2e> extends Collection<SpellPF2e<TAc
protected getSpellPrepList(spells: SpellPF2e<TActor>[]): Record<ZeroToTen, SpellPrepEntry[]> {
const indices = Array.fromRange(11) as ZeroToTen[];
const prepList: Record<ZeroToTen, SpellPrepEntry[]> = R.mapToObj(indices, (i) => [i, []]);
if (!this.entry.isPrepared) return prepList;
if (this.entry.category !== "prepared") return prepList;

for (const spell of spells) {
if (spell.isCantrip) {
Expand Down
29 changes: 1 addition & 28 deletions src/module/item/spellcasting-entry/item-spellcasting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ class ItemSpellcasting<TActor extends CreaturePF2e = CreaturePF2e> implements Sp
return false;
}

get isInnate(): false {
return false;
}

get isPrepared(): false {
return false;
}

get isSpontaneous(): false {
return false;
}

get isRitual(): false {
return false;
}

get isEphemeral(): true {
return true;
}
Expand All @@ -103,18 +87,7 @@ class ItemSpellcasting<TActor extends CreaturePF2e = CreaturePF2e> implements Sp
const collectionData: SpellCollectionData = (await spells?.getSpellData()) ?? { groups: [], prepList: null };

return {
...R.pick(this, [
"category",
"tradition",
"sort",
"isFlexible",
"isFocusPool",
"isInnate",
"isPrepared",
"isRitual",
"isSpontaneous",
"isEphemeral",
]),
...R.pick(this, ["category", "tradition", "sort", "isFlexible", "isFocusPool", "isEphemeral"]),
...collectionData,
id: spells?.id ?? this.id,
name: spells?.name ?? this.name,
Expand Down
12 changes: 0 additions & 12 deletions src/module/item/spellcasting-entry/rituals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,10 @@ export class RitualSpellcasting<TActor extends ActorPF2e> implements BaseSpellca
return false;
}

get isInnate(): false {
return false;
}

get isPrepared(): false {
return false;
}

get isRitual(): true {
return true;
}

get isSpontaneous(): false {
return false;
}

get isEphemeral(): true {
return true;
}
Expand Down
16 changes: 0 additions & 16 deletions src/module/item/spellcasting-entry/trick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,6 @@ class TrickMagicItemEntry<TActor extends ActorPF2e = ActorPF2e> implements Spell
return false;
}

get isInnate(): false {
return false;
}

get isPrepared(): false {
return false;
}

get isRitual(): false {
return false;
}

get isSpontaneous(): false {
return false;
}

get isEphemeral(): true {
return true;
}
Expand Down
4 changes: 0 additions & 4 deletions src/module/item/spellcasting-entry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ interface BaseSpellcastingEntry<TActor extends ActorPF2e | null = ActorPF2e | nu
attribute?: Maybe<AttributeString>;
isFlexible: boolean;
isFocusPool: boolean;
isInnate: boolean;
isPrepared: boolean;
isRitual: boolean;
isSpontaneous: boolean;
isEphemeral: boolean;
statistic?: Statistic | null;
/** A related but more-limited statistic for making counteract checks */
Expand Down
Loading