await ChatMessage.create

ChatMessage.create est async, il faut donc de préférence
l'appeler avec un await.

Des effets secondaires avaient lieu (ordre de messages, updates
ultérieurs parfois pas pris en compte)
This commit is contained in:
2026-05-02 00:42:45 +02:00
parent d15d0989a3
commit 7fb0ee1659
26 changed files with 184 additions and 191 deletions

View File

@@ -7,7 +7,7 @@ import { TMRUtility } from "./tmr-utility.js";
export class DialogCreateSigneDraconique extends Dialog {
static async createSigneForActors() {
const signe = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true});
const signe = await RdDItemSigneDraconique.randomSigneDraconique({ ephemere: true });
let dialogData = {
signe: signe,
tmrs: TMRUtility.buildSelectionTypesTMR(signe.system.typesTMR),
@@ -36,25 +36,25 @@ export class DialogCreateSigneDraconique extends Dialog {
super(conf, options);
this.dialogData = dialogData;
}
async _onCreerSigneActeurs() {
await this.html.find("[name='signe.system.ephemere']").change();
await this.html.find(".signe-xp-sort").change();
this.validerSigne();
this.dialogData.actors.filter(it => it.selected)
.map(it => game.actors.get(it.id))
.forEach(actor => this._createSigneForActor(actor, this.dialogData.signe));
await this.html.find("[name='signe.system.ephemere']").change()
await this.html.find(".signe-xp-sort").change()
this.validerSigne()
await Promise.all(this.dialogData.actors.filter(it => it.selected)
.map(it => game.actors.get(it.id))
.map(async actor => await this._createSigneForActor(actor, this.dialogData.signe)))
}
async _createSigneForActor(actor, signe) {
actor.createEmbeddedDocuments("Item", [signe]);
ChatMessage.create({
await actor.createEmbeddedDocuments("Item", [signe]);
await ChatMessage.createChatMessage.create({
whisper: ChatUtility.getOwners(actor),
content: await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.hbs", {
signe: signe,
alias: actor.getAlias()
})
});
})
}
validerSigne() {
@@ -67,7 +67,7 @@ export class DialogCreateSigneDraconique extends Dialog {
this.dialogData.signe.system.duree = this.html.find("[name='signe.system.duree']").val();
this.dialogData.signe.system.typesTMR = TMRUtility.buildListTypesTMRSelection(this.dialogData.tmrs);
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
@@ -81,7 +81,7 @@ export class DialogCreateSigneDraconique extends Dialog {
}
async setSigneAleatoire() {
const newSigne = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true});
const newSigne = await RdDItemSigneDraconique.randomSigneDraconique({ ephemere: true });
this.html.find("[name='signe.name']").val(newSigne.name);
this.html.find("[name='signe.system.valeur.norm']").val(newSigne.system.valeur.norm);
@@ -92,7 +92,7 @@ export class DialogCreateSigneDraconique extends Dialog {
this.html.find("[name='signe.system.ephemere']").prop("checked", newSigne.system.ephemere);
this.dialogData.tmrs = TMRUtility.buildSelectionTypesTMR(newSigne.system.typesTMR);
this.dialogData.tmrs.forEach(t => {
this.html.find(`[data-tmr-name='${t.name}']`).prop( "checked", t.selected);
this.html.find(`[data-tmr-name='${t.name}']`).prop("checked", t.selected);
})
this.setEphemere(newSigne.system.ephemere);
}
@@ -113,7 +113,7 @@ export class DialogCreateSigneDraconique extends Dialog {
onSelectTmr(event) {
const tmrName = this.html.find(event.currentTarget)?.data("tmr-name");
const onTmr = this.dialogData.tmrs.find(it => it.name == tmrName);
if (onTmr){
if (onTmr) {
onTmr.selected = event.currentTarget.checked;
}
}