2021-10-08 23:28:55 +02:00
|
|
|
import { Misc } from "./misc.js";
|
|
|
|
|
|
|
|
export class DialogStress extends Dialog {
|
|
|
|
|
|
|
|
static async distribuerStress() {
|
|
|
|
let dialogData = {
|
|
|
|
motif: "Motif",
|
|
|
|
stress: 10,
|
|
|
|
immediat: false,
|
|
|
|
actors: game.actors.filter(actor => actor.hasPlayerOwner && actor.isPersonnage())
|
|
|
|
.map(actor => {
|
2022-06-12 09:46:58 +02:00
|
|
|
let actorData = duplicate(actor);
|
2021-10-08 23:28:55 +02:00
|
|
|
actorData.selected = actor.hasPlayerOwner;
|
|
|
|
return actorData;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-stress.html", dialogData);
|
|
|
|
new DialogStress(dialogData, html)
|
|
|
|
.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(dialogData, html) {
|
|
|
|
let options = { classes: ["DialogStress"], width: 400, height: 320, 'z-index': 99999 };
|
|
|
|
let conf = {
|
|
|
|
title: "Donner du stress",
|
|
|
|
content: html,
|
|
|
|
buttons: {
|
|
|
|
"Stress": { label: "Stress !", callback: it => { this._onStress(); } }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
super(conf, options);
|
|
|
|
this.dialogData = dialogData;
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onStress() {
|
|
|
|
this.validerStress();
|
|
|
|
const compteur = this.dialogData.immediat ? 'experience' : 'stress';
|
|
|
|
const stress = this.dialogData.stress;
|
|
|
|
const motif = this.dialogData.motif;
|
|
|
|
|
|
|
|
this.dialogData.actors.filter(it => it.selected)
|
|
|
|
.map(it => game.actors.get(it._id))
|
|
|
|
.forEach(actor => actor.distribuerStress(compteur, stress, motif));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
validerStress() {
|
2021-11-26 00:46:26 +01:00
|
|
|
this.dialogData.motif = $("form.rdddialogstress input[name='motif']").val();
|
|
|
|
this.dialogData.stress = $("form.rdddialogstress input[name='stress']").val();
|
|
|
|
this.dialogData.immediat = $("form.rdddialogstress input[name='immediat']").prop("checked");;
|
2021-10-08 23:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
html.find(".select-actor").change((event) => this.onSelectActor(event));
|
|
|
|
}
|
|
|
|
|
|
|
|
async onSelectActor(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const options = event.currentTarget.options;
|
|
|
|
for (var i = 0; i < options.length; i++) { // looping over the options
|
|
|
|
const actorId = options[i].attributes["data-actor-id"].value;
|
|
|
|
const actor = this.dialogData.actors.find(it => it._id == actorId);
|
|
|
|
if (actor) {
|
|
|
|
actor.selected = options[i].selected;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|