Skip to content

Commit

Permalink
Detach item system data from ItemData (foundryvtt#6778)
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed Mar 6, 2023
1 parent 5569045 commit c95795d
Show file tree
Hide file tree
Showing 61 changed files with 252 additions and 221 deletions.
2 changes: 1 addition & 1 deletion src/module/actor/character/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class CharacterSheetPF2e extends CreatureSheetPF2e<CharacterPF2e> {
const actorData = sheetData.actor;

// Actions
type AnnotatedAction = RawObject<ActionItemPF2e["data"]> & {
type AnnotatedAction = ActionItemPF2e & {
encounter?: boolean;
exploration?: boolean;
downtime?: boolean;
Expand Down
6 changes: 2 additions & 4 deletions src/module/actor/npc/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ interface NPCSource extends BaseCreatureSource<"npc", NPCSystemSource> {
}

interface NPCData
extends Omit<NPCSource, "prototypeToken" | "system" | "type">,
BaseCreatureData<NPCPF2e, "npc", NPCSource> {
flags: NPCFlags;
}
extends Omit<NPCSource, "flags" | "prototypeToken" | "system" | "type">,
BaseCreatureData<NPCPF2e, "npc", NPCSource> {}

type NPCFlags = ActorFlagsPF2e & {
pf2e: { lootable: boolean };
Expand Down
5 changes: 0 additions & 5 deletions src/module/chat-message/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,8 @@ class ChatMessagePF2e extends ChatMessage<ActorPF2e> {

interface ChatMessagePF2e extends ChatMessage<ActorPF2e> {
readonly data: ChatMessageDataPF2e<this>;

flags: ChatMessageFlagsPF2e;

blind: this["data"]["blind"];
type: this["data"]["type"];
whisper: this["data"]["whisper"];

get user(): UserPF2e;
}

Expand Down
7 changes: 4 additions & 3 deletions src/module/item/abc/document.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ItemPF2e, FeatPF2e } from "@item";
import type { AncestryData } from "@item/ancestry/data";
import type { BackgroundData } from "@item/background/data";
import type { ClassData } from "@item/class/data";
import type { AncestryData, AncestrySystemData } from "@item/ancestry/data";
import type { BackgroundData, BackgroundSystemData } from "@item/background/data";
import type { ClassData, ClassSystemData } from "@item/class/data";
import { MigrationList, MigrationRunner } from "@module/migration";
import { objectHasKey } from "@util";
import { UUIDUtils } from "@util/uuid-utils";
Expand Down Expand Up @@ -65,6 +65,7 @@ abstract class ABCItemPF2e extends ItemPF2e {

interface ABCItemPF2e extends ItemPF2e {
readonly data: AncestryData | BackgroundData | ClassData;
system: AncestrySystemData | BackgroundSystemData | ClassSystemData;
}

export { ABCItemPF2e };
10 changes: 6 additions & 4 deletions src/module/item/action/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { OneToThree } from "@module/data";

type ActionItemSource = BaseItemSourcePF2e<"action", ActionSystemSource>;

type ActionItemData = Omit<ActionItemSource, "system"> &
BaseItemDataPF2e<ActionItemPF2e, "action", ActionSystemData, ActionItemSource>;
interface ActionItemData
extends Omit<ActionItemSource, "flags" | "system" | "type">,
BaseItemDataPF2e<ActionItemPF2e, "action", ActionItemSource> {}

type ActionTrait = keyof ConfigPF2e["PF2E"]["actionTraits"];
interface ActionTraits extends ItemTraits<ActionTrait> {
Expand All @@ -40,10 +41,11 @@ interface ActionSystemSource extends ItemSystemSource {
};
deathNote: boolean;
frequency?: FrequencySource;
level?: never;
}

interface ActionSystemData extends ActionSystemSource, Omit<ItemSystemData, "traits"> {
interface ActionSystemData extends ActionSystemSource, Omit<ItemSystemData, "level" | "traits"> {
frequency?: Frequency;
}

export { ActionItemSource, ActionItemData, ActionTrait, ActionTraits };
export { ActionItemSource, ActionItemData, ActionSystemData, ActionTrait, ActionTraits };
3 changes: 2 additions & 1 deletion src/module/item/action/document.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ItemPF2e } from "@item/base";
import { ActionItemData, ActionItemSource } from "./data";
import { ActionItemData, ActionItemSource, ActionSystemData } from "./data";
import { UserPF2e } from "@module/user";
import { ActionCost, Frequency } from "@item/data/base";
import { ItemSummaryData } from "@item/data";
Expand Down Expand Up @@ -75,6 +75,7 @@ class ActionItemPF2e extends ItemPF2e {

interface ActionItemPF2e extends ItemPF2e {
readonly data: ActionItemData;
system: ActionSystemData;
}

export { ActionItemPF2e };
23 changes: 8 additions & 15 deletions src/module/item/affliction/data.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import { SaveType } from "@actor/types";
import { EffectAuraData, EffectContextData, EffectTraits, TimeUnit } from "@item/abstract-effect/data";
import { EffectAuraData, EffectContextData, EffectTraits, TimeUnit } from "@item/abstract-effect";
import { ConditionSlug } from "@item/condition";
import {
BaseItemDataPF2e,
BaseItemSourcePF2e,
ItemFlagsPF2e,
ItemLevelData,
ItemSystemData,
ItemSystemSource,
} from "@item/data/base";
import { BaseItemDataPF2e, BaseItemSourcePF2e, ItemFlagsPF2e, ItemSystemData, ItemSystemSource } from "@item/data/base";
import { DamageCategoryUnique, DamageType } from "@system/damage";
import { AfflictionPF2e } from "./document";

type AfflictionSource = BaseItemSourcePF2e<"affliction", AfflictionSystemSource> & {
flags: DeepPartial<AfflictionFlags>;
};

type AfflictionData = Omit<AfflictionSource, "system"> &
BaseItemDataPF2e<AfflictionPF2e, "affliction", AfflictionSystemData, AfflictionSource>;
interface AfflictionData
extends Omit<AfflictionSource, "flags" | "system" | "type">,
BaseItemDataPF2e<AfflictionPF2e, "affliction", AfflictionSource> {}

type AfflictionFlags = ItemFlagsPF2e & {
pf2e: {
aura?: EffectAuraData;
};
};

interface AfflictionSystemSource extends ItemSystemSource, ItemLevelData {
interface AfflictionSystemSource extends ItemSystemSource {
level: { value: number };
traits: EffectTraits;
save: {
type: SaveType;
Expand All @@ -43,7 +38,7 @@ interface AfflictionSystemSource extends ItemSystemSource, ItemLevelData {
context: EffectContextData | null;
}

interface AfflictionSystemData extends AfflictionSystemSource, Omit<ItemSystemData, "traits"> {}
interface AfflictionSystemData extends AfflictionSystemSource, Omit<ItemSystemData, "level" | "traits"> {}

interface AfflictionOnset {
value: number;
Expand All @@ -69,8 +64,6 @@ interface AfflictionConditionData {
value?: number;
}

interface AfflictionSystemData extends Omit<AfflictionSystemSource, "items">, Omit<ItemSystemData, "traits"> {}

export {
AfflictionConditionData,
AfflictionDamage,
Expand Down
3 changes: 2 additions & 1 deletion src/module/item/affliction/document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractEffectPF2e, EffectBadge } from "@item/abstract-effect";
import { UserPF2e } from "@module/user";
import { AfflictionData, AfflictionFlags } from "./data";
import { AfflictionData, AfflictionFlags, AfflictionSystemData } from "./data";

class AfflictionPF2e extends AbstractEffectPF2e {
override get badge(): EffectBadge {
Expand Down Expand Up @@ -53,6 +53,7 @@ class AfflictionPF2e extends AbstractEffectPF2e {
interface AfflictionPF2e extends AbstractEffectPF2e {
flags: AfflictionFlags;
readonly data: AfflictionData;
system: AfflictionSystemData;
}

export { AfflictionPF2e };
8 changes: 5 additions & 3 deletions src/module/item/ancestry/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import type { AncestryPF2e } from ".";

type AncestrySource = BaseItemSourcePF2e<"ancestry", AncestrySystemSource>;

type AncestryData = Omit<AncestrySource, "system"> &
BaseItemDataPF2e<AncestryPF2e, "ancestry", AncestrySystemData, AncestrySource>;
interface AncestryData
extends Omit<AncestrySource, "flags" | "system" | "type">,
BaseItemDataPF2e<AncestryPF2e, "ancestry", AncestrySource> {}

export type CreatureTraits = TraitsWithRarity<CreatureTrait>;

Expand All @@ -33,8 +34,9 @@ interface AncestrySystemSource extends ABCSystemSource {
size: Size;
reach: number;
vision: "normal" | "darkvision" | "lowLightVision";
level?: never;
}

interface AncestrySystemData extends Omit<AncestrySystemSource, "items">, Omit<ABCSystemData, "traits"> {}
interface AncestrySystemData extends Omit<AncestrySystemSource, "items">, Omit<ABCSystemData, "level" | "traits"> {}

export { AncestrySource, AncestryData, AncestrySystemData };
3 changes: 2 additions & 1 deletion src/module/item/ancestry/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AbilityString } from "@actor/types";
import { ABCItemPF2e, FeatPF2e } from "@item";
import { Size } from "@module/data";
import { sluggify } from "@util";
import { AncestryData } from "./data";
import { AncestryData, AncestrySystemData } from "./data";

class AncestryPF2e extends ABCItemPF2e {
get traits(): Set<CreatureTrait> {
Expand Down Expand Up @@ -136,6 +136,7 @@ class AncestryPF2e extends ABCItemPF2e {

interface AncestryPF2e extends ABCItemPF2e {
readonly data: AncestryData;
system: AncestrySystemData;
}

export { AncestryPF2e };
4 changes: 3 additions & 1 deletion src/module/item/armor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import {

type ArmorSource = BasePhysicalItemSource<"armor", ArmorSystemSource>;

type ArmorData = Omit<ArmorSource, "system"> & BasePhysicalItemData<ArmorPF2e, "armor", ArmorSystemData, ArmorSource>;
interface ArmorData
extends Omit<ArmorSource, "flags" | "system" | "type">,
BasePhysicalItemData<ArmorPF2e, "armor", ArmorSource> {}

interface ArmorSystemSource extends Investable<PhysicalSystemSource> {
traits: ArmorTraits;
Expand Down
3 changes: 2 additions & 1 deletion src/module/item/armor/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getResilientBonus, PhysicalItemHitPoints, PhysicalItemPF2e } from "@ite
import { MAGIC_TRADITIONS } from "@item/spell/values";
import { LocalizePF2e } from "@module/system/localize";
import { addSign, ErrorPF2e, setHasElement, sluggify } from "@util";
import { ArmorCategory, ArmorData, ArmorGroup, BaseArmorType } from ".";
import { ArmorCategory, ArmorData, ArmorGroup, ArmorSystemData, BaseArmorType } from ".";

class ArmorPF2e extends PhysicalItemPF2e {
override isStackableWith(item: PhysicalItemPF2e): boolean {
Expand Down Expand Up @@ -240,6 +240,7 @@ class ArmorPF2e extends PhysicalItemPF2e {

interface ArmorPF2e extends PhysicalItemPF2e {
readonly data: ArmorData;
system: ArmorSystemData;
}

export { ArmorPF2e };
10 changes: 6 additions & 4 deletions src/module/item/background/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { BackgroundPF2e } from ".";

type BackgroundSource = BaseItemSourcePF2e<"background", BackgroundSystemSource>;

type BackgroundData = Omit<BackgroundSource, "system"> &
BaseItemDataPF2e<BackgroundPF2e, "background", BackgroundSystemData, BackgroundSource>;
interface BackgroundData
extends Omit<BackgroundSource, "flags" | "system" | "type">,
BaseItemDataPF2e<BackgroundPF2e, "background", BackgroundSource> {}

interface BackgroundSystemSource extends ABCSystemSource {
traits: ItemTraits;
Expand All @@ -16,8 +17,9 @@ interface BackgroundSystemSource extends ABCSystemSource {
trainedSkills: {
value: SkillAbbreviation[];
};
level?: never;
}

interface BackgroundSystemData extends Omit<BackgroundSystemSource, "items">, Omit<ABCSystemData, "traits"> {}
interface BackgroundSystemData extends Omit<BackgroundSystemSource, "items">, Omit<ABCSystemData, "level" | "traits"> {}

export { BackgroundData, BackgroundSource };
export { BackgroundData, BackgroundSource, BackgroundSystemData };
3 changes: 2 additions & 1 deletion src/module/item/background/document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ABCItemPF2e, FeatPF2e, ItemPF2e } from "@item";
import { OneToFour } from "@module/data";
import { BackgroundData } from "./data";
import { BackgroundData, BackgroundSystemData } from "./data";

class BackgroundPF2e extends ABCItemPF2e {
/** Set a skill feat granted by a GrantItem RE as one of this background's configured items */
Expand Down Expand Up @@ -49,6 +49,7 @@ class BackgroundPF2e extends ABCItemPF2e {

interface BackgroundPF2e extends ABCItemPF2e {
readonly data: BackgroundData;
system: BackgroundSystemData;
}

export { BackgroundPF2e };
7 changes: 4 additions & 3 deletions src/module/item/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { PhysicalItemPF2e } from "./physical/document";
import { PHYSICAL_ITEM_TYPES } from "./physical/values";
import { ItemSheetPF2e } from "./sheet/base";
import { UUIDUtils } from "@util/uuid-utils";
import { ItemFlagsPF2e } from "./data/base";
import { ItemFlagsPF2e, ItemSystemData } from "./data/base";

/** Override and extend the basic :class:`Item` implementation */
class ItemPF2e extends Item<ActorPF2e> {
Expand Down Expand Up @@ -100,12 +100,12 @@ class ItemPF2e extends Item<ActorPF2e> {
...traitOptions.map((t) => `${prefix}:${t}`),
];

const level = "level" in this ? this.level : "level" in this.system ? this.system.level.value : null;
const level = this.system.level?.value ?? null;
if (typeof level === "number") {
options.push(`${prefix}:level:${level}`);
}

if (["item", ""].includes(prefix)) {
if (prefix === "item") {
const itemType = this.isOfType("feat") && this.isFeature ? "feature" : this.type;
options.unshift(`${prefix}:type:${itemType}`);
}
Expand Down Expand Up @@ -684,6 +684,7 @@ class ItemPF2e extends Item<ActorPF2e> {

interface ItemPF2e extends Item<ActorPF2e> {
flags: ItemFlagsPF2e;
readonly system: ItemSystemData;
readonly data: ItemDataPF2e;
readonly parent: ActorPF2e | null;

Expand Down
6 changes: 4 additions & 2 deletions src/module/item/book/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import type { BookPF2e } from "./document";

type BookSource = BasePhysicalItemSource<"book", BookSystemSource>;

type BookData = Omit<BookSource, "system"> & BasePhysicalItemData<BookPF2e, "book", BookSystemData, BookSource>;
interface BookData
extends Omit<BookSource, "flags" | "system" | "type">,
BasePhysicalItemData<BookPF2e, "book", BookSource> {}

type BookSystemSource = EquipmentSystemSource & {
capacity: number;
Expand All @@ -22,4 +24,4 @@ interface SpellBookData {
item: object[];
}

export { BookData, BookSource };
export { BookData, BookSource, BookSystemData };
3 changes: 2 additions & 1 deletion src/module/item/book/document.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { PhysicalItemPF2e } from "@item";
import { BookData } from "./data";
import { BookData, BookSystemData } from "./data";

class BookPF2e extends PhysicalItemPF2e {}

interface BookPF2e extends PhysicalItemPF2e {
readonly data: BookData;
system: BookSystemData;
}

export { BookPF2e };
5 changes: 4 additions & 1 deletion src/module/item/class/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { CLASS_TRAITS } from "./values";

type ClassSource = BaseItemSourcePF2e<"class", ClassSystemSource>;

type ClassData = Omit<ClassSource, "system"> & BaseItemDataPF2e<ClassPF2e, "class", ClassSystemData, ClassSource>;
interface ClassData
extends Omit<ClassSource, "flags" | "system" | "type">,
BaseItemDataPF2e<ClassPF2e, "class", ClassSource> {}

interface ClassSystemSource extends ABCSystemSource {
traits: ItemTraits;
Expand All @@ -27,6 +29,7 @@ interface ClassSystemSource extends ABCSystemSource {
generalFeatLevels: { value: number[] };
skillFeatLevels: { value: number[] };
skillIncreaseLevels: { value: number[] };
level?: never;
}

type ClassSystemData = ClassSystemSource;
Expand Down
3 changes: 2 additions & 1 deletion src/module/item/class/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ARMOR_CATEGORIES } from "@item/armor/values";
import { WEAPON_CATEGORIES } from "@item/weapon/values";
import { ZeroToFour } from "@module/data";
import { setHasElement, sluggify } from "@util";
import { ClassAttackProficiencies, ClassData, ClassDefenseProficiencies, ClassTrait } from "./data";
import { ClassAttackProficiencies, ClassData, ClassDefenseProficiencies, ClassSystemData, ClassTrait } from "./data";

class ClassPF2e extends ABCItemPF2e {
get attacks(): ClassAttackProficiencies {
Expand Down Expand Up @@ -152,6 +152,7 @@ class ClassPF2e extends ABCItemPF2e {

interface ClassPF2e extends ABCItemPF2e {
readonly data: ClassData;
system: ClassSystemData;

get slug(): ClassTrait | null;
}
Expand Down
8 changes: 5 additions & 3 deletions src/module/item/condition/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { ConditionPF2e } from ".";

type ConditionSource = BaseItemSourcePF2e<"condition", ConditionSystemSource>;

type ConditionData = Omit<ConditionSource, "system"> &
BaseItemDataPF2e<ConditionPF2e, "condition", ConditionSystemData, ConditionSource>;
interface ConditionData
extends Omit<ConditionSource, "flags" | "system" | "type">,
BaseItemDataPF2e<ConditionPF2e, "condition", ConditionSource> {}

interface ConditionSystemSource extends ItemSystemSource {
slug: ConditionSlug;
Expand All @@ -25,10 +26,11 @@ interface ConditionSystemSource extends ItemSystemSource {
group: string | null;
value: ConditionValueData;
overrides: string[];
level?: never;
traits?: never;
}

interface ConditionSystemData extends ConditionSystemSource, Omit<ItemSystemData, "traits" | "slug"> {
interface ConditionSystemData extends ConditionSystemSource, Omit<ItemSystemData, "level" | "slug" | "traits"> {
persistent?: PersistentDamageData;
}

Expand Down
Loading

0 comments on commit c95795d

Please sign in to comment.