fvtt-malefices/modules/malefices-roll-dialog.js

92 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2023-02-01 14:28:08 +01:00
import { MaleficesUtility } from "./malefices-utility.js";
export class MaleficesRollDialog extends Dialog {
/* -------------------------------------------- */
static async create(actor, rollData) {
let options = { classes: ["MaleficesDialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
let html
if (rollData.attr && rollData.attr.iscard) {
html = await renderTemplate('systems/fvtt-malefices/templates/dialogs/confrontation-dialog.hbs', rollData);
} else {
html = await renderTemplate('systems/fvtt-malefices/templates/dialogs/roll-dialog-generic.hbs', rollData);
}
2023-02-01 14:28:08 +01:00
return new MaleficesRollDialog(actor, rollData, html, options);
}
/* -------------------------------------------- */
constructor(actor, rollData, html, options, close = undefined) {
let isCard = rollData.attr && rollData.attr.iscard
2023-02-01 14:28:08 +01:00
let conf = {
title: (isCard) ? "Jet" : "Tirage",
2023-02-01 14:28:08 +01:00
content: html,
buttons: {
roll: {
icon: '<i class="fas fa-check"></i>',
label: (isCard) ? "Tirer une carte" : "Lancer le dé",
2023-02-01 14:28:08 +01:00
callback: () => { this.roll() }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
2023-02-01 14:28:08 +01:00
callback: () => { this.close() }
}
},
close: close
}
super(conf, options);
this.actor = actor;
this.rollData = rollData;
}
/* -------------------------------------------- */
roll() {
let isCard = this.rollData.attr && this.rollData.attr.iscard
if (isCard) {
MaleficesUtility.tirageConfrontationMalefices(this.rollData)
} else {
MaleficesUtility.rollMalefices(this.rollData)
}
2023-02-01 14:28:08 +01:00
}
/* -------------------------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-malefices/templates/dialogs/roll-dialog-generic.hbs", this.rollData)
this.data.content = content
this.render(true)
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
var dialog = this;
function onLoad() {
}
$(function () { onLoad(); });
2023-02-01 19:48:35 +01:00
html.find('#bonusMalusSituation').change((event) => {
this.rollData.bonusMalusSituation = Number(event.currentTarget.value)
2023-02-01 14:28:08 +01:00
})
2023-02-01 19:48:35 +01:00
html.find('#bonusMalusPerso').change((event) => {
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
2023-02-01 14:28:08 +01:00
})
2023-02-01 19:48:35 +01:00
html.find('#bonusMalusDef').change((event) => {
this.rollData.bonusMalusDef = Number(event.currentTarget.value)
})
2023-02-02 23:59:41 +01:00
html.find('#bonusMalusPortee').change((event) => {
this.rollData.bonusMalusPortee = Number(event.currentTarget.value)
})
html.find('#confrontationDegre').change((event) => {
this.rollData.confrontationDegre = Number(event.currentTarget.value)
})
html.find('#confrontationModif').change((event) => {
this.rollData.confrontationModif = Number(event.currentTarget.value)
})
2023-02-01 14:28:08 +01:00
}
}