2020-12-06 20:11:30 +01:00
|
|
|
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 {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-04-06 23:39:27 +02:00
|
|
|
constructor(html, rollData, actor, onRoll) {
|
2020-12-06 20:11:30 +01:00
|
|
|
// Common conf
|
2021-04-06 23:39:27 +02:00
|
|
|
let dialogConf = {
|
|
|
|
title: "Test d'éthylisme",
|
|
|
|
content: html,
|
|
|
|
default: "rollButton",
|
2022-12-09 02:00:31 +01:00
|
|
|
buttons: { "rollButton": { label: "Test d'éthylisme", callback: html => onRoll(this.rollData) } }
|
2021-04-06 23:39:27 +02:00
|
|
|
};
|
2022-12-06 01:30:12 +01:00
|
|
|
let dialogOptions = { classes: ["rdd-roll-dialog"], width: 400, height: 'fit-content', 'z-index': 99999 }
|
2020-12-06 20:11:30 +01:00
|
|
|
super(dialogConf, dialogOptions)
|
2021-04-06 23:39:27 +02:00
|
|
|
|
2020-12-06 20:11:30 +01:00
|
|
|
this.rollData = rollData;
|
|
|
|
this.actor = actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html = html;
|
|
|
|
this.bringToTop();
|
2021-04-06 23:39:27 +02:00
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find(".force-alcool").change((event) => {
|
|
|
|
this.rollData.forceAlcool = Misc.toInt(event.currentTarget.value);
|
|
|
|
this.updateRollResult();
|
2020-12-06 20:11:30 +01:00
|
|
|
});
|
2021-04-06 23:39:27 +02:00
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find(".force-alcool").val(Misc.toInt(this.rollData.forceAlcool));
|
|
|
|
this.updateRollResult();
|
2020-12-06 20:11:30 +01:00
|
|
|
}
|
2022-12-09 02:00:31 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-04-21 19:40:48 +02:00
|
|
|
async updateRollResult() {
|
2022-12-09 02:00:31 +01:00
|
|
|
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();
|
2021-04-21 19:40:48 +02:00
|
|
|
}
|
2020-12-06 20:11:30 +01:00
|
|
|
|
|
|
|
}
|