forked from foundryvtt/pf2e
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert loot system data to
TypeDataModel
(foundryvtt#17284)
- Loading branch information
Showing
11 changed files
with
91 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,73 @@ | ||
import { | ||
ActorAttributes, | ||
ActorAttributesSource, | ||
ActorDetails, | ||
ActorSystemData, | ||
ActorSystemSource, | ||
BaseActorSourcePF2e, | ||
} from "@actor/data/base.ts"; | ||
import { BaseActorSourcePF2e, FlankingData } from "@actor/data/base.ts"; | ||
import { ActorSystemModel, ActorSystemSchema } from "@actor/data/model.ts"; | ||
import { ModelPropFromDataField } from "types/foundry/common/data/fields.js"; | ||
import type { LootPF2e } from "./document.ts"; | ||
import fields = foundry.data.fields; | ||
|
||
/** The stored source data of a loot actor */ | ||
type LootSource = BaseActorSourcePF2e<"loot", LootSystemSource>; | ||
|
||
/** The system-level data of loot actors. */ | ||
interface LootSystemSource extends ActorSystemSource { | ||
attributes: LootAttributesSource; | ||
details: LootDetailsSource; | ||
lootSheetType: "Merchant" | "Loot"; | ||
hiddenWhenEmpty: boolean; | ||
traits?: never; | ||
class LootSystemData extends ActorSystemModel<LootPF2e, LootSystemSchema> { | ||
static override defineSchema(): LootSystemSchema { | ||
return { | ||
...super.defineSchema(), | ||
details: new fields.SchemaField({ | ||
description: new fields.HTMLField({ required: true, nullable: false, blank: true, initial: "" }), | ||
level: new fields.SchemaField({ | ||
value: new fields.NumberField({ | ||
required: true, | ||
nullable: false, | ||
min: 0, | ||
integer: true, | ||
initial: 0, | ||
}), | ||
}), | ||
}), | ||
lootSheetType: new fields.StringField({ | ||
required: true, | ||
nullable: false, | ||
choices: ["Loot", "Merchant"], | ||
initial: "Loot", | ||
}), | ||
hiddenWhenEmpty: new fields.BooleanField(), | ||
}; | ||
} | ||
} | ||
|
||
interface LootSystemData extends Omit<LootSystemSource, "attributes" | "details">, ActorSystemData { | ||
attributes: LootAttributes; | ||
interface LootSystemData extends ActorSystemModel<LootPF2e, LootSystemSchema>, ModelPropsFromSchema<LootSystemSchema> { | ||
details: LootDetails; | ||
traits?: never; | ||
attributes: LootAttributes; | ||
} | ||
|
||
interface LootAttributesSource extends ActorAttributesSource { | ||
hp?: never; | ||
ac?: never; | ||
perception?: never; | ||
immunities?: never; | ||
weaknesses?: never; | ||
resistances?: never; | ||
} | ||
type LootSystemSchema = ActorSystemSchema & { | ||
details: fields.SchemaField<{ | ||
description: fields.HTMLField<string, string, true, false, true>; | ||
level: fields.SchemaField<{ | ||
value: fields.NumberField<number, number, true, false, true>; | ||
}>; | ||
}>; | ||
lootSheetType: fields.StringField<"Merchant" | "Loot", "Merchant" | "Loot", true, false, true>; | ||
hiddenWhenEmpty: fields.BooleanField; | ||
}; | ||
|
||
interface LootAttributes | ||
extends Omit<LootAttributesSource, "immunities" | "weaknesses" | "resistances">, | ||
Omit<ActorAttributes, "perception" | "hp" | "ac"> { | ||
initiative?: never; | ||
/** The system-level data of loot actors. */ | ||
interface LootSystemSource extends SourceFromSchema<LootSystemSchema> { | ||
attributes?: never; | ||
traits?: never; | ||
schema?: never; | ||
} | ||
|
||
interface LootDetailsSource { | ||
alliance?: never; | ||
description: string; | ||
level: { | ||
value: number; | ||
}; | ||
interface LootDetails extends ModelPropFromDataField<LootSystemSchema["details"]> { | ||
alliance: null; | ||
} | ||
|
||
interface LootDetails extends Omit<LootDetailsSource, "alliance">, ActorDetails { | ||
alliance: null; | ||
interface LootAttributes { | ||
immunities: never[]; | ||
weaknesses: never[]; | ||
resistances: never[]; | ||
flanking: FlankingData; | ||
} | ||
|
||
export type { LootSource, LootSystemData, LootSystemSource }; | ||
export { LootSystemData }; | ||
export type { LootSource, LootSystemSource }; |
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
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