ds4/src/item/spell/spell-sheet.ts

35 lines
1.1 KiB
TypeScript

// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { getGame } from "../../helpers";
import { DS4ItemSheet } from "../item-sheet";
import { calculateManaCost } from "./calculate-mana-const";
import type { DS4Item } from "../item";
export class DS4SpellSheet extends DS4ItemSheet {
/** @override */
activateListeners(html: JQuery): void {
super.activateListeners(html);
if (!this.options.editable) return;
html.find(".ds4-calculate-mana-cost").on("click", this.onCalculateManaCost.bind(this));
}
/** Calculates the mana cost of the spell automatically. */
protected onCalculateManaCost(): void {
const game = getGame();
const manaCost = calculateManaCost(this.item.data.data);
Dialog.confirm({
title: game.i18n.localize("DS4.CalculateManaCost"),
content: game.i18n.localize("DS4.CalculateManaCostConfirmationQuestion"),
yes: () => this.item.update({ data: { manaCost } }),
});
}
}
export interface DS4SpellSheet {
object: DS4Item & { data: { type: "spell"; _source: { type: "spell" } } };
}