diff --git a/src/module/actor/actor-data.ts b/src/module/actor/actor-data.ts index c45a0cb2..9f12ef3e 100644 --- a/src/module/actor/actor-data.ts +++ b/src/module/actor/actor-data.ts @@ -1,23 +1,31 @@ import { ModifiableData, ResourceData, UsableResource } from "../common/common-data"; +import { DS4 } from "../config"; import { DS4ItemData } from "../item/item-data"; -export type DS4ActorData = Actor.Data; +export type DS4ActorData = DS4CharacterData | DS4CreatureData; -type DS4ActorDataType = DS4ActorDataCharacter | DS4ActorDataCreature; +type ActorType = keyof typeof DS4.i18n.actorTypes; -interface DS4ActorDataBase { - attributes: DS4ActorDataAttributes; - traits: DS4ActorDataTraits; - combatValues: DS4ActorDataCombatValues; +interface DS4ActorDataHelper extends Actor.Data { + type: U; } -interface DS4ActorDataAttributes { +type DS4CharacterData = DS4ActorDataHelper; +type DS4CreatureData = DS4ActorDataHelper; + +interface DS4ActorDataDataBase { + attributes: DS4ActorDataDataAttributes; + traits: DS4ActorDataDataTraits; + combatValues: DS4ActorDataDataCombatValues; +} + +interface DS4ActorDataDataAttributes { body: ModifiableData; mobility: ModifiableData; mind: ModifiableData; } -interface DS4ActorDataTraits { +interface DS4ActorDataDataTraits { strength: ModifiableData; constitution: ModifiableData; agility: ModifiableData; @@ -26,7 +34,7 @@ interface DS4ActorDataTraits { aura: ModifiableData; } -interface DS4ActorDataCombatValues { +interface DS4ActorDataDataCombatValues { hitPoints: ResourceData; defense: ModifiableData; initiative: ModifiableData; @@ -37,34 +45,32 @@ interface DS4ActorDataCombatValues { targetedSpellcasting: ModifiableData; } -interface DS4ActorDataCharacter extends DS4ActorDataBase { - baseInfo: DS4ActorDataCharacterBaseInfo; - progression: DS4ActorDataCharacterProgression; - language: DS4ActorDataCharacterLanguage; - profile: DS4ActorDataCharacterProfile; - currency: DS4ActorDataCharacterCurrency; +interface DS4CharacterDataData extends DS4ActorDataDataBase { + baseInfo: DS4CharacterDataDataBaseInfo; + progression: DS4CharacterDataDataProgression; + language: DS4CharacterDataDataLanguage; + profile: DS4CharacterDataDataProfile; + currency: DS4CharacterDataDataCurrency; } - -interface DS4ActorDataCharacterBaseInfo { +interface DS4CharacterDataDataBaseInfo { race: string; class: string; heroClass: string; culture: string; } - -interface DS4ActorDataCharacterProgression { +interface DS4CharacterDataDataProgression { level: number; experiencePoints: number; talentPoints: UsableResource; progressPoints: UsableResource; } -interface DS4ActorDataCharacterLanguage { +interface DS4CharacterDataDataLanguage { languages: string; alphabets: string; } -interface DS4ActorDataCharacterProfile { +interface DS4CharacterDataDataProfile { biography: string; gender: string; birthday: string; @@ -77,21 +83,21 @@ interface DS4ActorDataCharacterProfile { specialCharacteristics: string; } -interface DS4ActorDataCharacterCurrency { +interface DS4CharacterDataDataCurrency { gold: number; silver: number; copper: number; } -interface DS4ActorDataCreature extends DS4ActorDataBase { - baseInfo: DS4ActorDataCreatureBaseInfo; +interface DS4CreatureDataData extends DS4ActorDataDataBase { + baseInfo: DS4CreatureDataDataBaseInfo; } type CreatureType = "animal" | "construct" | "humanoid" | "magicalEntity" | "plantBeing" | "undead"; type SizeCategory = "tiny" | "small" | "normal" | "large" | "huge" | "colossal"; -interface DS4ActorDataCreatureBaseInfo { +interface DS4CreatureDataDataBaseInfo { loot: string; foeFactor: number; creatureType: CreatureType; diff --git a/src/module/actor/actor.ts b/src/module/actor/actor.ts index 6c68e460..47623d47 100644 --- a/src/module/actor/actor.ts +++ b/src/module/actor/actor.ts @@ -1,6 +1,6 @@ import { ModifiableData } from "../common/common-data"; import { DS4Item } from "../item/item"; -import { DS4Armor, DS4Shield, ItemType } from "../item/item-data"; +import { ItemType } from "../item/item-data"; import { DS4ActorData } from "./actor-data"; export class DS4Actor extends Actor { @@ -84,10 +84,13 @@ export class DS4Actor extends Actor { */ private _calculateArmorValueOfEquippedItems(): number { return this.items - .filter((item) => ["armor", "shield"].includes(item.type)) - .map((item) => item.data.data as DS4Armor | DS4Shield) - .filter((itemData) => itemData.equipped) - .map((itemData) => itemData.armorValue) + .map((item) => { + if (item.data.type === "armor" || item.data.type === "shield") { + return item.data.data.equipped ? item.data.data.armorValue : 0; + } else { + return 0; + } + }) .reduce((a, b) => a + b, 0); } diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 470b8e31..c9adc8fc 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -128,7 +128,7 @@ export class DS4ActorSheet extends ActorSheet { * @param {JQuery.ChangeEvent} ev The originating change event * @private */ - private _onItemChange(ev: JQuery.ChangeEvent): void { + private _onItemChange(ev: JQuery.ChangeEvent): void { ev.preventDefault(); console.log("Current target:", $(ev.currentTarget).get(0)["name"]); const el: HTMLFormElement = $(ev.currentTarget).get(0); diff --git a/src/module/item/item-data.ts b/src/module/item/item-data.ts index 53736b79..33a9b67a 100644 --- a/src/module/item/item-data.ts +++ b/src/module/item/item-data.ts @@ -3,35 +3,53 @@ import { DS4 } from "../config"; export type ItemType = keyof typeof DS4.i18n.itemTypes; -export type DS4ItemData = Item.Data; +export type DS4ItemData = + | DS4WeaponData + | DS4ArmorData + | DS4ShieldData + | DS4SpellData + | DS4TrinketData + | DS4EquipmentData + | DS4TalentData + | DS4RacialAbilityData + | DS4LanguageData + | DS4AlphabetData + | DS4SpecialCreatureAbilityData; -type DS4ItemDataType = - | DS4Weapon - | DS4Armor - | DS4Shield - | DS4Spell - | DS4Trinket - | DS4Equipment - | DS4Talent - | DS4RacialAbility - | DS4Language - | DS4Alphabet - | DS4SpecialCreatureAbility; +interface DS4ItemDataHelper extends Item.Data { + type: U; +} + +type DS4WeaponData = DS4ItemDataHelper; +type DS4ArmorData = DS4ItemDataHelper; +type DS4ShieldData = DS4ItemDataHelper; +type DS4SpellData = DS4ItemDataHelper; +type DS4TrinketData = DS4ItemDataHelper; +type DS4EquipmentData = DS4ItemDataHelper; +type DS4TalentData = DS4ItemDataHelper; +type DS4RacialAbilityData = DS4ItemDataHelper; +type DS4LanguageData = DS4ItemDataHelper; +type DS4AlphabetData = DS4ItemDataHelper; +type DS4SpecialCreatureAbilityData = DS4ItemDataHelper; // types -interface DS4Weapon extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable { +interface DS4WeaponDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical, DS4ItemDataDataEquipable { attackType: "melee" | "ranged" | "meleeRanged"; weaponBonus: number; opponentDefense: number; } -export interface DS4Armor extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable, DS4ItemProtective { +interface DS4ArmorDataData + extends DS4ItemDataDataBase, + DS4ItemDataDataPhysical, + DS4ItemDataDataEquipable, + DS4ItemDataDataProtective { armorMaterialType: "cloth" | "leather" | "chain" | "plate"; armorType: "body" | "helmet" | "vambrace" | "greaves" | "vambraceGreaves"; } -export interface DS4Talent extends DS4ItemBase { +interface DS4TalentDataData extends DS4ItemDataDataBase { rank: DS4TalentRank; } @@ -39,7 +57,7 @@ interface DS4TalentRank extends ModifiableData { max: number; } -interface DS4Spell extends DS4ItemBase, DS4ItemEquipable { +interface DS4SpellDataData extends DS4ItemDataDataBase, DS4ItemDataDataEquipable { spellType: "spellcasting" | "targetedSpellcasting"; bonus: string; spellCategory: @@ -59,37 +77,41 @@ interface DS4Spell extends DS4ItemBase, DS4ItemEquipable { scrollPrice: number; } -export interface DS4Shield extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable, DS4ItemProtective {} -interface DS4Trinket extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable {} -interface DS4Equipment extends DS4ItemBase, DS4ItemPhysical {} -type DS4RacialAbility = DS4ItemBase; -type DS4Language = DS4ItemBase; -type DS4Alphabet = DS4ItemBase; -interface DS4SpecialCreatureAbility extends DS4ItemBase { +interface DS4ShieldDataData + extends DS4ItemDataDataBase, + DS4ItemDataDataPhysical, + DS4ItemDataDataEquipable, + DS4ItemDataDataProtective {} +interface DS4TrinketDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical, DS4ItemDataDataEquipable {} +interface DS4EquipmentDataData extends DS4ItemDataDataBase, DS4ItemDataDataPhysical {} +type DS4RacialAbilityDataData = DS4ItemDataDataBase; +type DS4LanguageDataData = DS4ItemDataDataBase; +type DS4AlphabetDataData = DS4ItemDataDataBase; +interface DS4SpecialCreatureAbilityDataData extends DS4ItemDataDataBase { experiencePoints: number; } // templates -interface DS4ItemBase { +interface DS4ItemDataDataBase { description: string; } -interface DS4ItemPhysical { +interface DS4ItemDataDataPhysical { quantity: number; price: number; availability: "hamlet" | "village" | "city" | "elves" | "dwarves" | "nowhere" | "unset"; storageLocation: string; } -export function isDS4ItemDataTypePhysical(input: DS4ItemDataType): boolean { +export function isDS4ItemDataTypePhysical(input: DS4ItemData["data"]): boolean { return "quantity" in input && "price" in input && "availability" in input && "storageLocation" in input; } -interface DS4ItemEquipable { +interface DS4ItemDataDataEquipable { equipped: boolean; } -interface DS4ItemProtective { +interface DS4ItemDataDataProtective { armorValue: number; } diff --git a/src/module/item/item.ts b/src/module/item/item.ts index 4944a12c..0226b5bb 100644 --- a/src/module/item/item.ts +++ b/src/module/item/item.ts @@ -1,4 +1,4 @@ -import { DS4ItemData, DS4Talent } from "./item-data"; +import { DS4ItemData } from "./item-data"; /** * Extend the basic Item with some very simple modifications. @@ -19,8 +19,8 @@ export class DS4Item extends Item { } prepareDerivedData(): void { - if (this.type === "talent") { - const data = this.data.data as DS4Talent; + if (this.data.type === "talent") { + const data = this.data.data; data.rank.total = data.rank.base + data.rank.mod; } }