2021-10-08 23:28:55 +02:00
|
|
|
|
|
|
|
export class DialogStress extends Dialog {
|
|
|
|
|
|
|
|
static async distribuerStress() {
|
2022-09-23 20:23:35 +02:00
|
|
|
const dialogData = {
|
2021-10-08 23:28:55 +02:00
|
|
|
motif: "Motif",
|
|
|
|
stress: 10,
|
|
|
|
immediat: false,
|
|
|
|
actors: game.actors.filter(actor => actor.hasPlayerOwner && actor.isPersonnage())
|
2022-09-23 20:23:35 +02:00
|
|
|
.map(actor => ({
|
|
|
|
id: actor.id,
|
|
|
|
name: actor.name,
|
|
|
|
selected: true
|
|
|
|
})
|
|
|
|
)
|
2021-10-08 23:28:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-stress.html", dialogData);
|
|
|
|
new DialogStress(dialogData, html)
|
|
|
|
.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(dialogData, html) {
|
2022-09-23 20:23:35 +02:00
|
|
|
const options = { classes: ["DialogStress"],
|
|
|
|
width: 400,
|
2022-11-16 02:46:26 +01:00
|
|
|
height: 'fit-content',
|
2022-09-23 20:23:35 +02:00
|
|
|
'z-index': 99999
|
|
|
|
};
|
|
|
|
const conf = {
|
2021-10-08 23:28:55 +02:00
|
|
|
title: "Donner du stress",
|
|
|
|
content: html,
|
|
|
|
buttons: {
|
2022-09-23 20:23:35 +02:00
|
|
|
stress: { label: "Stress !", callback: it => { this.onStress(); } }
|
|
|
|
},
|
|
|
|
default: "stress"
|
2021-10-08 23:28:55 +02:00
|
|
|
};
|
|
|
|
super(conf, options);
|
|
|
|
this.dialogData = dialogData;
|
|
|
|
}
|
|
|
|
|
2022-09-23 20:23:35 +02:00
|
|
|
async onStress() {
|
|
|
|
const motif = $("form.rdddialogstress input[name='motif']").val();
|
|
|
|
const stress = Number($("form.rdddialogstress input[name='stress']").val());
|
|
|
|
const compteur = ($("form.rdddialogstress input[name='immediat']").prop("checked")) ? 'experience' : 'stress';
|
2021-10-08 23:28:55 +02:00
|
|
|
|
|
|
|
this.dialogData.actors.filter(it => it.selected)
|
2022-09-23 20:23:35 +02:00
|
|
|
.map(it => game.actors.get(it.id))
|
2021-10-08 23:28:55 +02:00
|
|
|
.forEach(actor => actor.distribuerStress(compteur, stress, motif));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2022-09-23 20:23:35 +02:00
|
|
|
html.find("input.select-actor").change((event) => this.onSelectActor(event));
|
2021-10-08 23:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async onSelectActor(event) {
|
2022-09-23 20:23:35 +02:00
|
|
|
const actorId = $(event.currentTarget)?.data("actor-id");
|
|
|
|
const actor = this.dialogData.actors.find(it => it.id == actorId);
|
|
|
|
if (actor) {
|
|
|
|
actor.selected = event.currentTarget.checked;
|
|
|
|
}
|
2021-10-08 23:28:55 +02:00
|
|
|
}
|
|
|
|
}
|