fvtt-les-heritiers/modules/heritiers-roll-dialog.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-12-26 00:33:13 +01:00
import { HeritiersUtility } from "./heritiers-utility.js";
export class HeritiersRollDialog extends Dialog {
/* -------------------------------------------- */
2023-01-18 16:16:18 +01:00
static async create(actor, rollData) {
2022-12-26 00:33:13 +01:00
let options = { classes: ["HeritiersDialog"], width: 320, height: 'fit-content', 'z-index': 99999 };
let html = await renderTemplate('systems/fvtt-les-heritiers/templates/roll-dialog-generic.html', rollData);
2023-01-18 16:16:18 +01:00
return new HeritiersRollDialog(actor, rollData, html, options);
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
constructor(actor, rollData, html, options, close = undefined) {
let conf = {
title: "Test de Capacité",
content: html,
2023-01-20 15:19:04 +01:00
buttons:
{
2023-01-18 16:16:18 +01:00
rolld8: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d8",
callback: () => { this.roll("d8") }
},
2022-12-26 00:33:13 +01:00
rolld10: {
2023-01-18 16:16:18 +01:00
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d10",
callback: () => { this.roll("d10") }
},
rolld12: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d12",
callback: () => { this.roll("d12") }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
}
},
2022-12-26 00:33:13 +01:00
close: close
}
2023-01-20 15:19:04 +01:00
// Overwrite in case of carac only -> 1d10
if (rollData.mode == "carac") {
conf.buttons = {
rolld8: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d8",
callback: () => { this.roll("d8") }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
}
}
}
2022-12-26 00:33:13 +01:00
super(conf, options);
this.actor = actor
this.rollData = rollData
}
/* -------------------------------------------- */
2023-01-18 16:16:18 +01:00
roll(dice) {
2022-12-26 00:33:13 +01:00
this.rollData.mainDice = dice
2023-01-18 16:16:18 +01:00
HeritiersUtility.rollHeritiers(this.rollData)
2022-12-26 00:33:13 +01:00
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
var dialog = this;
function onLoad() {
}
$(function () { onLoad(); });
2023-01-18 16:16:18 +01:00
html.find('#sdValue').change(async (event) => {
this.rollData.sdValue = Number(event.currentTarget.value)
2022-12-26 00:33:13 +01:00
})
2023-01-18 16:16:18 +01:00
html.find('#caracKey').change(async (event) => {
this.rollData.caracKey = String(event.currentTarget.value)
2022-12-26 00:33:13 +01:00
})
html.find('#bonus-malus-context').change((event) => {
2023-01-18 16:16:18 +01:00
this.rollData.bonusMalusContext = Number(event.currentTarget.value)
2022-12-26 00:33:13 +01:00
})
2023-01-18 21:08:32 +01:00
html.find('#useTricherie').change((event) => {
this.rollData.useTricherie = event.currentTarget.checked
})
2023-03-08 16:58:11 +01:00
html.find('#useSpecialite').change((event) => {
this.rollData.useSpecialite = event.currentTarget.checked
})
2023-01-18 21:08:32 +01:00
html.find('#useHeritage').change((event) => {
this.rollData.useHeritage = event.currentTarget.checked
2023-01-20 15:19:04 +01:00
})
2022-12-26 00:33:13 +01:00
}
}