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

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-12-06 20:11:30 +01:00
import { RdDResolutionTable } from "./rdd-resolution-table.js";
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) {
2020-12-06 20:11:30 +01:00
// Common conf
let dialogConf = {
title: "Test d'éthylisme",
content: html,
default: "rollButton",
buttons: { "rollButton": { label: "Test d'éthylisme", callback: html => this.onButton(html) } }
};
2021-04-21 19:40:48 +02:00
let dialogOptions = { classes: ["rdddialog"], width: 400, height: 270, 'z-index': 99999 }
2020-12-06 20:11:30 +01:00
super(dialogConf, dialogOptions)
2020-12-18 23:35:53 +01:00
//console.log("ETH", rollData);
this.onRoll = onRoll;
2020-12-06 20:11:30 +01:00
this.rollData = rollData;
this.actor = actor;
}
async onButton(html) {
this.onRoll(this.rollData);
}
2020-12-06 20:11:30 +01:00
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
2020-12-06 20:11:30 +01:00
this.bringToTop(); // Ensure top level
// Get the rollData stuff
var rollData = this.rollData;
2021-04-21 19:40:48 +02:00
var dialog = this;
2020-12-06 20:11:30 +01:00
// Setup everything onload
$(function () {
$("#forceAlcool").val(Misc.toInt(rollData.forceAlcool));
2021-04-21 19:40:48 +02:00
dialog.updateRollResult();
2020-12-06 20:11:30 +01:00
});
2020-12-06 20:11:30 +01:00
// Update !
html.find('#forceAlcool').change((event) => {
rollData.forceAlcool = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus
2021-04-21 19:40:48 +02:00
dialog.updateRollResult();
2020-12-06 20:11:30 +01:00
});
}
2021-04-21 19:40:48 +02:00
async updateRollResult() {
this.rollData.finalLevel = Number(this.rollData.etat) + Number(this.rollData.forceAlcool) + this.rollData.diffNbDoses;
// Mise à jour valeurs
$("#roll-param").text(this.rollData.vieValue + " / " + Misc.toSignedString(this.rollData.finalLevel));
$(".table-resolution").remove();
}
2020-12-06 20:11:30 +01:00
}