TMR et acteurs à cocher pour les signe draconiques

Au lieu d'une liste à sélection multiple, choisir les types de TMR
avec des cases à cocher.

Lors de l'ajout de signes éphémères, sélectionner les personnages
avec des cases à cocher.
This commit is contained in:
Vincent Vandemeulebrouck
2022-09-24 00:31:51 +02:00
parent fe80881405
commit fc5674a7d8
8 changed files with 91 additions and 52 deletions

View File

@ -1,7 +1,6 @@
import { ChatUtility } from "./chat-utility.js";
import { HtmlUtility } from "./html-utility.js";
import { RdDItemSigneDraconique } from "./item-signedraconique.js";
import { Misc } from "./misc.js";
import { TMRUtility } from "./tmr-utility.js";
export class DialogCreateSigneDraconique extends Dialog {
@ -10,12 +9,13 @@ export class DialogCreateSigneDraconique extends Dialog {
const signe = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true});
let dialogData = {
signe: signe,
tmrs: TMRUtility.listSelectedTMR(signe.system.typesTMR ?? []),
actors: game.actors.filter(actor => actor.isHautRevant()).map(actor => {
let actorData = duplicate(actor);
actorData.selected = actor.hasPlayerOwner;
return actorData;
})
tmrs: TMRUtility.buildSelectionTypesTMR(signe.system.typesTMR),
actors: game.actors.filter(actor => actor.isPersonnage() && actor.isHautRevant())
.map(actor => ({
id: actor.id,
name: actor.name,
selected: true
}))
};
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-create-signedraconique.html", dialogData);
@ -23,12 +23,11 @@ export class DialogCreateSigneDraconique extends Dialog {
.render(true);
}
constructor(dialogData, html, callback) {
constructor(dialogData, html) {
let options = { classes: ["DialogCreateSigneDraconiqueActorsActors"], width: 500, height: 650, 'z-index': 99999 };
let conf = {
title: "Créer un signe",
content: html,
default: "Ajouter aux haut-rêvants",
buttons: {
"Ajouter aux haut-rêvants": { label: "Ajouter aux haut-rêvants", callback: it => { this._onCreerSigneActeurs(); } }
}
@ -41,7 +40,8 @@ export class DialogCreateSigneDraconique extends Dialog {
await $("[name='signe.system.ephemere']").change();
await $(".signe-xp-sort").change();
this.validerSigne();
this.dialogData.actors.filter(it => it.selected).map(it => game.actors.get(it._id))
this.dialogData.actors.filter(it => it.selected)
.map(it => game.actors.get(it.id))
.forEach(actor => this._createSigneForActor(actor, this.dialogData.signe));
}
@ -64,7 +64,7 @@ export class DialogCreateSigneDraconique extends Dialog {
this.dialogData.signe.system.difficulte = $("[name='signe.system.difficulte']").val();
this.dialogData.signe.system.ephemere = $("[name='signe.system.ephemere']").prop("checked");
this.dialogData.signe.system.duree = $("[name='signe.system.duree']").val();
this.dialogData.signe.system.typesTMR = $(".select-tmr").val();
this.dialogData.signe.system.typesTMR = TMRUtility.buildListTypesTMRSelection(this.dialogData.tmrs);
}
/* -------------------------------------------- */
@ -73,8 +73,9 @@ export class DialogCreateSigneDraconique extends Dialog {
this.setEphemere(this.dialogData.signe.system.ephemere);
html.find(".signe-aleatoire").click(event => this.setSigneAleatoire());
html.find("[name='signe.system.ephemere']").change((event) => this.setEphemere(event.currentTarget.checked));
html.find(".select-actor").change((event) => this.onSelectActor(event));
html.find(".signe-xp-sort").change((event) => this.onValeurXpSort(event));
html.find("input.select-actor").change((event) => this.onSelectActor(event));
html.find("input.select-tmr").change((event) => this.onSelectTmr(event));
}
async setSigneAleatoire() {
@ -87,7 +88,10 @@ export class DialogCreateSigneDraconique extends Dialog {
$("[name='signe.system.difficulte']").val(newSigne.system.difficulte);
$("[name='signe.system.duree']").val(newSigne.system.duree);
$("[name='signe.system.ephemere']").prop("checked", newSigne.system.ephemere);
$(".select-tmr").val(newSigne.system.typesTMR);
this.dialogData.tmrs = TMRUtility.buildSelectionTypesTMR(newSigne.system.typesTMR);
this.dialogData.tmrs.forEach(t => {
$(`[data-tmr-name='${t.name}']`).prop( "checked", t.selected);
})
this.setEphemere(newSigne.system.ephemere);
}
@ -97,17 +101,22 @@ export class DialogCreateSigneDraconique extends Dialog {
}
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;
}
}
onSelectTmr(event) {
const tmrName = $(event.currentTarget)?.data("tmr-name");
const onTmr = this.tmrs.find(it => it.name == tmrName);
if (onTmr){
onTmr.selected = event.currentTarget.checked;
}
}
onValeurXpSort(event) {
const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0;
const xp = Number(event.currentTarget.value);