Separate data and _data for DS4Item

This commit is contained in:
Johannes Loher 2021-03-22 09:04:45 +01:00
parent a7569633e2
commit 7c7d30854c
12 changed files with 150 additions and 54 deletions

View file

@ -46,7 +46,7 @@
"postinstall": "husky install"
},
"devDependencies": {
"@league-of-foundry-developers/foundry-vtt-types": "^0.7.9-3",
"@league-of-foundry-developers/foundry-vtt-types": "^0.7.9-4",
"@rollup/plugin-node-resolve": "^11.2.0",
"@types/fs-extra": "^9.0.8",
"@types/jest": "^26.0.20",

View file

@ -1,4 +1,4 @@
import { ModifiableData, ResourceData, UsableResource } from "../common/common-data";
import { ModifiableDataTotal, ResourceData, UsableResource } from "../common/common-data";
import { DS4 } from "../config";
import { DS4ItemData } from "../item/item-data";
@ -21,29 +21,29 @@ interface DS4ActorDataDataBase {
}
interface DS4ActorDataDataAttributes {
body: ModifiableData<number>;
mobility: ModifiableData<number>;
mind: ModifiableData<number>;
body: ModifiableDataTotal<number>;
mobility: ModifiableDataTotal<number>;
mind: ModifiableDataTotal<number>;
}
interface DS4ActorDataDataTraits {
strength: ModifiableData<number>;
constitution: ModifiableData<number>;
agility: ModifiableData<number>;
dexterity: ModifiableData<number>;
intellect: ModifiableData<number>;
aura: ModifiableData<number>;
strength: ModifiableDataTotal<number>;
constitution: ModifiableDataTotal<number>;
agility: ModifiableDataTotal<number>;
dexterity: ModifiableDataTotal<number>;
intellect: ModifiableDataTotal<number>;
aura: ModifiableDataTotal<number>;
}
interface DS4ActorDataDataCombatValues {
hitPoints: ResourceData<number>;
defense: ModifiableData<number>;
initiative: ModifiableData<number>;
movement: ModifiableData<number>;
meleeAttack: ModifiableData<number>;
rangedAttack: ModifiableData<number>;
spellcasting: ModifiableData<number>;
targetedSpellcasting: ModifiableData<number>;
defense: ModifiableDataTotal<number>;
initiative: ModifiableDataTotal<number>;
movement: ModifiableDataTotal<number>;
meleeAttack: ModifiableDataTotal<number>;
rangedAttack: ModifiableDataTotal<number>;
spellcasting: ModifiableDataTotal<number>;
targetedSpellcasting: ModifiableDataTotal<number>;
}
interface DS4ActorDataDataRolling {

View file

@ -1,4 +1,4 @@
import { ModifiableData } from "../common/common-data";
import { ModifiableDataTotal } from "../common/common-data";
import { DS4 } from "../config";
import { DS4Item } from "../item/item";
import { ItemType } from "../item/item-data";
@ -32,11 +32,11 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
const attributes = data.data.attributes;
Object.values(attributes).forEach(
(attribute: ModifiableData<number>) => (attribute.total = attribute.base + attribute.mod),
(attribute: ModifiableDataTotal<number>) => (attribute.total = attribute.base + attribute.mod),
);
const traits = data.data.traits;
Object.values(traits).forEach((trait: ModifiableData<number>) => (trait.total = trait.base + trait.mod));
Object.values(traits).forEach((trait: ModifiableDataTotal<number>) => (trait.total = trait.base + trait.mod));
}
applyActiveEffectsToBaseData(): void {
@ -184,7 +184,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: ModifiableData<number>) => (combatValue.total = combatValue.base + combatValue.mod),
(combatValue: ModifiableDataTotal<number>) => (combatValue.total = combatValue.base + combatValue.mod),
);
}

View file

@ -160,7 +160,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Data<DS4Actor>> {
ev.preventDefault();
const el: HTMLFormElement = $(ev.currentTarget).get(0);
const id = $(ev.currentTarget).parents(".item").data("itemId");
const item = duplicate<DS4Item, "lenient">(this.actor.getOwnedItem(id));
const item = duplicate(this.actor.getOwnedItem(id));
const property: string | undefined = $(ev.currentTarget).data("property");
// Early return:

View file

@ -1,6 +1,15 @@
export interface ModifiableData<T> {
base: T;
mod: T;
}
export interface HasTotal<T> {
total: T;
}
export interface ModifiableDataTotal<T> {
base: T;
mod: T;
total?: T;
}

6
src/module/global.d.ts vendored Normal file
View file

@ -0,0 +1,6 @@
declare namespace ClientSettings {
interface Values {
"ds4.systemMigrationVersion": number;
"ds4.useSlayingDiceForAutomatedChecks": boolean;
}
}

View file

@ -16,7 +16,7 @@ export type DS4ItemData =
| DS4AlphabetData
| DS4SpecialCreatureAbilityData;
interface DS4ItemDataHelper<T, U extends ItemType> extends Item.Data<T> {
export interface DS4ItemDataHelper<T, U extends ItemType> extends Item.Data<T> {
type: U;
}
@ -34,17 +34,13 @@ type DS4SpecialCreatureAbilityData = DS4ItemDataHelper<DS4SpecialCreatureAbility
export type AttackType = keyof typeof DS4["i18n"]["attackTypes"];
interface DS4WeaponDataData
extends DS4ItemDataDataBase,
DS4ItemDataDataPhysical,
DS4ItemDataDataEquipable,
DS4ItemDataDataRollable {
export interface DS4WeaponDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical, DS4ItemDataDataEquipable {
attackType: AttackType;
weaponBonus: number;
opponentDefense: number;
}
interface DS4ArmorDataData
export interface DS4ArmorDataData
extends DS4ItemDataDataBase,
DS4ItemDataDataPhysical,
DS4ItemDataDataEquipable,
@ -53,15 +49,15 @@ interface DS4ArmorDataData
armorType: "body" | "helmet" | "vambrace" | "greaves" | "vambraceGreaves";
}
interface DS4TalentDataData extends DS4ItemDataDataBase {
export interface DS4TalentDataData extends DS4ItemDataDataBase {
rank: DS4TalentRank;
}
interface DS4TalentRank extends ModifiableData<number> {
export interface DS4TalentRank extends ModifiableData<number> {
max: number;
}
interface DS4SpellDataData extends DS4ItemDataDataBase, DS4ItemDataDataEquipable, DS4ItemDataDataRollable {
export interface DS4SpellDataData extends DS4ItemDataDataBase, DS4ItemDataDataEquipable {
spellType: "spellcasting" | "targetedSpellcasting";
bonus: string;
spellCategory:
@ -81,17 +77,23 @@ interface DS4SpellDataData extends DS4ItemDataDataBase, DS4ItemDataDataEquipable
scrollPrice: number;
}
interface DS4ShieldDataData
export interface DS4ShieldDataData
extends DS4ItemDataDataBase,
DS4ItemDataDataPhysical,
DS4ItemDataDataEquipable,
DS4ItemDataDataProtective {}
interface DS4EquipmentDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical, DS4ItemDataDataEquipable {}
interface DS4LootDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical {}
type DS4RacialAbilityDataData = DS4ItemDataDataBase;
type DS4LanguageDataData = DS4ItemDataDataBase;
type DS4AlphabetDataData = DS4ItemDataDataBase;
interface DS4SpecialCreatureAbilityDataData extends DS4ItemDataDataBase {
export interface DS4EquipmentDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical, DS4ItemDataDataEquipable {}
export interface DS4LootDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical {}
export type DS4RacialAbilityDataData = DS4ItemDataDataBase;
export type DS4LanguageDataData = DS4ItemDataDataBase;
export type DS4AlphabetDataData = DS4ItemDataDataBase;
export interface DS4SpecialCreatureAbilityDataData extends DS4ItemDataDataBase {
experiencePoints: number;
}
@ -115,10 +117,6 @@ interface DS4ItemDataDataEquipable {
equipped: boolean;
}
interface DS4ItemDataDataRollable {
rollable?: boolean;
}
interface DS4ItemDataDataProtective {
armorValue: number;
}

View file

@ -0,0 +1,80 @@
import { HasTotal } from "../common/common-data";
import {
DS4AlphabetDataData,
DS4ArmorDataData,
DS4EquipmentDataData,
DS4ItemDataHelper,
DS4LanguageDataData,
DS4LootDataData,
DS4RacialAbilityDataData,
DS4ShieldDataData,
DS4SpecialCreatureAbilityDataData,
DS4SpellDataData,
DS4TalentDataData,
DS4TalentRank,
DS4WeaponDataData,
} from "./item-data";
export type DS4ItemPreparedData =
| DS4WeaponPreparedData
| DS4ArmorPreparedData
| DS4ShieldPreparedData
| DS4SpellPreparedData
| DS4EquipmentPreparedData
| DS4LootPreparedData
| DS4TalentPreparedData
| DS4RacialAbilityPreparedData
| DS4LanguagePreparedData
| DS4AlphabetPreparedData
| DS4SpecialCreatureAbilityPreparedData;
type DS4WeaponPreparedData = DS4ItemDataHelper<DS4WeaponPreparedDataData, "weapon">;
type DS4ArmorPreparedData = DS4ItemDataHelper<DS4ArmorPreparedDataData, "armor">;
type DS4ShieldPreparedData = DS4ItemDataHelper<DS4ShieldPreparedDataData, "shield">;
type DS4SpellPreparedData = DS4ItemDataHelper<DS4SpellPreparedDataData, "spell">;
type DS4EquipmentPreparedData = DS4ItemDataHelper<DS4EquipmentPreparedDataData, "equipment">;
type DS4LootPreparedData = DS4ItemDataHelper<DS4LootPreparedDataData, "loot">;
type DS4TalentPreparedData = DS4ItemDataHelper<DS4TalentPreparedDataData, "talent">;
type DS4RacialAbilityPreparedData = DS4ItemDataHelper<DS4RacialAbilityPreparedDataData, "racialAbility">;
type DS4LanguagePreparedData = DS4ItemDataHelper<DS4LanguagePreparedDataData, "language">;
type DS4AlphabetPreparedData = DS4ItemDataHelper<DS4AlphabetPreparedDataData, "alphabet">;
type DS4SpecialCreatureAbilityPreparedData = DS4ItemDataHelper<
DS4SpecialCreatureAbilityPreparedDataData,
"specialCreatureAbility"
>;
interface DS4WeaponPreparedDataData extends DS4WeaponDataData, DS4ItemPreparedDataDataRollable {}
interface DS4ArmorPreparedDataData extends DS4ArmorDataData, DS4ItemPreparedDataDataRollable {}
interface DS4ShieldPreparedDataData extends DS4ShieldDataData, DS4ItemPreparedDataDataRollable {}
interface DS4SpellPreparedDataData extends DS4SpellDataData, DS4ItemPreparedDataDataRollable {}
interface DS4EquipmentPreparedDataData extends DS4EquipmentDataData, DS4ItemPreparedDataDataRollable {}
interface DS4LootPreparedDataData extends DS4LootDataData, DS4ItemPreparedDataDataRollable {}
interface DS4TalentPreparedDataData extends DS4TalentDataData, DS4ItemPreparedDataDataRollable {
rank: DS4TalentPreparedRank;
}
interface DS4TalentPreparedRank extends DS4TalentRank, HasTotal<number> {
max: number;
}
interface DS4RacialAbilityPreparedDataData extends DS4RacialAbilityDataData, DS4ItemPreparedDataDataRollable {}
interface DS4LanguagePreparedDataData extends DS4LanguageDataData, DS4ItemPreparedDataDataRollable {}
interface DS4AlphabetPreparedDataData extends DS4AlphabetDataData, DS4ItemPreparedDataDataRollable {}
interface DS4SpecialCreatureAbilityPreparedDataData
extends DS4SpecialCreatureAbilityDataData,
DS4ItemPreparedDataDataRollable {}
// templates
interface DS4ItemPreparedDataDataRollable {
rollable: boolean;
}

View file

@ -3,11 +3,12 @@ import { DS4 } from "../config";
import { createCheckRoll } from "../rolls/check-factory";
import notifications from "../ui/notifications";
import { AttackType, DS4ItemData, ItemType } from "./item-data";
import { DS4ItemPreparedData } from "./item-prepared-data";
/**
* The Item class for DS4
*/
export class DS4Item extends Item<DS4ItemData> {
export class DS4Item extends Item<DS4ItemData, DS4ItemPreparedData> {
/**
* @override
*/
@ -23,6 +24,8 @@ export class DS4Item extends Item<DS4ItemData> {
}
if (this.data.type === "weapon" || this.data.type === "spell") {
this.data.data.rollable = this.data.data.equipped;
} else {
this.data.data.rollable = false;
}
}
@ -94,7 +97,7 @@ export class DS4Item extends Item<DS4ItemData> {
const checkTargetNumber = (ownerDataData.combatValues[combatValue].total as number) + weaponBonus;
await createCheckRoll(checkTargetNumber, {
rollMode: game.settings.get("core", "rollMode"),
rollMode: game.settings.get("core", "rollMode") as Const.DiceRollMode, // TODO(types): Type this setting in upstream
maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ItemWeaponCheckFlavor", { actor: actor.name, weapon: this.name }),
@ -138,7 +141,7 @@ export class DS4Item extends Item<DS4ItemData> {
const checkTargetNumber = (ownerDataData.combatValues[spellType].total as number) + (spellBonus ?? 0);
await createCheckRoll(checkTargetNumber, {
rollMode: game.settings.get("core", "rollMode"),
rollMode: game.settings.get("core", "rollMode") as Const.DiceRollMode, // TODO(types): Type this setting in upstream
maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ItemSpellCheckFlavor", { actor: actor.name, spell: this.name }),

View file

@ -9,7 +9,7 @@ async function migrate(): Promise<void> {
return;
}
const oldMigrationVersion: number = game.settings.get("ds4", "systemMigrationVersion");
const oldMigrationVersion = game.settings.get("ds4", "systemMigrationVersion");
const targetMigrationVersion = migrations.length;

View file

@ -79,7 +79,7 @@ export async function createCheckRoll(
const newOptions: Partial<DS4CheckFactoryOptions> = {
maximumCoupResult: gmModifierData.maximumCoupResult ?? options.maximumCoupResult,
minimumFumbleResult: gmModifierData.minimumFumbleResult ?? options.minimumFumbleResult,
useSlayingDice: game.settings.get("ds4", "useSlayingDiceForAutomatedChecks") ?? false,
useSlayingDice: game.settings.get("ds4", "useSlayingDiceForAutomatedChecks"),
rollMode: gmModifierData.rollMode ?? options.rollMode,
flavor: options.flavor,
};

View file

@ -647,9 +647,9 @@ __metadata:
languageName: node
linkType: hard
"@league-of-foundry-developers/foundry-vtt-types@npm:^0.7.9-3":
version: 0.7.9-3
resolution: "@league-of-foundry-developers/foundry-vtt-types@npm:0.7.9-3"
"@league-of-foundry-developers/foundry-vtt-types@npm:^0.7.9-4":
version: 0.7.9-4
resolution: "@league-of-foundry-developers/foundry-vtt-types@npm:0.7.9-4"
dependencies:
"@types/howler": 2.2.1
"@types/jquery": 3.5.1
@ -659,7 +659,7 @@ __metadata:
pixi.js: 5.3.4
tinymce: 5.6.2
typescript: ^4.1.4
checksum: 75524c7aa78ddb77cad1a9d041af30ae5bbd708f5b26568dabbb3d913a4643aefcc6f2ed80e1e76b3c17050579665eab155f035f840db6397691cf68eeee9b3f
checksum: 9aeee3d49c20dd69e736abd50347e43f5cfdcfdca7fba5af9fb321250cc3ca78758daed14fe6328005f3b606ed0ace49bf2562d7262912c1461132718ab793b8
languageName: node
linkType: hard
@ -2891,7 +2891,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "dungeonslayers4@workspace:."
dependencies:
"@league-of-foundry-developers/foundry-vtt-types": ^0.7.9-3
"@league-of-foundry-developers/foundry-vtt-types": ^0.7.9-4
"@rollup/plugin-node-resolve": ^11.2.0
"@types/fs-extra": ^9.0.8
"@types/jest": ^26.0.20