diff --git a/module/dialog-stress.js b/module/dialog-stress.js index 1decf82e..a1dd5d97 100644 --- a/module/dialog-stress.js +++ b/module/dialog-stress.js @@ -1,18 +1,19 @@ -import { Misc } from "./misc.js"; +import { RdDSheetUtility } from "./rdd-sheet-utility.js"; export class DialogStress extends Dialog { static async distribuerStress() { - let dialogData = { + const dialogData = { motif: "Motif", stress: 10, immediat: false, actors: game.actors.filter(actor => actor.hasPlayerOwner && actor.isPersonnage()) - .map(actor => { - let actorData = duplicate(actor); - actorData.selected = actor.hasPlayerOwner; - return actorData; - }) + .map(actor => ({ + id: actor.id, + name: actor.name, + selected: true + }) + ) }; const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-stress.html", dialogData); @@ -21,52 +22,44 @@ export class DialogStress extends Dialog { } constructor(dialogData, html) { - let options = { classes: ["DialogStress"], width: 400, height: 320, 'z-index': 99999 }; - let conf = { + const options = { classes: ["DialogStress"], + width: 400, + height: 205+dialogData.actors.length*25, + 'z-index': 99999 + }; + const conf = { title: "Donner du stress", content: html, buttons: { - "Stress": { label: "Stress !", callback: it => { this._onStress(); } } - } + stress: { label: "Stress !", callback: it => { this.onStress(); } } + }, + default: "stress" }; 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; + 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'; this.dialogData.actors.filter(it => it.selected) - .map(it => game.actors.get(it._id)) + .map(it => game.actors.get(it.id)) .forEach(actor => actor.distribuerStress(compteur, stress, motif)); } - - validerStress() { - 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");; - } - /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html); - html.find(".select-actor").change((event) => this.onSelectActor(event)); + html.find("input.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; - } - }; + const actorId = $(event.currentTarget)?.data("actor-id"); + const actor = this.dialogData.actors.find(it => it.id == actorId); + if (actor) { + actor.selected = event.currentTarget.checked; + } } - } \ No newline at end of file diff --git a/styles/simple.css b/styles/simple.css index 7b121391..79343e64 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -840,6 +840,15 @@ ul, li { margin-left: 3rem; } +.grid-select-actor { + display: grid; + grid-column: span 2 / span 2; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 0.1rem; + margin: 0.1rem; + padding: 0; +} + .sheet-competence-img { width: 24px; height: 24px; diff --git a/templates/dialog-stress.html b/templates/dialog-stress.html index 12a6608f..b920fa18 100644 --- a/templates/dialog-stress.html +++ b/templates/dialog-stress.html @@ -12,13 +12,17 @@ -