2021-05-11 00:52:25 +02:00
|
|
|
import { ChatUtility } from "./chat-utility.js";
|
|
|
|
import { HtmlUtility } from "./html-utility.js";
|
2023-01-18 01:37:22 +01:00
|
|
|
import { RdDItemSigneDraconique } from "./item/signedraconique.js";
|
2021-10-08 23:26:10 +02:00
|
|
|
import { TMRUtility } from "./tmr-utility.js";
|
2021-05-11 00:52:25 +02:00
|
|
|
|
2021-05-11 21:21:33 +02:00
|
|
|
export class DialogCreateSigneDraconique extends Dialog {
|
2021-05-11 00:52:25 +02:00
|
|
|
|
|
|
|
static async createSigneForActors() {
|
2021-05-18 19:51:12 +02:00
|
|
|
const signe = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true});
|
2021-05-11 00:52:25 +02:00
|
|
|
let dialogData = {
|
2021-05-11 21:21:33 +02:00
|
|
|
signe: signe,
|
2022-09-24 00:31:51 +02:00
|
|
|
tmrs: TMRUtility.buildSelectionTypesTMR(signe.system.typesTMR),
|
2023-11-04 18:26:40 +01:00
|
|
|
actors: game.actors.filter(actor => actor.isPersonnage() && actor.isHautRevant())
|
2022-09-24 00:31:51 +02:00
|
|
|
.map(actor => ({
|
|
|
|
id: actor.id,
|
|
|
|
name: actor.name,
|
2023-11-04 18:26:40 +01:00
|
|
|
selected: false
|
2022-09-24 00:31:51 +02:00
|
|
|
}))
|
2021-05-11 00:52:25 +02:00
|
|
|
};
|
|
|
|
|
2021-05-11 21:21:33 +02:00
|
|
|
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-create-signedraconique.html", dialogData);
|
|
|
|
new DialogCreateSigneDraconique(dialogData, html)
|
2021-05-11 00:52:25 +02:00
|
|
|
.render(true);
|
|
|
|
}
|
|
|
|
|
2022-09-24 00:31:51 +02:00
|
|
|
constructor(dialogData, html) {
|
2021-05-11 00:52:25 +02:00
|
|
|
let options = { classes: ["DialogCreateSigneDraconiqueActorsActors"], width: 500, height: 650, 'z-index': 99999 };
|
|
|
|
let conf = {
|
2021-05-11 21:21:33 +02:00
|
|
|
title: "Créer un signe",
|
2021-05-11 00:52:25 +02:00
|
|
|
content: html,
|
2021-05-11 21:21:33 +02:00
|
|
|
buttons: {
|
|
|
|
"Ajouter aux haut-rêvants": { label: "Ajouter aux haut-rêvants", callback: it => { this._onCreerSigneActeurs(); } }
|
|
|
|
}
|
2021-05-11 00:52:25 +02:00
|
|
|
};
|
|
|
|
super(conf, options);
|
|
|
|
this.dialogData = dialogData;
|
|
|
|
}
|
2022-12-09 02:00:31 +01:00
|
|
|
|
2021-05-11 21:21:33 +02:00
|
|
|
async _onCreerSigneActeurs() {
|
2022-12-09 02:00:31 +01:00
|
|
|
await this.html.find("[name='signe.system.ephemere']").change();
|
|
|
|
await this.html.find(".signe-xp-sort").change();
|
2021-05-11 21:21:33 +02:00
|
|
|
this.validerSigne();
|
2022-09-24 00:31:51 +02:00
|
|
|
this.dialogData.actors.filter(it => it.selected)
|
2022-12-09 02:00:31 +01:00
|
|
|
.map(it => game.actors.get(it.id))
|
|
|
|
.forEach(actor => this._createSigneForActor(actor, this.dialogData.signe));
|
2021-05-11 00:52:25 +02:00
|
|
|
}
|
2022-12-09 02:00:31 +01:00
|
|
|
|
2021-05-11 00:52:25 +02:00
|
|
|
async _createSigneForActor(actor, signe) {
|
|
|
|
actor.createEmbeddedDocuments("Item", [signe]);
|
|
|
|
ChatMessage.create({
|
2022-06-12 09:46:58 +02:00
|
|
|
whisper: ChatUtility.getWhisperRecipientsAndGMs(actor.name),
|
2021-05-11 00:52:25 +02:00
|
|
|
content: await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.html", {
|
|
|
|
signe: signe,
|
2022-06-12 09:46:58 +02:00
|
|
|
alias: actor.name
|
2021-05-11 00:52:25 +02:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-11 21:21:33 +02:00
|
|
|
validerSigne() {
|
2022-12-09 02:00:31 +01:00
|
|
|
this.dialogData.signe.name = this.html.find("[name='signe.name']").val();
|
|
|
|
this.dialogData.signe.system.valeur.norm = this.html.find("[name='signe.system.valeur.norm']").val();
|
|
|
|
this.dialogData.signe.system.valeur.sign = this.html.find("[name='signe.system.valeur.sign']").val();
|
|
|
|
this.dialogData.signe.system.valeur.part = this.html.find("[name='signe.system.valeur.part']").val();
|
|
|
|
this.dialogData.signe.system.difficulte = this.html.find("[name='signe.system.difficulte']").val();
|
|
|
|
this.dialogData.signe.system.ephemere = this.html.find("[name='signe.system.ephemere']").prop("checked");
|
|
|
|
this.dialogData.signe.system.duree = this.html.find("[name='signe.system.duree']").val();
|
2022-09-24 00:31:51 +02:00
|
|
|
this.dialogData.signe.system.typesTMR = TMRUtility.buildListTypesTMRSelection(this.dialogData.tmrs);
|
2021-05-11 21:21:33 +02:00
|
|
|
}
|
2022-12-09 02:00:31 +01:00
|
|
|
|
2021-05-11 00:52:25 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html = html;
|
2022-09-07 09:01:23 +02:00
|
|
|
this.setEphemere(this.dialogData.signe.system.ephemere);
|
2021-05-11 21:21:33 +02:00
|
|
|
html.find(".signe-aleatoire").click(event => this.setSigneAleatoire());
|
2022-09-07 09:01:23 +02:00
|
|
|
html.find("[name='signe.system.ephemere']").change((event) => this.setEphemere(event.currentTarget.checked));
|
2021-05-11 21:21:33 +02:00
|
|
|
html.find(".signe-xp-sort").change((event) => this.onValeurXpSort(event));
|
2022-09-24 00:31:51 +02:00
|
|
|
html.find("input.select-actor").change((event) => this.onSelectActor(event));
|
|
|
|
html.find("input.select-tmr").change((event) => this.onSelectTmr(event));
|
2021-05-11 00:52:25 +02:00
|
|
|
}
|
2021-06-04 19:35:27 +02:00
|
|
|
|
2021-05-11 21:21:33 +02:00
|
|
|
async setSigneAleatoire() {
|
2021-05-18 19:51:12 +02:00
|
|
|
const newSigne = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true});
|
2021-05-11 21:21:33 +02:00
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("[name='signe.name']").val(newSigne.name);
|
|
|
|
this.html.find("[name='signe.system.valeur.norm']").val(newSigne.system.valeur.norm);
|
|
|
|
this.html.find("[name='signe.system.valeur.sign']").val(newSigne.system.valeur.sign);
|
|
|
|
this.html.find("[name='signe.system.valeur.part']").val(newSigne.system.valeur.part);
|
|
|
|
this.html.find("[name='signe.system.difficulte']").val(newSigne.system.difficulte);
|
|
|
|
this.html.find("[name='signe.system.duree']").val(newSigne.system.duree);
|
|
|
|
this.html.find("[name='signe.system.ephemere']").prop("checked", newSigne.system.ephemere);
|
2022-09-24 00:31:51 +02:00
|
|
|
this.dialogData.tmrs = TMRUtility.buildSelectionTypesTMR(newSigne.system.typesTMR);
|
|
|
|
this.dialogData.tmrs.forEach(t => {
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find(`[data-tmr-name='${t.name}']`).prop( "checked", t.selected);
|
2022-09-24 00:31:51 +02:00
|
|
|
})
|
2022-09-07 09:01:23 +02:00
|
|
|
this.setEphemere(newSigne.system.ephemere);
|
2021-05-11 00:52:25 +02:00
|
|
|
}
|
|
|
|
|
2021-05-11 21:21:33 +02:00
|
|
|
async setEphemere(ephemere) {
|
2022-09-07 09:01:23 +02:00
|
|
|
this.dialogData.signe.system.ephemere = ephemere;
|
2023-01-10 22:11:16 +01:00
|
|
|
HtmlUtility.showControlWhen(this.html.find(".signe-system-duree"), ephemere);
|
2021-05-11 00:52:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async onSelectActor(event) {
|
2022-12-09 02:00:31 +01:00
|
|
|
const actorId = this.html.find(event.currentTarget)?.data("actor-id");
|
2022-09-24 00:31:51 +02:00
|
|
|
const actor = this.dialogData.actors.find(it => it.id == actorId);
|
|
|
|
if (actor) {
|
|
|
|
actor.selected = event.currentTarget.checked;
|
|
|
|
}
|
2021-05-11 00:52:25 +02:00
|
|
|
}
|
|
|
|
|
2022-09-24 00:31:51 +02:00
|
|
|
onSelectTmr(event) {
|
2022-12-09 02:00:31 +01:00
|
|
|
const tmrName = this.html.find(event.currentTarget)?.data("tmr-name");
|
2023-06-24 00:34:30 +02:00
|
|
|
const onTmr = this.dialogData.tmrs.find(it => it.name == tmrName);
|
2022-09-24 00:31:51 +02:00
|
|
|
if (onTmr){
|
|
|
|
onTmr.selected = event.currentTarget.checked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-11 00:52:25 +02:00
|
|
|
onValeurXpSort(event) {
|
|
|
|
const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0;
|
|
|
|
const xp = Number(event.currentTarget.value);
|
2022-09-07 09:01:23 +02:00
|
|
|
const oldValeur = this.dialogData.signe.system.valeur;
|
|
|
|
this.dialogData.signe.system.valeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur);
|
2021-05-11 00:52:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|