diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 6e734ad7..48fb2f32 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -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 { 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> { - 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> { + // 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): ActorSheet.Data { - const valueGroups = [data.data.attributes, data.data.traits, data.data.combatValues]; + // protected _addTooltipsToData(data: ActorSheet.Data): ActorSheet.Data { + // const valueGroups = [data.data.attributes, data.data.traits, data.data.combatValues]; - valueGroups.forEach((valueGroup) => { - Object.values(valueGroup).forEach((attribute: ModifiableDataBaseTotal & { tooltip?: string }) => { - attribute.tooltip = this._getTooltipForValue(attribute); - }); - }); - return data; - } + // valueGroups.forEach((valueGroup) => { + // Object.values(valueGroup).forEach((attribute: ModifiableDataBaseTotal & { tooltip?: string }) => { + // attribute.tooltip = this._getTooltipForValue(attribute); + // }); + // }); + // return data; + // } protected _getTooltipForValue(value: ModifiableDataBaseTotal): string { return `${value.base} (${game.i18n.localize("DS4.TooltipBaseValue")}) + ${value.mod} (${game.i18n.localize( diff --git a/src/module/item/item-sheet.ts b/src/module/item/item-sheet.ts index 5e53175d..44eb35a1 100644 --- a/src/module/item/item-sheet.ts +++ b/src/module/item/item-sheet.ts @@ -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> { - 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> { + // 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 & { height: number }) | undefined { const position = super.setPosition(options); diff --git a/src/module/item/item.ts b/src/module/item/item.ts index 928bd89f..3077521e 100644 --- a/src/module/item/item.ts +++ b/src/module/item/item.ts @@ -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 { - 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 { + protected async rollWeapon(): Promise { 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 { + protected async rollSpell(): Promise { 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; - } } diff --git a/tsconfig.json b/tsconfig.json index 55672c07..a0f5fb6a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] }