Skip to content
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
168 changes: 161 additions & 7 deletions src/module/item/ancestry/data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { CreatureTrait, Language } from "@actor/creature/index.ts";
import { AttributeString } from "@actor/types.ts";
import { ABCSystemData, ABCSystemSource } from "@item/abc/index.ts";
import { BaseItemSourcePF2e, ItemTraits } from "@item/base/data/system.ts";
import { Size, TraitsWithRarity, ValuesList } from "@module/data.ts";
import type { CreatureTrait, Language } from "@actor/creature/index.ts";
import type { AttributeString } from "@actor/types.ts";
import { ATTRIBUTE_ABBREVIATIONS } from "@actor/values.ts";
import { ABCFeatureEntryField, type ABCSystemSource } from "@item/abc/index.ts";
import { ItemSystemModel, type ItemSystemSchema } from "@item/base/data/model.ts";
import type { BaseItemSourcePF2e, ItemTraits } from "@item/base/data/system.ts";
import { SIZES, type Size, type TraitsWithRarity, type ValuesList } from "@module/data.ts";
import { RarityField } from "@module/model.ts";
import { RecordField, SlugField } from "@system/schema-data-fields.ts";
import type { AncestryPF2e } from "./document.ts";
import fields = foundry.data.fields;

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

Expand Down Expand Up @@ -40,7 +46,155 @@ interface AncestrySystemSource extends ABCSystemSource {
level?: never;
}

class AncestrySystemData extends ItemSystemModel<AncestryPF2e, AncestrySystemSchema> {
static override defineSchema(): AncestrySystemSchema {
return {
...super.defineSchema(),
traits: new fields.SchemaField({
otherTags: new fields.ArrayField(
new SlugField({ required: true, nullable: false, initial: undefined }),
),
rarity: new RarityField(),
value: new fields.ArrayField(new fields.StringField({ required: true, blank: false })),
}),
items: new RecordField(
new fields.StringField({ required: true, nullable: false }),
new ABCFeatureEntryField(),
),
additionalLanguages: new fields.SchemaField({
count: new fields.NumberField({ nullable: false, initial: 1 }),
value: new fields.ArrayField(new fields.StringField({ required: true, blank: false })),
custom: new fields.StringField(),
}),
alternateAncestryBoosts: new fields.ArrayField(
new fields.StringField({ required: true, nullable: false, choices: [...ATTRIBUTE_ABBREVIATIONS] }),
),
boosts: new RecordField(
new fields.StringField({ required: true, nullable: false }),
new fields.SchemaField({
value: new fields.ArrayField(
new fields.StringField({ choices: [...ATTRIBUTE_ABBREVIATIONS], required: true }),
),
selected: new fields.StringField({ nullable: true }),
}),
),
flaws: new RecordField(
new fields.StringField({ required: true, nullable: false }),
new fields.SchemaField({
value: new fields.ArrayField(
new fields.StringField({ choices: [...ATTRIBUTE_ABBREVIATIONS], required: true }),
),
selected: new fields.StringField({ nullable: true }),
}),
),
voluntary: new fields.SchemaField(
{
boost: new fields.StringField({
nullable: true,
required: false,
initial: undefined,
choices: [...ATTRIBUTE_ABBREVIATIONS],
}),
flaws: new fields.ArrayField(
new fields.StringField({ choices: [...ATTRIBUTE_ABBREVIATIONS], required: true }),
),
},
{ required: false, initial: undefined },
),
hp: new fields.NumberField({ required: true, initial: 6, min: 0, max: 12, step: 2, nullable: false }),
languages: new fields.SchemaField({
value: new fields.ArrayField(new fields.StringField({ required: true, blank: false })),
}),
speed: new fields.NumberField({ required: true, initial: 25, min: 0, max: 60, step: 5, nullable: false }),
size: new fields.StringField({ required: true, nullable: false, initial: "med", choices: [...SIZES] }),
hands: new fields.NumberField({ required: true, initial: 2, min: 0, max: 12, step: 2, nullable: false }),
reach: new fields.NumberField({ required: true, initial: 5, min: 0, max: 25, step: 5, nullable: false }),
vision: new fields.StringField({
required: true,
nullable: false,
initial: "normal",
choices: ["normal", "darkvision", "low-light-vision"],
}),
};
}
}

type BoostOrFlawSchema = {
value: fields.ArrayField<fields.StringField<AttributeString, AttributeString, true, false, false>>;
selected: fields.StringField<AttributeString, AttributeString, false, true, false>;
};

type AncestrySystemSchema = Omit<ItemSystemSchema, "traits"> & {
traits: fields.SchemaField<{
otherTags: fields.ArrayField<SlugField<true, false, false>>;
rarity: RarityField;
value: fields.ArrayField<fields.StringField<CreatureTrait, CreatureTrait, true, false, false>>;
}>;
items: RecordField<fields.StringField<string, string, true, false>, ABCFeatureEntryField, true, false, true, true>;
additionalLanguages: fields.SchemaField<{
count: fields.NumberField<number, number, false, false, true>;
value: fields.ArrayField<fields.StringField<string, string, true, false, false>>;
custom: fields.StringField;
}>;
alternateAncestryBoosts: fields.ArrayField<
fields.StringField<AttributeString, AttributeString, true, false, false>
>;
boosts: RecordField<
fields.StringField<string, string, true, false>,
fields.SchemaField<BoostOrFlawSchema>,
true,
false,
true,
true
>;
flaws: RecordField<
fields.StringField<string, string, true, false>,
fields.SchemaField<BoostOrFlawSchema>,
true,
false,
true,
true
>;
voluntary: fields.SchemaField<
{
boost?: fields.StringField<AttributeString, AttributeString, false, true, false>;
flaws: fields.ArrayField<fields.StringField<AttributeString, AttributeString, true, false, false>>;
},
{
boost?: AttributeString | null;
flaws: AttributeString[];
},
{
boost?: AttributeString | null;
flaws: AttributeString[];
},
false,
false,
false
>;
hp: fields.NumberField<number, number, true, false, true>;
languages: fields.SchemaField<{
value: fields.ArrayField<fields.StringField<Language, Language, true, false, false>>;
}>;
speed: fields.NumberField<number, number, true, false, true>;
size: fields.StringField<Size, Size, true, false, true>;
hands: fields.NumberField<number, number, true, false, true>;
reach: fields.NumberField<number, number, true, false, true>;
vision: fields.StringField<
"normal" | "darkvision" | "low-light-vision",
"normal" | "darkvision" | "low-light-vision",
true,
false,
true
>;
};

interface AncestrySystemData
extends Omit<AncestrySystemSource, "description" | "items">, Omit<ABCSystemData, "level" | "traits"> {}
extends
ItemSystemModel<AncestryPF2e, AncestrySystemSchema>,
Omit<fields.ModelPropsFromSchema<AncestrySystemSchema>, "description" | "traits" | "level"> {
traits: AncestryTraits;
}

export type { AncestrySource, AncestrySystemData, AncestrySystemSource, AncestryTraits, CreatureTraits };
export { AncestrySystemData };
export type { AncestrySource, AncestrySystemSource, AncestryTraits, CreatureTraits };
2 changes: 2 additions & 0 deletions src/scripts/hooks/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { VehicleSystemData } from "@actor/vehicle/data.ts";
import { ItemProxyPF2e } from "@item";
import { AbilitySystemData } from "@item/ability/index.ts";
import { AfflictionSystemData } from "@item/affliction/data.ts";
import { AncestrySystemData } from "@item/ancestry/data.ts";
import { CampaignFeatureSystemData } from "@item/campaign-feature/data.ts";
import { ClassSystemData } from "@item/class/data.ts";
import { ConditionSystemData } from "@item/condition/data.ts";
Expand Down Expand Up @@ -117,6 +118,7 @@ export class Load {
CONFIG.Item.dataModels.affliction = AfflictionSystemData;
}
CONFIG.Item.dataModels.action = AbilitySystemData;
CONFIG.Item.dataModels.ancestry = AncestrySystemData;
CONFIG.Item.dataModels.campaignFeature = CampaignFeatureSystemData;
CONFIG.Item.dataModels.class = ClassSystemData;
CONFIG.Item.dataModels.condition = ConditionSystemData;
Expand Down
Loading