Fix multi-dialogs

Arrêter d'utiliser le jQuery $(selector) qui cause des effets de bord si
plusieurs élements de la page (ie: foundry) correspondent
au selector.

Stocker le html dans les Sheet/Dialogs lors de l'appel
activateListeners  afin de pouvoir s'y référer ensuite.

Utiliser this.html.find pour chercher dans le html de la fenêtre
courante.

Eliminer les référence par id html car l'id est unique (donc ne marche
pas en multi-fenêtres)
This commit is contained in:
Vincent Vandemeulebrouck
2022-12-09 02:00:31 +01:00
parent aefc7a434b
commit 63770790b9
42 changed files with 706 additions and 759 deletions

View File

@ -1,4 +1,5 @@
import { ENTITE_BLURETTE, ENTITE_INCARNE} from "./constants.js";
import { ENTITE_BLURETTE, ENTITE_INCARNE } from "./constants.js";
import { RdDUtility } from "./rdd-utility.js";
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
@ -6,30 +7,35 @@ import { ENTITE_BLURETTE, ENTITE_INCARNE} from "./constants.js";
*/
export class RdDEncaisser extends Dialog {
static async encaisser(actor) {
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.html',
{ ajustementsEncaissement: RdDUtility.getAjustementsEncaissement() }
);
new RdDEncaisser(html, actor).render(true);
}
/* -------------------------------------------- */
constructor(html, actor) {
// Common conf
let buttons = {};
if (!actor.isEntite()){
buttons = {
let dialogConf = {
title: "Jet d'Encaissement",
content: html,
}
if (!actor.isEntite()) {
dialogConf.default = "mortel";
dialogConf.buttons = {
"mortel": { label: "Mortel", callback: html => this.performEncaisser("mortel") },
"non-mortel": { label: "Non-mortel", callback: html => this.performEncaisser("non-mortel") },
"sonne": { label: "Sonné", callback: html => this.actor.setSonne() },
};
}
else if (actor.isEntite([ENTITE_BLURETTE, ENTITE_INCARNE])){
buttons = {
"cauchemar": { label: "cauchemar", callback: html => this.performEncaisser("cauchemar") }
else if (actor.isEntite([ENTITE_BLURETTE, ENTITE_INCARNE])) {
dialogConf.default = "cauchemar"
dialogConf.buttons = {
"cauchemar": { label: "Cauchemar", callback: html => this.performEncaisser("cauchemar") }
}
}
let dialogConf = {
title: "Jet d'Encaissement",
content: html,
buttons: buttons,
default: "mortel"
}
let dialogOptions = {
classes: ["rdd-roll-dialog"],
width: 320,
@ -44,7 +50,18 @@ export class RdDEncaisser extends Dialog {
this.encaisserSpecial = "aucun";
}
activateListeners(html) {
super.activateListeners(html);
this.html = html;
this.html.find('[name="modificateurDegats"]').val("0");
this.html.find('[name="modificateurDegats"]').change((event) => {
this.modifier = event.currentTarget.value; // Update the selected bonus/malus
});
this.html.find('[name="encaisserSpecial"]').change((event) => {
this.encaisserSpecial = event.currentTarget.value; // Update the selected bonus/malus
});
}
/* -------------------------------------------- */
performEncaisser(mortalite) {
@ -58,22 +75,4 @@ export class RdDEncaisser extends Dialog {
}
});
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
// Setup everything onload
$(function () {
$("#modificateurDegats").val("0");
});
html.find('#modificateurDegats').change((event) => {
this.modifier = event.currentTarget.value; // Update the selected bonus/malus
});
html.find('#encaisserSpecial').change((event) => {
this.encaisserSpecial = event.currentTarget.value; // Update the selected bonus/malus
});
}
}