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

147 lines
4.3 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
2023-04-11 13:26:51 +02:00
let options = { classes: ["HeritiersDialog"], width: 420, height: 'fit-content', 'z-index': 99999 };
2022-12-26 00:33:13 +01:00
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) {
2023-04-08 18:49:54 +02:00
let buttons = {
rolld8: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d8",
callback: () => { this.roll("d8") }
}
}
let enableD10 = false
let enableD12 = false
2024-04-11 12:36:50 +02:00
if (rollData.mode == "pouvoir" || rollData.competence?.system.niveau > 0) {
enableD10 = true
}
2024-04-11 12:36:50 +02:00
if (rollData.mode == "pouvoir" || rollData.competence?.system.niveau > 1) {
enableD12 = true
}
if (enableD10) {
buttons.rolld10 = {
2023-04-08 18:49:54 +02:00
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d10",
callback: () => { this.roll("d10") }
}
}
if (enableD12) {
buttons.rolld12 = {
2023-04-08 18:49:54 +02:00
icon: '<i class="fas fa-check"></i>',
label: "Lancer 1d12",
callback: () => { this.roll("d12") }
}
}
2023-04-08 18:49:54 +02:00
if (rollData.tricherie) {
buttons["rollTricherie"] = {
icon: '<i class="fas fa-check"></i>',
label: "Lancer avec 1 Point de Tricherie",
callback: () => { this.roll("tricherie") }
}
}
if (rollData.heritage) {
buttons["rollHeritage"] = {
icon: '<i class="fas fa-check"></i>',
label: "Lancer avec 1 Point d'Héritage",
callback: () => { this.roll("heritage") }
}
}
buttons["Cancel"] = {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
}
2022-12-26 00:33:13 +01:00
let conf = {
title: "Test de Capacité",
content: html,
2023-04-08 18:49:54 +02:00
buttons: buttons,
2022-12-26 00:33:13 +01:00
close: close
}
// Overwrite in case of carac only -> 1d8
2023-01-20 15:19:04 +01:00
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) {
2023-04-08 18:49:54 +02:00
if (dice == "heritage") {
this.rollData.useHeritage = true
}
else {
if (dice == "tricherie") {
this.rollData.useTricherie = true
} else {
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) => {
2024-07-13 12:12:38 +02:00
//console.log("caracKey", event.currentTarget.value)
2023-01-18 16:16:18 +01:00
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-04-10 14:11:47 +02:00
html.find('#bonus-attaque-plusieurs').change((event) => {
this.rollData.bonusAttaquePlusieurs = Number(event.currentTarget.value)
})
2023-03-08 16:58:11 +01:00
html.find('#useSpecialite').change((event) => {
this.rollData.useSpecialite = event.currentTarget.checked
})
2024-03-23 11:37:15 +01:00
html.find('#pouvoirPointsUsage').change((event) => {
this.rollData.pouvoirPointsUsage = Number(event.currentTarget.value)
})
2023-04-10 14:11:47 +02:00
html.find('#attaqueDos').change((event) => {
this.rollData.attaqueDos = event.currentTarget.checked
})
2023-04-11 13:26:51 +02:00
html.find('#bonus-attaque-seconde-arme').change((event) => {
this.rollData.secondeArme = String(event.currentTarget.value)
})
html.find('#attaque-cible').change((event) => {
this.rollData.attaqueCible = String(event.currentTarget.value)
})
2023-04-10 14:11:47 +02:00
2022-12-26 00:33:13 +01:00
}
}