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 { 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<DS4ActorData, DS4Item, DS4ActorPreparedData>
*/
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<DS4ActorData, DS4Item, DS4ActorPreparedData>
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<DS4ActorData, DS4Item, DS4ActorPreparedData>
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(", "),
}),
);
}

View file

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

View file

@ -41,13 +41,9 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Data<DS4Item>> {
/** @override */
setPosition(options: Partial<Application.Position> = {}): 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.");
}
return position;
}

View file

@ -156,7 +156,7 @@ export class DS4Item extends Item<DS4ItemData, DS4ItemPreparedData> {
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<DS4ItemData, DS4ItemPreparedData> {
}
return `${selectedAttackType}Attack` as const;
},
options: { jQuery: true },
});
return answer;
} else {
return `${attackType}Attack` as const;
}