Improve code slightly in a couple of places

This commit is contained in:
Johannes Loher 2021-06-26 11:42:50 +02:00
parent 5b26dbb00a
commit d443b339d8
4 changed files with 29 additions and 30 deletions

View file

@ -2,6 +2,7 @@ import { ModifiableDataBaseTotal } from "../common/common-data";
import { DS4 } from "../config"; import { DS4 } from "../config";
import { DS4Item } from "../item/item"; import { DS4Item } from "../item/item";
import { ItemType } from "../item/item-data"; import { ItemType } from "../item/item-data";
import { DS4ArmorPreparedData, DS4ShieldPreparedData } from "../item/item-prepared-data";
import { createCheckRoll } from "../rolls/check-factory"; import { createCheckRoll } from "../rolls/check-factory";
import { DS4ActorData, isAttribute, isTrait } from "./actor-data"; import { DS4ActorData, isAttribute, isTrait } from "./actor-data";
import { Check, DS4ActorPreparedData } from "./actor-prepared-data"; import { Check, DS4ActorPreparedData } from "./actor-prepared-data";
@ -208,13 +209,13 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
*/ */
protected _calculateArmorValueOfEquippedItems(): number { protected _calculateArmorValueOfEquippedItems(): number {
return this.items return this.items
.map((item) => { .map((item) => item.data)
if (item.data.type === "armor" || item.data.type === "shield") { .filter(
return item.data.data.equipped ? item.data.data.armorValue : 0; (data): data is DS4ArmorPreparedData | DS4ShieldPreparedData =>
} else { data.type === "armor" || data.type === "shield",
return 0; )
} .filter((data) => data.data.equipped)
}) .map((data) => data.data.armorValue)
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
} }
@ -340,7 +341,9 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorUnexpectedAttribute", { game.i18n.format("DS4.ErrorUnexpectedAttribute", {
actualAttribute: selectedAttribute, 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<DS4ActorData, DS4Item, DS4ActorPreparedData>
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorUnexpectedTrait", { game.i18n.format("DS4.ErrorUnexpectedTrait", {
actualTrait: selectedTrait, actualTrait: selectedTrait,
expectedTypes: "'strength', 'constitution', 'agility', 'dexterity', 'intellect', 'aura'", expectedTypes: Object.keys(DS4.i18n.traits)
.map((attribute) => `'${attribute}'`)
.join(", "),
}), }),
); );
} }

View file

@ -28,17 +28,17 @@ export type DS4ItemPreparedData =
| DS4AlphabetPreparedData | DS4AlphabetPreparedData
| DS4SpecialCreatureAbilityPreparedData; | DS4SpecialCreatureAbilityPreparedData;
type DS4WeaponPreparedData = DS4ItemDataHelper<DS4WeaponPreparedDataData, "weapon">; export type DS4WeaponPreparedData = DS4ItemDataHelper<DS4WeaponPreparedDataData, "weapon">;
type DS4ArmorPreparedData = DS4ItemDataHelper<DS4ArmorPreparedDataData, "armor">; export type DS4ArmorPreparedData = DS4ItemDataHelper<DS4ArmorPreparedDataData, "armor">;
type DS4ShieldPreparedData = DS4ItemDataHelper<DS4ShieldPreparedDataData, "shield">; export type DS4ShieldPreparedData = DS4ItemDataHelper<DS4ShieldPreparedDataData, "shield">;
type DS4SpellPreparedData = DS4ItemDataHelper<DS4SpellPreparedDataData, "spell">; export type DS4SpellPreparedData = DS4ItemDataHelper<DS4SpellPreparedDataData, "spell">;
type DS4EquipmentPreparedData = DS4ItemDataHelper<DS4EquipmentPreparedDataData, "equipment">; export type DS4EquipmentPreparedData = DS4ItemDataHelper<DS4EquipmentPreparedDataData, "equipment">;
type DS4LootPreparedData = DS4ItemDataHelper<DS4LootPreparedDataData, "loot">; export type DS4LootPreparedData = DS4ItemDataHelper<DS4LootPreparedDataData, "loot">;
type DS4TalentPreparedData = DS4ItemDataHelper<DS4TalentPreparedDataData, "talent">; export type DS4TalentPreparedData = DS4ItemDataHelper<DS4TalentPreparedDataData, "talent">;
type DS4RacialAbilityPreparedData = DS4ItemDataHelper<DS4RacialAbilityPreparedDataData, "racialAbility">; export type DS4RacialAbilityPreparedData = DS4ItemDataHelper<DS4RacialAbilityPreparedDataData, "racialAbility">;
type DS4LanguagePreparedData = DS4ItemDataHelper<DS4LanguagePreparedDataData, "language">; export type DS4LanguagePreparedData = DS4ItemDataHelper<DS4LanguagePreparedDataData, "language">;
type DS4AlphabetPreparedData = DS4ItemDataHelper<DS4AlphabetPreparedDataData, "alphabet">; export type DS4AlphabetPreparedData = DS4ItemDataHelper<DS4AlphabetPreparedDataData, "alphabet">;
type DS4SpecialCreatureAbilityPreparedData = DS4ItemDataHelper< export type DS4SpecialCreatureAbilityPreparedData = DS4ItemDataHelper<
DS4SpecialCreatureAbilityPreparedDataData, DS4SpecialCreatureAbilityPreparedDataData,
"specialCreatureAbility" "specialCreatureAbility"
>; >;

View file

@ -41,13 +41,9 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Data<DS4Item>> {
/** @override */ /** @override */
setPosition(options: Partial<Application.Position> = {}): Application.Position & { height: number } { setPosition(options: Partial<Application.Position> = {}): Application.Position & { height: number } {
const position = super.setPosition(options); const position = super.setPosition(options);
if ("find" in this.element) {
const sheetBody = this.element.find(".sheet-body"); const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192; const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight); sheetBody.css("height", bodyHeight);
} else {
console.log("Failure setting position.");
}
return position; return position;
} }

View file

@ -156,7 +156,7 @@ export class DS4Item extends Item<DS4ItemData, DS4ItemPreparedData> {
if (attackType === "meleeRanged") { if (attackType === "meleeRanged") {
const { melee, ranged } = { ...DS4.i18n.attackTypes }; const { melee, ranged } = { ...DS4.i18n.attackTypes };
const identifier = "attack-type-selection"; const identifier = "attack-type-selection";
const answer = Dialog.prompt({ return Dialog.prompt({
title: game.i18n.localize("DS4.DialogAttackTypeSelection"), title: game.i18n.localize("DS4.DialogAttackTypeSelection"),
content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", { content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", {
selects: [ selects: [
@ -180,9 +180,7 @@ export class DS4Item extends Item<DS4ItemData, DS4ItemPreparedData> {
} }
return `${selectedAttackType}Attack` as const; return `${selectedAttackType}Attack` as const;
}, },
options: { jQuery: true },
}); });
return answer;
} else { } else {
return `${attackType}Attack` as const; return `${attackType}Attack` as const;
} }