foundryvtt-reve-de-dragon/module/rdd-roll-ethylisme.js

46 lines
1.4 KiB
JavaScript

import { Misc } from "./misc.js";
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog}
*/
export class RdDRollDialogEthylisme extends Dialog {
/* -------------------------------------------- */
constructor(html, rollData, actor, onRoll) {
// Common conf
let dialogConf = {
title: "Test d'éthylisme",
content: html,
default: "rollButton",
buttons: { "rollButton": { label: "Test d'éthylisme", callback: html => onRoll(this.rollData) } }
};
let dialogOptions = { classes: ["rdd-roll-dialog"], width: 400, height: 'fit-content', 'z-index': 99999 }
super(dialogConf, dialogOptions)
this.rollData = rollData;
this.actor = actor;
}
activateListeners(html) {
super.activateListeners(html);
this.html = html;
this.bringToTop();
this.html.find(".force-alcool").change((event) => {
this.rollData.forceAlcool = Misc.toInt(event.currentTarget.value);
this.updateRollResult();
});
this.html.find(".force-alcool").val(Misc.toInt(this.rollData.forceAlcool));
this.updateRollResult();
}
/* -------------------------------------------- */
async updateRollResult() {
this.html.find(".roll-ethylisme").text(this.rollData.vie + " / " + Misc.toSignedString(Number(this.rollData.etat) + Number(this.rollData.forceAlcool) + this.rollData.diffNbDoses));
this.html.find(".table-resolution").remove();
}
}