From d443b339d8c285827bff35faaadfae60719a1a68 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Sat, 26 Jun 2021 11:42:50 +0200 Subject: [PATCH] Improve code slightly in a couple of places --- src/module/actor/actor.ts | 23 ++++++++++++++--------- src/module/item/item-prepared-data.ts | 22 +++++++++++----------- src/module/item/item-sheet.ts | 10 +++------- src/module/item/item.ts | 4 +--- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/module/actor/actor.ts b/src/module/actor/actor.ts index a887838c..8ca08128 100644 --- a/src/module/actor/actor.ts +++ b/src/module/actor/actor.ts @@ -2,6 +2,7 @@ import { ModifiableDataBaseTotal } from "../common/common-data"; import { DS4 } from "../config"; import { DS4Item } from "../item/item"; import { ItemType } from "../item/item-data"; +import { DS4ArmorPreparedData, DS4ShieldPreparedData } from "../item/item-prepared-data"; import { createCheckRoll } from "../rolls/check-factory"; import { DS4ActorData, isAttribute, isTrait } from "./actor-data"; import { Check, DS4ActorPreparedData } from "./actor-prepared-data"; @@ -208,13 +209,13 @@ export class DS4Actor extends Actor */ protected _calculateArmorValueOfEquippedItems(): number { return this.items - .map((item) => { - if (item.data.type === "armor" || item.data.type === "shield") { - return item.data.data.equipped ? item.data.data.armorValue : 0; - } else { - return 0; - } - }) + .map((item) => item.data) + .filter( + (data): data is DS4ArmorPreparedData | DS4ShieldPreparedData => + data.type === "armor" || data.type === "shield", + ) + .filter((data) => data.data.equipped) + .map((data) => data.data.armorValue) .reduce((a, b) => a + b, 0); } @@ -340,7 +341,9 @@ export class DS4Actor extends Actor throw new Error( game.i18n.format("DS4.ErrorUnexpectedAttribute", { actualAttribute: selectedAttribute, - expectedTypes: "'body', 'agility', 'mind'", + expectedTypes: Object.keys(DS4.i18n.attributes) + .map((attribute) => `'${attribute}'`) + .join(", "), }), ); } @@ -349,7 +352,9 @@ export class DS4Actor extends Actor throw new Error( game.i18n.format("DS4.ErrorUnexpectedTrait", { actualTrait: selectedTrait, - expectedTypes: "'strength', 'constitution', 'agility', 'dexterity', 'intellect', 'aura'", + expectedTypes: Object.keys(DS4.i18n.traits) + .map((attribute) => `'${attribute}'`) + .join(", "), }), ); } diff --git a/src/module/item/item-prepared-data.ts b/src/module/item/item-prepared-data.ts index 6a9b4574..1a88fcfd 100644 --- a/src/module/item/item-prepared-data.ts +++ b/src/module/item/item-prepared-data.ts @@ -28,17 +28,17 @@ export type DS4ItemPreparedData = | DS4AlphabetPreparedData | DS4SpecialCreatureAbilityPreparedData; -type DS4WeaponPreparedData = DS4ItemDataHelper; -type DS4ArmorPreparedData = DS4ItemDataHelper; -type DS4ShieldPreparedData = DS4ItemDataHelper; -type DS4SpellPreparedData = DS4ItemDataHelper; -type DS4EquipmentPreparedData = DS4ItemDataHelper; -type DS4LootPreparedData = DS4ItemDataHelper; -type DS4TalentPreparedData = DS4ItemDataHelper; -type DS4RacialAbilityPreparedData = DS4ItemDataHelper; -type DS4LanguagePreparedData = DS4ItemDataHelper; -type DS4AlphabetPreparedData = DS4ItemDataHelper; -type DS4SpecialCreatureAbilityPreparedData = DS4ItemDataHelper< +export type DS4WeaponPreparedData = DS4ItemDataHelper; +export type DS4ArmorPreparedData = DS4ItemDataHelper; +export type DS4ShieldPreparedData = DS4ItemDataHelper; +export type DS4SpellPreparedData = DS4ItemDataHelper; +export type DS4EquipmentPreparedData = DS4ItemDataHelper; +export type DS4LootPreparedData = DS4ItemDataHelper; +export type DS4TalentPreparedData = DS4ItemDataHelper; +export type DS4RacialAbilityPreparedData = DS4ItemDataHelper; +export type DS4LanguagePreparedData = DS4ItemDataHelper; +export type DS4AlphabetPreparedData = DS4ItemDataHelper; +export type DS4SpecialCreatureAbilityPreparedData = DS4ItemDataHelper< DS4SpecialCreatureAbilityPreparedDataData, "specialCreatureAbility" >; diff --git a/src/module/item/item-sheet.ts b/src/module/item/item-sheet.ts index edf49f0b..31ffde93 100644 --- a/src/module/item/item-sheet.ts +++ b/src/module/item/item-sheet.ts @@ -41,13 +41,9 @@ export class DS4ItemSheet extends ItemSheet> { /** @override */ setPosition(options: Partial = {}): Application.Position & { height: number } { const position = super.setPosition(options); - if ("find" in this.element) { - const sheetBody = this.element.find(".sheet-body"); - const bodyHeight = position.height - 192; - sheetBody.css("height", bodyHeight); - } else { - console.log("Failure setting position."); - } + const sheetBody = this.element.find(".sheet-body"); + const bodyHeight = position.height - 192; + sheetBody.css("height", bodyHeight); return position; } diff --git a/src/module/item/item.ts b/src/module/item/item.ts index 4c6bfd4a..46984672 100644 --- a/src/module/item/item.ts +++ b/src/module/item/item.ts @@ -156,7 +156,7 @@ export class DS4Item extends Item { if (attackType === "meleeRanged") { const { melee, ranged } = { ...DS4.i18n.attackTypes }; const identifier = "attack-type-selection"; - const answer = Dialog.prompt({ + return Dialog.prompt({ title: game.i18n.localize("DS4.DialogAttackTypeSelection"), content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", { selects: [ @@ -180,9 +180,7 @@ export class DS4Item extends Item { } return `${selectedAttackType}Attack` as const; }, - options: { jQuery: true }, }); - return answer; } else { return `${attackType}Attack` as const; }