import { MAGICS, SUBTYPES } from "../../../config/constants.js" import { CDEBaseActorSheet } from "./base.js" export class CDECharacterSheet extends CDEBaseActorSheet { static DEFAULT_OPTIONS = { classes: ["character"], } static PARTS = { main: { template: "systems/fvtt-chroniques-de-l-etrange/templates/actor/cde-character-sheet.html" }, } tabGroups = { primary: "description" } async _prepareContext() { const context = await super._prepareContext() context.equipments = context.items.filter((item) => item.type === "item") context.spells = context.items.filter((item) => item.type === "spell") context.kungfus = context.items.filter((item) => item.type === "kungfu") context.CDE = { MAGICS, SUBTYPES } return context } _onRender(context, options) { super._onRender?.(context, options) this.#bindInitiativeControls() this.#bindPrefs() } #bindInitiativeControls() { const buttons = this.element?.querySelectorAll(".click-initiative") if (!buttons?.length) return buttons.forEach((button) => { button.addEventListener("click", async () => { const action = button.dataset.libelId let initiative = this.document.system.initiative ?? 1 if (action === "plus") { initiative = initiative >= 24 ? 1 : initiative + 1 await this.document.update({ "system.initiative": initiative }) return } if (action === "minus") { initiative = initiative <= 1 ? 24 : initiative - 1 await this.document.update({ "system.initiative": initiative }) return } if (action === "create") { const html = `
` const value = await Dialog.prompt({ title: game.i18n.localize("CDE.TurnOrder"), content: html, label: game.i18n.localize("CDE.Validate"), callback: (dlg) => { const input = dlg.querySelector("input[name='initiative']") return Number(input?.value ?? initiative) }, }) if (Number.isFinite(value)) { const sanitized = foundry.utils.clamp(Number(value), 1, 24) await this.document.update({ "system.initiative": sanitized }) } } }) }) } #bindPrefs() { const button = this.element?.querySelector(".click-prefs") if (!button) return button.addEventListener("click", async () => { const current = this.document.system.prefs?.typeofthrow ?? { choice: "0", check: true } const html = ` ` const prefs = await Dialog.prompt({ title: game.i18n.localize("CDE.Preferences"), content: html, label: game.i18n.localize("CDE.Validate"), callback: (dlg) => { const choice = dlg.querySelector("select[name='choice']")?.value ?? "0" const check = dlg.querySelector("input[name='check']")?.checked ?? false return { choice, check } }, }) if (prefs) { await this.document.update({ "system.prefs.typeofthrow.choice": String(prefs.choice), "system.prefs.typeofthrow.check": !!prefs.check, }) } }) } }