fvtt-te-deum/modules/dialogs/tedeum-roll-dialog.js

87 lines
2.8 KiB
JavaScript
Raw Normal View History

2023-12-11 21:41:51 +01:00
import { TeDeumUtility } from "../common/tedeum-utility.js";
2023-12-11 20:11:10 +01:00
2023-12-11 21:41:51 +01:00
export class TeDeumRollDialog extends Dialog {
2023-12-11 20:11:10 +01:00
/* -------------------------------------------- */
static async create(actor, rollData) {
2023-12-11 21:41:51 +01:00
let options = { classes: ["tedeum-roll-dialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
let html = await renderTemplate('systems/fvtt-te-deum/templates/dialogs/roll-dialog-generic.hbs', rollData);
2023-12-11 21:41:51 +01:00
return new TeDeumRollDialog(actor, rollData, html, options);
2023-12-11 20:11:10 +01:00
}
/* -------------------------------------------- */
constructor(actor, rollData, html, options, close = undefined) {
let conf = {
2023-12-11 22:24:19 +01:00
title: "Lancer !",
2023-12-11 20:11:10 +01:00
content: html,
buttons: {
roll: {
icon: '<i class="fas fa-check"></i>',
2023-12-11 22:24:19 +01:00
label: "Lancer",
2023-12-11 20:11:10 +01:00
callback: () => { this.roll() }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
2023-12-11 22:24:19 +01:00
label: "Annuler",
2023-12-11 20:11:10 +01:00
callback: () => { this.close() }
}
},
close: close
}
super(conf, options);
this.actor = actor;
this.rollData = rollData;
}
/* -------------------------------------------- */
roll() {
TeDeumUtility.rollTeDeum(this.rollData)
2023-12-11 20:11:10 +01:00
}
/* -------------------------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-te-deum/templates/dialogs/roll-dialog-generic.hbs", this.rollData)
2023-12-11 20:11:10 +01:00
this.data.content = content
this.render(true)
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
2023-12-11 22:44:06 +01:00
let dialog = this;
2023-12-11 20:11:10 +01:00
function onLoad() {
}
$(function () { onLoad(); });
html.find('#bonusMalusPerso').change((event) => {
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
})
html.find('#roll-difficulty').change((event) => {
this.rollData.difficulty = String(event.currentTarget.value) || "pardefaut"
2023-12-11 20:11:10 +01:00
})
html.find('#roll-bonus-malus').change((event) => {
this.rollData.bonusMalus = event.currentTarget.value || "0"
})
html.find('#roll-enable-providence').change((event) => {
this.rollData.enableProvidence = event.currentTarget.checked
})
2024-09-13 22:14:21 +02:00
html.find('#roll-portee-tir').change((event) => {
this.rollData.porteeTir = event.currentTarget.value
this.rollData.difficulty = game.system.tedeum.config.ARME_PORTEES[this.rollData.porteeTir].difficulty
this.rollData.porteeLabel = game.system.tedeum.config.ARME_PORTEES[this.rollData.porteeTir].label
})
html.find('#roll-tir-viser').change((event) => {
this.rollData.isViser = event.currentTarget.checked
})
html.find('#roll-tir-mouvement').change((event) => {
this.rollData.isMouvement = event.currentTarget.checked
})
2023-12-11 20:11:10 +01:00
}
}