Make DS4Item compile and commen getData methods for now

This commit is contained in:
Johannes Loher 2021-06-30 12:54:39 +02:00
parent 446340c064
commit 918fa5081b
4 changed files with 62 additions and 72 deletions

View file

@ -9,7 +9,6 @@ import { ModifiableDataBaseTotal } from "../../common/common-data";
import { DS4 } from "../../config";
import { getCanvas } from "../../helpers";
import { DS4Item } from "../../item/item";
import { DS4ItemData } from "../../item/item-data-source";
import { getDS4Settings } from "../../settings";
import notifications from "../../ui/notifications";
import { DS4Actor } from "../actor";
@ -51,39 +50,39 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options> {
return `${basePath}/${this.actor.data.type}-sheet.hbs`;
}
/**
* This method returns the data for the template of the actor sheet.
* It explicitly adds the items of the object sorted by type in the
* object itemsByType.
* @returns The data fed to the template of the actor sheet
*/
async getData(): Promise<ActorSheet.Data<DS4Actor>> {
const itemsByType = Object.fromEntries(
Object.entries(this.actor.itemTypes).map(([itemType, items]) => {
return [itemType, items.map((item) => item.data).sort((a, b) => (a.sort || 0) - (b.sort || 0))];
}),
);
const data = {
...this._addTooltipsToData(await super.getData()),
// Add the localization config to the data:
config: DS4,
// Add the items explicitly sorted by type to the data:
itemsByType,
settings: getDS4Settings(),
};
return data;
}
// /**
// * This method returns the data for the template of the actor sheet.
// * It explicitly adds the items of the object sorted by type in the
// * object itemsByType.
// * @returns The data fed to the template of the actor sheet
// */
// async getData(): Promise<ActorSheet.Data<DS4Actor>> {
// const itemsByType = Object.fromEntries(
// Object.entries(this.actor.itemTypes).map(([itemType, items]) => {
// return [itemType, items.map((item) => item.data).sort((a, b) => (a.sort || 0) - (b.sort || 0))];
// }),
// );
// const data = {
// ...this._addTooltipsToData(await super.getData()),
// // Add the localization config to the data:
// config: DS4,
// // Add the items explicitly sorted by type to the data:
// itemsByType,
// settings: getDS4Settings(),
// };
// return data;
// }
protected _addTooltipsToData(data: ActorSheet.Data<DS4Actor>): ActorSheet.Data<DS4Actor> {
const valueGroups = [data.data.attributes, data.data.traits, data.data.combatValues];
// protected _addTooltipsToData(data: ActorSheet.Data<DS4Actor>): ActorSheet.Data<DS4Actor> {
// const valueGroups = [data.data.attributes, data.data.traits, data.data.combatValues];
valueGroups.forEach((valueGroup) => {
Object.values(valueGroup).forEach((attribute: ModifiableDataBaseTotal<number> & { tooltip?: string }) => {
attribute.tooltip = this._getTooltipForValue(attribute);
});
});
return data;
}
// valueGroups.forEach((valueGroup) => {
// Object.values(valueGroup).forEach((attribute: ModifiableDataBaseTotal<number> & { tooltip?: string }) => {
// attribute.tooltip = this._getTooltipForValue(attribute);
// });
// });
// return data;
// }
protected _getTooltipForValue(value: ModifiableDataBaseTotal<number>): string {
return `${value.base} (${game.i18n.localize("DS4.TooltipBaseValue")}) + ${value.mod} (${game.i18n.localize(

View file

@ -32,19 +32,17 @@ export class DS4ItemSheet extends ItemSheet {
const basePath = "systems/ds4/templates/sheets/item";
return `${basePath}/${this.item.data.type}-sheet.hbs`;
}
/** @override */
async getData(): Promise<ItemSheet.Data<DS4Item>> {
const data = {
...(await super.getData()),
config: DS4,
isOwned: this.item.isOwned,
actor: this.item.actor,
isPhysical: isDS4ItemDataTypePhysical(this.item.data.data),
};
return data;
}
// /** @override */
// async getData(): Promise<ItemSheet.Data<DS4Item>> {
// const data = {
// ...(await super.getData()),
// config: DS4,
// isOwned: this.item.isOwned,
// actor: this.item.actor,
// isPhysical: isDS4ItemDataTypePhysical(this.item.data.data),
// };
// return data;
// }
/** @override */
setPosition(options: Partial<Application.Position> = {}): (Application.Position & { height: number }) | undefined {
const position = super.setPosition(options);

View file

@ -3,7 +3,6 @@
//
// SPDX-License-Identifier: MIT
import { DS4Actor } from "../actor/actor";
import { DS4 } from "../config";
import { createCheckRoll } from "../rolls/check-factory";
import notifications from "../ui/notifications";
@ -20,14 +19,12 @@ declare global {
* The Item class for DS4
*/
export class DS4Item extends Item {
/**
* @override
*/
/** @override */
prepareData(): void {
super.prepareData();
this.prepareDerivedData();
}
/** @override */
prepareDerivedData(): void {
if (this.data.type === "talent") {
const data = this.data.data;
@ -68,10 +65,6 @@ export class DS4Item extends Item {
* Roll a check for an action with this item.
*/
async roll(): Promise<void> {
if (!this.isOwnedItem()) {
throw new Error(game.i18n.format("DS4.ErrorCannotRollUnownedItem", { name: this.name, id: this.id }));
}
switch (this.data.type) {
case "weapon":
return this.rollWeapon();
@ -82,7 +75,7 @@ export class DS4Item extends Item {
}
}
protected async rollWeapon(this: this & { readonly actor: DS4Actor }): Promise<void> {
protected async rollWeapon(): Promise<void> {
if (!(this.data.type === "weapon")) {
throw new Error(
game.i18n.format("DS4.ErrorWrongItemType", {
@ -104,8 +97,11 @@ export class DS4Item extends Item {
);
}
const actor = this.actor;
const ownerDataData = actor.data.data;
if (!this.actor) {
throw new Error(game.i18n.format("DS4.ErrorCannotRollUnownedItem", { name: this.name, id: this.id }));
}
const ownerDataData = this.actor.data.data;
const weaponBonus = this.data.data.weaponBonus;
const combatValue = await this.getCombatValueKeyForAttackType(this.data.data.attackType);
const checkTargetNumber = ownerDataData.combatValues[combatValue].total + weaponBonus;
@ -114,11 +110,11 @@ export class DS4Item extends Item {
rollMode: game.settings.get("core", "rollMode"),
maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ItemWeaponCheckFlavor", { actor: actor.name, weapon: this.name }),
flavor: game.i18n.format("DS4.ItemWeaponCheckFlavor", { actor: this.actor.name, weapon: this.name }),
});
}
protected async rollSpell(this: this & { readonly actor: DS4Actor }): Promise<void> {
protected async rollSpell(): Promise<void> {
if (!(this.data.type === "spell")) {
throw new Error(
game.i18n.format("DS4.ErrorWrongItemType", {
@ -140,8 +136,11 @@ export class DS4Item extends Item {
);
}
const actor = this.actor;
const ownerDataData = actor.data.data;
if (!this.actor) {
throw new Error(game.i18n.format("DS4.ErrorCannotRollUnownedItem", { name: this.name, id: this.id }));
}
const ownerDataData = this.actor.data.data;
const spellBonus = Number.isNumeric(this.data.data.bonus) ? parseInt(this.data.data.bonus) : undefined;
if (spellBonus === undefined) {
notifications.info(
@ -158,7 +157,7 @@ export class DS4Item extends Item {
rollMode: game.settings.get("core", "rollMode"),
maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ItemSpellCheckFlavor", { actor: actor.name, spell: this.name }),
flavor: game.i18n.format("DS4.ItemSpellCheckFlavor", { actor: this.actor.name, spell: this.name }),
});
}
@ -195,11 +194,4 @@ export class DS4Item extends Item {
return `${attackType}Attack` as const;
}
}
/**
* Type-guarding variant to check if the item is owned.
*/
isOwnedItem(): this is this & { readonly isOwned: true; readonly actor: DS4Actor; readonly parent: DS4Actor } {
return this.isOwned;
}
}

View file

@ -3,11 +3,12 @@
"target": "ES2020",
"lib": ["DOM", "ES2020"],
"types": ["@league-of-foundry-developers/foundry-vtt-types"],
"esModuleInterop": true,
// "esModuleInterop": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
// "forceConsistentCasingInFileNames": true,
"strict": true,
"sourceMap": true
"sourceMap": true,
"outDir": "foooo"
},
"include": ["src"]
}