-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert familiar system data to
TypeDataModel
(#16999)
- Loading branch information
Showing
16 changed files
with
210 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { ActorPF2e } from "@actor"; | ||
import type { MigrationDataField } from "@module/data.ts"; | ||
import type { AutoChangeEntry } from "@module/rules/rule-element/ae-like.ts"; | ||
|
||
abstract class ActorSystemModel<TParent extends ActorPF2e, TSchema extends ActorSystemSchema> extends foundry.abstract | ||
.TypeDataModel<TParent, TSchema> { | ||
declare autoChanges: Record<string, AutoChangeEntry[] | undefined>; | ||
|
||
static override defineSchema(): ActorSystemSchema { | ||
const fields = foundry.data.fields; | ||
return { | ||
_migration: new fields.SchemaField({ | ||
version: new fields.NumberField({ | ||
required: true, | ||
nullable: true, | ||
positive: true, | ||
initial: null, | ||
}), | ||
previous: new fields.SchemaField( | ||
{ | ||
foundry: new fields.StringField({ required: true, nullable: true, initial: null }), | ||
system: new fields.StringField({ required: true, nullable: true, initial: null }), | ||
schema: new fields.NumberField({ | ||
required: true, | ||
nullable: true, | ||
positive: true, | ||
initial: null, | ||
}), | ||
}, | ||
{ required: true, nullable: true, initial: null }, | ||
), | ||
}), | ||
}; | ||
} | ||
} | ||
|
||
type ActorSystemSchema = { | ||
_migration: MigrationDataField; | ||
}; | ||
|
||
export { ActorSystemModel, type ActorSystemSchema }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,137 @@ | ||
import { | ||
import { ActorPF2e } from "@actor"; | ||
import type { | ||
BaseCreatureSource, | ||
CreatureAttributes, | ||
CreatureDetails, | ||
CreatureDetailsSource, | ||
CreatureSystemData, | ||
CreatureSystemSource, | ||
CreatureLanguagesData, | ||
CreaturePerceptionData, | ||
CreatureResources, | ||
CreatureSaves, | ||
CreatureTraitsData, | ||
SkillData, | ||
} from "@actor/creature/data.ts"; | ||
import { AttributeString } from "@actor/types.ts"; | ||
import { StatisticTraceData } from "@system/statistic/index.ts"; | ||
import { ActorSystemModel, ActorSystemSchema } from "@actor/data/model.ts"; | ||
import type { ModifierPF2e } from "@actor/modifiers.ts"; | ||
import type { AttributeString } from "@actor/types.ts"; | ||
import { ATTRIBUTE_ABBREVIATIONS } from "@actor/values.ts"; | ||
import type { StatisticTraceData } from "@system/statistic/data.ts"; | ||
import type { ModelPropFromDataField, SourcePropFromDataField } from "types/foundry/common/data/fields.d.ts"; | ||
import type { FamiliarPF2e } from "./document.ts"; | ||
import fields = foundry.data.fields; | ||
|
||
type FamiliarSource = BaseCreatureSource<"familiar", FamiliarSystemSource>; | ||
|
||
interface FamiliarSystemSource extends CreatureSystemSource { | ||
details: FamiliarDetailsSource; | ||
attributes: FamiliarAttributesSource; | ||
master: { | ||
id: string | null; | ||
ability: AttributeString | null; | ||
}; | ||
class FamiliarSystemData extends ActorSystemModel<FamiliarPF2e, FamiliarSystemSchema> { | ||
declare traits: CreatureTraitsData; | ||
|
||
declare perception: CreaturePerceptionData; | ||
|
||
declare saves: CreatureSaves; | ||
|
||
declare skills: Record<string, SkillData>; | ||
|
||
declare attack: StatisticTraceData; | ||
|
||
declare resources: CreatureResources; | ||
|
||
static override defineSchema(): FamiliarSystemSchema { | ||
return { | ||
...super.defineSchema(), | ||
master: new fields.SchemaField({ | ||
id: new fields.ForeignDocumentField(ActorPF2e, { | ||
idOnly: true, | ||
required: true, | ||
nullable: true, | ||
initial: null, | ||
}), | ||
ability: new fields.StringField({ | ||
required: true, | ||
nullable: true, | ||
choices: Array.from(ATTRIBUTE_ABBREVIATIONS), | ||
initial: null, | ||
}), | ||
}), | ||
attributes: new fields.SchemaField({ | ||
hp: new fields.SchemaField({ | ||
value: new fields.NumberField({ | ||
required: true, | ||
nullable: false, | ||
integer: true, | ||
min: 0, | ||
initial: 5, | ||
}), | ||
temp: new fields.NumberField({ | ||
required: true, | ||
nullable: false, | ||
integer: true, | ||
min: 0, | ||
initial: 0, | ||
}), | ||
}), | ||
}), | ||
details: new fields.SchemaField({ | ||
creature: new fields.SchemaField({ | ||
value: new fields.StringField({ required: true, nullable: false, blank: true, initial: "" }), | ||
}), | ||
}), | ||
}; | ||
} | ||
} | ||
|
||
interface FamiliarSystemData | ||
extends foundry.abstract.TypeDataModel<FamiliarPF2e, FamiliarSystemSchema>, | ||
ModelPropsFromSchema<FamiliarSystemSchema> { | ||
attributes: CreatureAttributes; | ||
details: FamiliarDetails; | ||
customModifiers: Record<string, ModifierPF2e[]>; | ||
} | ||
|
||
type FamiliarSystemSchema = ActorSystemSchema & { | ||
master: fields.SchemaField<{ | ||
id: fields.ForeignDocumentField<string, true, true, true>; | ||
ability: fields.StringField<AttributeString, AttributeString, true, true, true>; | ||
}>; | ||
attributes: fields.SchemaField<{ | ||
hp: fields.SchemaField<{ | ||
value: fields.NumberField<number, number, true, false, true>; | ||
temp: fields.NumberField<number, number, true, false, true>; | ||
}>; | ||
}>; | ||
details: fields.SchemaField<{ | ||
creature: fields.SchemaField<{ | ||
value: fields.StringField<string, string, true, false, true>; | ||
}>; | ||
}>; | ||
}; | ||
|
||
interface FamiliarSystemSource extends SourceFromSchema<FamiliarSystemSchema> { | ||
attributes: FamiliarAttributesSource; | ||
details: FamiliarDetailsSource; | ||
customModifiers?: never; | ||
perception?: never; | ||
resources?: never; | ||
saves?: never; | ||
skills?: never; | ||
traits?: never; | ||
/** Legacy location of `MigrationRecord` */ | ||
schema?: object; | ||
} | ||
|
||
interface FamiliarAttributesSource { | ||
hp: { value: number; temp: number }; | ||
interface FamiliarAttributesSource extends SourcePropFromDataField<FamiliarSystemSchema["attributes"]> { | ||
immunities?: never; | ||
weaknesses?: never; | ||
resistances?: never; | ||
} | ||
|
||
interface FamiliarDetailsSource extends CreatureDetailsSource { | ||
creature: { | ||
value: string; | ||
}; | ||
interface FamiliarDetailsSource extends SourcePropFromDataField<FamiliarSystemSchema["details"]> { | ||
alliance?: never; | ||
languages?: never; | ||
level?: never; | ||
} | ||
|
||
/** The raw information contained within the actor data object for familiar actors. */ | ||
interface FamiliarSystemData extends Omit<FamiliarSystemSource, SourceOmission>, CreatureSystemData { | ||
details: FamiliarDetails; | ||
attack: StatisticTraceData; | ||
attributes: CreatureAttributes; | ||
master: { | ||
id: string | null; | ||
ability: AttributeString | null; | ||
}; | ||
|
||
actions?: never; | ||
initiative?: never; | ||
} | ||
|
||
type SourceOmission = | ||
| "attributes" | ||
| "customModifiers" | ||
| "details" | ||
| "perception" | ||
| "resources" | ||
| "saves" | ||
| "skills" | ||
| "traits"; | ||
|
||
interface FamiliarDetails extends CreatureDetails { | ||
creature: { | ||
value: string; | ||
}; | ||
interface FamiliarDetails extends ModelPropFromDataField<FamiliarSystemSchema["details"]>, CreatureDetails { | ||
languages: CreatureLanguagesData; | ||
} | ||
|
||
export type { FamiliarSource, FamiliarSystemData, FamiliarSystemSource }; | ||
export { FamiliarSystemData }; | ||
export type { FamiliarSource, FamiliarSystemSource }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.