Separate types for data and _data for DS4Actor
This commit is contained in:
parent
7c7d30854c
commit
17633ced68
7 changed files with 174 additions and 102 deletions
|
@ -1,4 +1,4 @@
|
|||
import { ModifiableDataTotal, ResourceData, UsableResource } from "../common/common-data";
|
||||
import { ModifiableData, ModifiableDataBase, ResourceData, UsableResource } from "../common/common-data";
|
||||
import { DS4 } from "../config";
|
||||
import { DS4ItemData } from "../item/item-data";
|
||||
|
||||
|
@ -6,50 +6,48 @@ export type DS4ActorData = DS4CharacterData | DS4CreatureData;
|
|||
|
||||
type ActorType = keyof typeof DS4.i18n.actorTypes;
|
||||
|
||||
interface DS4ActorDataHelper<T, U extends ActorType> extends Actor.Data<T, DS4ItemData> {
|
||||
export interface DS4ActorDataHelper<T, U extends ActorType> extends Actor.Data<T, DS4ItemData> {
|
||||
type: U;
|
||||
}
|
||||
|
||||
type DS4CharacterData = DS4ActorDataHelper<DS4CharacterDataData, "character">;
|
||||
type DS4CreatureData = DS4ActorDataHelper<DS4CreatureDataData, "creature">;
|
||||
|
||||
// templates
|
||||
|
||||
interface DS4ActorDataDataBase {
|
||||
attributes: DS4ActorDataDataAttributes;
|
||||
traits: DS4ActorDataDataTraits;
|
||||
combatValues: DS4ActorDataDataCombatValues;
|
||||
rolling: DS4ActorDataDataRolling;
|
||||
}
|
||||
|
||||
interface DS4ActorDataDataAttributes {
|
||||
body: ModifiableDataTotal<number>;
|
||||
mobility: ModifiableDataTotal<number>;
|
||||
mind: ModifiableDataTotal<number>;
|
||||
body: ModifiableDataBase<number>;
|
||||
mobility: ModifiableDataBase<number>;
|
||||
mind: ModifiableDataBase<number>;
|
||||
}
|
||||
|
||||
interface DS4ActorDataDataTraits {
|
||||
strength: ModifiableDataTotal<number>;
|
||||
constitution: ModifiableDataTotal<number>;
|
||||
agility: ModifiableDataTotal<number>;
|
||||
dexterity: ModifiableDataTotal<number>;
|
||||
intellect: ModifiableDataTotal<number>;
|
||||
aura: ModifiableDataTotal<number>;
|
||||
strength: ModifiableDataBase<number>;
|
||||
constitution: ModifiableDataBase<number>;
|
||||
agility: ModifiableDataBase<number>;
|
||||
dexterity: ModifiableDataBase<number>;
|
||||
intellect: ModifiableDataBase<number>;
|
||||
aura: ModifiableDataBase<number>;
|
||||
}
|
||||
|
||||
interface DS4ActorDataDataCombatValues {
|
||||
hitPoints: ResourceData<number>;
|
||||
defense: ModifiableDataTotal<number>;
|
||||
initiative: ModifiableDataTotal<number>;
|
||||
movement: ModifiableDataTotal<number>;
|
||||
meleeAttack: ModifiableDataTotal<number>;
|
||||
rangedAttack: ModifiableDataTotal<number>;
|
||||
spellcasting: ModifiableDataTotal<number>;
|
||||
targetedSpellcasting: ModifiableDataTotal<number>;
|
||||
defense: ModifiableData<number>;
|
||||
initiative: ModifiableData<number>;
|
||||
movement: ModifiableData<number>;
|
||||
meleeAttack: ModifiableData<number>;
|
||||
rangedAttack: ModifiableData<number>;
|
||||
spellcasting: ModifiableData<number>;
|
||||
targetedSpellcasting: ModifiableData<number>;
|
||||
}
|
||||
|
||||
interface DS4ActorDataDataRolling {
|
||||
maximumCoupResult?: number;
|
||||
minimumFumbleResult?: number;
|
||||
}
|
||||
// types
|
||||
|
||||
interface DS4CharacterDataData extends DS4ActorDataDataBase {
|
||||
baseInfo: DS4CharacterDataDataBaseInfo;
|
||||
|
@ -58,25 +56,25 @@ interface DS4CharacterDataData extends DS4ActorDataDataBase {
|
|||
profile: DS4CharacterDataDataProfile;
|
||||
currency: DS4CharacterDataDataCurrency;
|
||||
}
|
||||
interface DS4CharacterDataDataBaseInfo {
|
||||
export interface DS4CharacterDataDataBaseInfo {
|
||||
race: string;
|
||||
class: string;
|
||||
heroClass: string;
|
||||
culture: string;
|
||||
}
|
||||
interface DS4CharacterDataDataProgression {
|
||||
export interface DS4CharacterDataDataProgression {
|
||||
level: number;
|
||||
experiencePoints: number;
|
||||
talentPoints: UsableResource<number>;
|
||||
progressPoints: UsableResource<number>;
|
||||
}
|
||||
|
||||
interface DS4CharacterDataDataLanguage {
|
||||
export interface DS4CharacterDataDataLanguage {
|
||||
languages: string;
|
||||
alphabets: string;
|
||||
}
|
||||
|
||||
interface DS4CharacterDataDataProfile {
|
||||
export interface DS4CharacterDataDataProfile {
|
||||
biography: string;
|
||||
gender: string;
|
||||
birthday: string;
|
||||
|
@ -89,7 +87,7 @@ interface DS4CharacterDataDataProfile {
|
|||
specialCharacteristics: string;
|
||||
}
|
||||
|
||||
interface DS4CharacterDataDataCurrency {
|
||||
export interface DS4CharacterDataDataCurrency {
|
||||
gold: number;
|
||||
silver: number;
|
||||
copper: number;
|
||||
|
@ -99,11 +97,7 @@ interface DS4CreatureDataData extends DS4ActorDataDataBase {
|
|||
baseInfo: DS4CreatureDataDataBaseInfo;
|
||||
}
|
||||
|
||||
type CreatureType = "animal" | "construct" | "humanoid" | "magicalEntity" | "plantBeing" | "undead";
|
||||
|
||||
type SizeCategory = "tiny" | "small" | "normal" | "large" | "huge" | "colossal";
|
||||
|
||||
interface DS4CreatureDataDataBaseInfo {
|
||||
export interface DS4CreatureDataDataBaseInfo {
|
||||
loot: string;
|
||||
foeFactor: number;
|
||||
creatureType: CreatureType;
|
||||
|
@ -111,3 +105,7 @@ interface DS4CreatureDataDataBaseInfo {
|
|||
experiencePoints: number;
|
||||
description: string;
|
||||
}
|
||||
|
||||
type CreatureType = "animal" | "construct" | "humanoid" | "magicalEntity" | "plantBeing" | "undead";
|
||||
|
||||
type SizeCategory = "tiny" | "small" | "normal" | "large" | "huge" | "colossal";
|
||||
|
|
69
src/module/actor/actor-prepared-data.ts
Normal file
69
src/module/actor/actor-prepared-data.ts
Normal file
|
@ -0,0 +1,69 @@
|
|||
import { ModifiableDataBaseTotal, ResourceDataBaseTotalMax } from "../common/common-data";
|
||||
import {
|
||||
DS4ActorDataHelper,
|
||||
DS4CharacterDataDataBaseInfo,
|
||||
DS4CharacterDataDataCurrency,
|
||||
DS4CharacterDataDataLanguage,
|
||||
DS4CharacterDataDataProfile,
|
||||
DS4CharacterDataDataProgression,
|
||||
DS4CreatureDataDataBaseInfo,
|
||||
} from "./actor-data";
|
||||
|
||||
export type DS4ActorPreparedData = DS4CharacterPreparedData | DS4CreaturePreparedData;
|
||||
|
||||
type DS4CharacterPreparedData = DS4ActorDataHelper<DS4CharacterPreparedDataData, "character">;
|
||||
type DS4CreaturePreparedData = DS4ActorDataHelper<DS4CreaturePreparedDataData, "creature">;
|
||||
|
||||
// templates
|
||||
|
||||
interface DS4ActorPreparedDataDataBase {
|
||||
attributes: DS4ActorPreparedDataDataAttributes;
|
||||
traits: DS4ActorPreparedDataDataTraits;
|
||||
combatValues: DS4ActorPreparedDataDataCombatValues;
|
||||
rolling: DS4ActorPreparedDataDataRolling;
|
||||
}
|
||||
|
||||
interface DS4ActorPreparedDataDataAttributes {
|
||||
body: ModifiableDataBaseTotal<number>;
|
||||
mobility: ModifiableDataBaseTotal<number>;
|
||||
mind: ModifiableDataBaseTotal<number>;
|
||||
}
|
||||
|
||||
interface DS4ActorPreparedDataDataTraits {
|
||||
strength: ModifiableDataBaseTotal<number>;
|
||||
constitution: ModifiableDataBaseTotal<number>;
|
||||
agility: ModifiableDataBaseTotal<number>;
|
||||
dexterity: ModifiableDataBaseTotal<number>;
|
||||
intellect: ModifiableDataBaseTotal<number>;
|
||||
aura: ModifiableDataBaseTotal<number>;
|
||||
}
|
||||
|
||||
interface DS4ActorPreparedDataDataCombatValues {
|
||||
hitPoints: ResourceDataBaseTotalMax<number>;
|
||||
defense: ModifiableDataBaseTotal<number>;
|
||||
initiative: ModifiableDataBaseTotal<number>;
|
||||
movement: ModifiableDataBaseTotal<number>;
|
||||
meleeAttack: ModifiableDataBaseTotal<number>;
|
||||
rangedAttack: ModifiableDataBaseTotal<number>;
|
||||
spellcasting: ModifiableDataBaseTotal<number>;
|
||||
targetedSpellcasting: ModifiableDataBaseTotal<number>;
|
||||
}
|
||||
|
||||
interface DS4ActorPreparedDataDataRolling {
|
||||
maximumCoupResult: number;
|
||||
minimumFumbleResult: number;
|
||||
}
|
||||
|
||||
// types
|
||||
|
||||
interface DS4CharacterPreparedDataData extends DS4ActorPreparedDataDataBase {
|
||||
baseInfo: DS4CharacterDataDataBaseInfo;
|
||||
progression: DS4CharacterDataDataProgression;
|
||||
language: DS4CharacterDataDataLanguage;
|
||||
profile: DS4CharacterDataDataProfile;
|
||||
currency: DS4CharacterDataDataCurrency;
|
||||
}
|
||||
|
||||
interface DS4CreaturePreparedDataData extends DS4ActorPreparedDataDataBase {
|
||||
baseInfo: DS4CreatureDataDataBaseInfo;
|
||||
}
|
|
@ -1,16 +1,17 @@
|
|||
import { ModifiableDataTotal } from "../common/common-data";
|
||||
import { ModifiableDataBaseTotal } from "../common/common-data";
|
||||
import { DS4 } from "../config";
|
||||
import { DS4Item } from "../item/item";
|
||||
import { ItemType } from "../item/item-data";
|
||||
import { DS4ActorData } from "./actor-data";
|
||||
import { DS4ActorPreparedData } from "./actor-prepared-data";
|
||||
|
||||
/**
|
||||
* The Actor class for DS4
|
||||
*/
|
||||
export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
|
||||
export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData> {
|
||||
/** @override */
|
||||
prepareData(): void {
|
||||
this.data = duplicate(this._data) as DS4ActorData;
|
||||
this.data = duplicate(this._data) as DS4ActorPreparedData;
|
||||
if (!this.data.img) this.data.img = CONST.DEFAULT_TOKEN;
|
||||
if (!this.data.name) this.data.name = "New " + this.entity;
|
||||
this.prepareBaseData();
|
||||
|
@ -32,11 +33,13 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
|
|||
|
||||
const attributes = data.data.attributes;
|
||||
Object.values(attributes).forEach(
|
||||
(attribute: ModifiableDataTotal<number>) => (attribute.total = attribute.base + attribute.mod),
|
||||
(attribute: ModifiableDataBaseTotal<number>) => (attribute.total = attribute.base + attribute.mod),
|
||||
);
|
||||
|
||||
const traits = data.data.traits;
|
||||
Object.values(traits).forEach((trait: ModifiableDataTotal<number>) => (trait.total = trait.base + trait.mod));
|
||||
Object.values(traits).forEach(
|
||||
(trait: ModifiableDataBaseTotal<number>) => (trait.total = trait.base + trait.mod),
|
||||
);
|
||||
}
|
||||
|
||||
applyActiveEffectsToBaseData(): void {
|
||||
|
@ -184,7 +187,7 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
|
|||
(data.attributes.mind.total ?? 0) + (data.traits.dexterity.total ?? 0) - armorValueOfEquippedItems;
|
||||
|
||||
Object.values(data.combatValues).forEach(
|
||||
(combatValue: ModifiableDataTotal<number>) => (combatValue.total = combatValue.base + combatValue.mod),
|
||||
(combatValue: ModifiableDataBaseTotal<number>) => (combatValue.total = combatValue.base + combatValue.mod),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ModifiableMaybeData } from "../../common/common-data";
|
||||
import { ModifiableDataBaseTotal } from "../../common/common-data";
|
||||
import { DS4 } from "../../config";
|
||||
import { DS4Item } from "../../item/item";
|
||||
import { DS4ItemData } from "../../item/item-data";
|
||||
|
@ -75,17 +75,16 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Data<DS4Actor>> {
|
|||
|
||||
protected _addTooltipsToData(data: ActorSheet.Data<DS4Actor>): ActorSheet.Data<DS4Actor> {
|
||||
const valueGroups = [data.data.attributes, data.data.traits, data.data.combatValues];
|
||||
|
||||
valueGroups.forEach((valueGroup) => {
|
||||
Object.values(valueGroup).forEach(
|
||||
(attribute: ModifiableMaybeData<number | null> & { tooltip?: string }) => {
|
||||
attribute.tooltip = this._getTooltipForValue(attribute);
|
||||
},
|
||||
);
|
||||
Object.values(valueGroup).forEach((attribute: ModifiableDataBaseTotal<number> & { tooltip?: string }) => {
|
||||
attribute.tooltip = this._getTooltipForValue(attribute);
|
||||
});
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
protected _getTooltipForValue(value: ModifiableMaybeData<number | null>): string {
|
||||
protected _getTooltipForValue(value: ModifiableDataBaseTotal<number>): string {
|
||||
return `${value.base} (${game.i18n.localize("DS4.TooltipBaseValue")}) + ${value.mod} (${game.i18n.localize(
|
||||
"DS4.TooltipModifier",
|
||||
)}) ➞ ${game.i18n.localize("DS4.TooltipEffects")} ➞ ${value.total}`;
|
||||
|
|
|
@ -1,29 +1,30 @@
|
|||
export interface ModifiableData<T> {
|
||||
base: T;
|
||||
mod: T;
|
||||
}
|
||||
|
||||
export interface HasBase<T> {
|
||||
base: T;
|
||||
}
|
||||
export interface ModifiableDataBase<T> extends ModifiableData<T>, HasBase<T> {}
|
||||
|
||||
export interface HasTotal<T> {
|
||||
total: T;
|
||||
}
|
||||
|
||||
export interface ModifiableDataTotal<T> {
|
||||
base: T;
|
||||
mod: T;
|
||||
total?: T;
|
||||
}
|
||||
export interface ModifiableDataTotal<T> extends ModifiableData<T>, HasTotal<T> {}
|
||||
|
||||
export interface ModifiableMaybeData<T> {
|
||||
base?: T;
|
||||
mod: T;
|
||||
total?: T;
|
||||
}
|
||||
export interface ModifiableDataBaseTotal<T> extends ModifiableDataBase<T>, HasTotal<T> {}
|
||||
|
||||
export interface ResourceData<T> extends ModifiableMaybeData<T> {
|
||||
export interface ResourceData<T> extends ModifiableData<T> {
|
||||
value: T;
|
||||
max?: T;
|
||||
}
|
||||
|
||||
export interface HasMax<T> {
|
||||
max: T;
|
||||
}
|
||||
|
||||
export interface ResourceDataBaseTotalMax<T> extends ResourceData<T>, HasBase<T>, HasTotal<T>, HasMax<T> {}
|
||||
|
||||
export interface UsableResource<T> {
|
||||
total: T;
|
||||
used: T;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ModifiableData } from "../common/common-data";
|
||||
import { ModifiableDataBase } from "../common/common-data";
|
||||
import { DS4 } from "../config";
|
||||
|
||||
export type ItemType = keyof typeof DS4.i18n.itemTypes;
|
||||
|
@ -32,7 +32,38 @@ type DS4LanguageData = DS4ItemDataHelper<DS4LanguageDataData, "language">;
|
|||
type DS4AlphabetData = DS4ItemDataHelper<DS4AlphabetDataData, "alphabet">;
|
||||
type DS4SpecialCreatureAbilityData = DS4ItemDataHelper<DS4SpecialCreatureAbilityDataData, "specialCreatureAbility">;
|
||||
|
||||
export type AttackType = keyof typeof DS4["i18n"]["attackTypes"];
|
||||
// templates
|
||||
|
||||
interface DS4ItemDataDataBase {
|
||||
description: string;
|
||||
}
|
||||
interface DS4ItemDataDataPhysical {
|
||||
quantity: number;
|
||||
price: number;
|
||||
availability: "hamlet" | "village" | "city" | "elves" | "dwarves" | "nowhere" | "unset";
|
||||
storageLocation: string;
|
||||
}
|
||||
|
||||
export function isDS4ItemDataTypePhysical(input: DS4ItemData["data"]): boolean {
|
||||
return "quantity" in input && "price" in input && "availability" in input && "storageLocation" in input;
|
||||
}
|
||||
|
||||
interface DS4ItemDataDataEquipable {
|
||||
equipped: boolean;
|
||||
}
|
||||
|
||||
interface DS4ItemDataDataProtective {
|
||||
armorValue: number;
|
||||
}
|
||||
|
||||
interface UnitData<UnitType> {
|
||||
value: string;
|
||||
unit: UnitType;
|
||||
}
|
||||
type TemporalUnit = "rounds" | "minutes" | "hours" | "days" | "custom";
|
||||
type DistanceUnit = "meter" | "kilometer" | "custom";
|
||||
|
||||
// types
|
||||
|
||||
export interface DS4WeaponDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical, DS4ItemDataDataEquipable {
|
||||
attackType: AttackType;
|
||||
|
@ -40,6 +71,8 @@ export interface DS4WeaponDataData extends DS4ItemDataDataBase, DS4ItemDataDataP
|
|||
opponentDefense: number;
|
||||
}
|
||||
|
||||
export type AttackType = keyof typeof DS4["i18n"]["attackTypes"];
|
||||
|
||||
export interface DS4ArmorDataData
|
||||
extends DS4ItemDataDataBase,
|
||||
DS4ItemDataDataPhysical,
|
||||
|
@ -53,7 +86,7 @@ export interface DS4TalentDataData extends DS4ItemDataDataBase {
|
|||
rank: DS4TalentRank;
|
||||
}
|
||||
|
||||
export interface DS4TalentRank extends ModifiableData<number> {
|
||||
export interface DS4TalentRank extends ModifiableDataBase<number> {
|
||||
max: number;
|
||||
}
|
||||
|
||||
|
@ -96,34 +129,3 @@ export type DS4AlphabetDataData = DS4ItemDataDataBase;
|
|||
export interface DS4SpecialCreatureAbilityDataData extends DS4ItemDataDataBase {
|
||||
experiencePoints: number;
|
||||
}
|
||||
|
||||
// templates
|
||||
|
||||
interface DS4ItemDataDataBase {
|
||||
description: string;
|
||||
}
|
||||
interface DS4ItemDataDataPhysical {
|
||||
quantity: number;
|
||||
price: number;
|
||||
availability: "hamlet" | "village" | "city" | "elves" | "dwarves" | "nowhere" | "unset";
|
||||
storageLocation: string;
|
||||
}
|
||||
|
||||
export function isDS4ItemDataTypePhysical(input: DS4ItemData["data"]): boolean {
|
||||
return "quantity" in input && "price" in input && "availability" in input && "storageLocation" in input;
|
||||
}
|
||||
|
||||
interface DS4ItemDataDataEquipable {
|
||||
equipped: boolean;
|
||||
}
|
||||
|
||||
interface DS4ItemDataDataProtective {
|
||||
armorValue: number;
|
||||
}
|
||||
|
||||
interface UnitData<UnitType> {
|
||||
value: string;
|
||||
unit: UnitType;
|
||||
}
|
||||
type TemporalUnit = "rounds" | "minutes" | "hours" | "days" | "custom";
|
||||
type DistanceUnit = "meter" | "kilometer" | "custom";
|
||||
|
|
|
@ -43,6 +43,14 @@ type DS4SpecialCreatureAbilityPreparedData = DS4ItemDataHelper<
|
|||
"specialCreatureAbility"
|
||||
>;
|
||||
|
||||
// templates
|
||||
|
||||
interface DS4ItemPreparedDataDataRollable {
|
||||
rollable: boolean;
|
||||
}
|
||||
|
||||
//types
|
||||
|
||||
interface DS4WeaponPreparedDataData extends DS4WeaponDataData, DS4ItemPreparedDataDataRollable {}
|
||||
|
||||
interface DS4ArmorPreparedDataData extends DS4ArmorDataData, DS4ItemPreparedDataDataRollable {}
|
||||
|
@ -59,9 +67,7 @@ interface DS4TalentPreparedDataData extends DS4TalentDataData, DS4ItemPreparedDa
|
|||
rank: DS4TalentPreparedRank;
|
||||
}
|
||||
|
||||
interface DS4TalentPreparedRank extends DS4TalentRank, HasTotal<number> {
|
||||
max: number;
|
||||
}
|
||||
interface DS4TalentPreparedRank extends DS4TalentRank, HasTotal<number> {}
|
||||
|
||||
interface DS4RacialAbilityPreparedDataData extends DS4RacialAbilityDataData, DS4ItemPreparedDataDataRollable {}
|
||||
|
||||
|
@ -72,9 +78,3 @@ interface DS4AlphabetPreparedDataData extends DS4AlphabetDataData, DS4ItemPrepar
|
|||
interface DS4SpecialCreatureAbilityPreparedDataData
|
||||
extends DS4SpecialCreatureAbilityDataData,
|
||||
DS4ItemPreparedDataDataRollable {}
|
||||
|
||||
// templates
|
||||
|
||||
interface DS4ItemPreparedDataDataRollable {
|
||||
rollable: boolean;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue