2022-10-09 02:19:33 +02:00
|
|
|
import { HIDE_DICE, 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 {
|
|
|
|
|
2023-11-04 03:42:39 +01:00
|
|
|
static async validerEncaissement(actor, rollData, armure, onEncaisser) {
|
2022-10-09 02:19:33 +02:00
|
|
|
let encaissement = await RdDUtility.jetEncaissement(rollData, armure, { showDice: HIDE_DICE });
|
|
|
|
const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-validation-encaissement.html', {
|
|
|
|
actor: actor,
|
|
|
|
rollData: rollData,
|
2023-11-04 03:42:39 +01:00
|
|
|
encaissement: encaissement
|
2022-10-09 02:19:33 +02:00
|
|
|
});
|
2023-11-04 03:42:39 +01:00
|
|
|
const dialog = new DialogValidationEncaissement(html, actor, rollData, armure, encaissement, onEncaisser);
|
2022-10-09 02:19:33 +02:00
|
|
|
dialog.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2023-11-04 03:42:39 +01:00
|
|
|
constructor(html, actor, rollData, armure, encaissement, onEncaisser) {
|
2022-10-09 02:19:33 +02:00
|
|
|
// Common conf
|
|
|
|
let buttons = {
|
2023-03-30 00:19:12 +02:00
|
|
|
"valider": { label: "Valider", callback: html => this.onValider() },
|
2022-10-09 02:19:33 +02:00
|
|
|
"annuler": { label: "Annuler", callback: html => { } },
|
|
|
|
};
|
|
|
|
|
|
|
|
let dialogConf = {
|
|
|
|
title: "Validation d'encaissement",
|
|
|
|
content: html,
|
|
|
|
buttons: buttons,
|
|
|
|
default: "valider"
|
|
|
|
}
|
|
|
|
|
|
|
|
let dialogOptions = {
|
2022-12-06 01:30:12 +01:00
|
|
|
classes: ["rdd-roll-dialog"],
|
2022-10-09 02:19:33 +02:00
|
|
|
width: 350,
|
|
|
|
height: 290
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select proper roll dialog template and stuff
|
|
|
|
super(dialogConf, dialogOptions);
|
|
|
|
|
|
|
|
this.actor = actor
|
|
|
|
this.rollData = rollData;
|
|
|
|
this.armure = armure;
|
|
|
|
this.encaissement = encaissement;
|
|
|
|
this.onEncaisser = onEncaisser;
|
|
|
|
this.forceDiceResult = {total: encaissement.roll.result };
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html = html;
|
|
|
|
this.html.find('input.encaissement-roll-result').keyup(async event => {
|
2022-10-09 02:19:33 +02:00
|
|
|
this.forceDiceResult.total = event.currentTarget.value;
|
|
|
|
this.encaissement = await RdDUtility.jetEncaissement(this.rollData, this.armure, { showDice: HIDE_DICE, forceDiceResult: this.forceDiceResult});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('label.encaissement-total').text(this.encaissement.total);
|
|
|
|
this.html.find('label.encaissement-blessure').text(this.encaissement.blessures)
|
2022-10-09 02:19:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 00:19:12 +02:00
|
|
|
async onValider() {
|
2022-10-09 02:19:33 +02:00
|
|
|
this.encaissement = await RdDUtility.jetEncaissement(this.rollData, this.armure, { showDice: SHOW_DICE, forceDiceResult: this.forceDiceResult});
|
2023-11-04 03:42:39 +01:00
|
|
|
this.onEncaisser(this.encaissement)
|
2022-10-09 02:19:33 +02:00
|
|
|
}
|
|
|
|
}
|