import { HIDE_DICE, renderTemplate, SHOW_DICE } from "./constants.js"; import { RdDUtility } from "./rdd-utility.js"; /** * Extend the base Dialog entity by defining a custom window to perform roll. * @extends {Dialog} */ export class DialogValidationEncaissement extends Dialog { static async validerEncaissement(actor, dmg, armure, onEncaisser) { const encaissement = await RdDUtility.jetEncaissement(actor, dmg, armure, { showDice: HIDE_DICE }); const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-validation-encaissement.hbs', { actor: actor, encaissement: encaissement }); new DialogValidationEncaissement(html, actor, dmg, armure, encaissement, onEncaisser).render(true); } /* -------------------------------------------- */ constructor(html, actor, dmg, armure, encaissement, onEncaisser) { // Common conf let buttons = { "valider": { label: "Valider", callback: html => this.onValider() }, "annuler": { label: "Annuler", callback: html => { } }, }; let dialogConf = { title: "Validation d'encaissement", content: html, buttons: buttons, default: "valider" } let dialogOptions = { classes: ["rdd-roll-dialog"], width: 350, height: 290 } // Select proper roll dialog template and stuff super(dialogConf, dialogOptions); this.actor = actor this.dmg = dmg this.armure = armure this.encaissement = encaissement this.onEncaisser = onEncaisser this.forceDiceResult = {total: encaissement.roll.result } } /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html); this.html = html; this.html.find('input.encaissement-roll-result').keyup(async event => { this.forceDiceResult.total = event.currentTarget.value; this.encaissement = await RdDUtility.jetEncaissement(this.actor, this.dmg, this.armure, { showDice: HIDE_DICE, forceDiceResult: this.forceDiceResult}); this.html.find('label.encaissement-total').text(this.encaissement.total); this.html.find('label.encaissement-blessure').text(this.encaissement.blessures) }); } async onValider() { this.encaissement = await RdDUtility.jetEncaissement(this.actor, this.dmg, this.armure, { showDice: SHOW_DICE, forceDiceResult: this.forceDiceResult}); this.onEncaisser(this.encaissement) } }