From b611cc90923e8bcc7575a8bf5fed0c9dc12029b0 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 9 Jan 2021 19:36:19 +0100 Subject: [PATCH] Reorder params for ease to read (options json param at the end) --- module/actor.js | 10 ++++++---- module/chat-utility.js | 9 ++++----- module/rdd-combat.js | 19 +++++++++---------- module/rdd-commands.js | 5 ++--- module/rdd-resolution-table.js | 6 +++--- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/module/actor.js b/module/actor.js index 82f47209..433db6b4 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1388,8 +1388,9 @@ export class RdDActor extends Actor { value: carac.value, xp: carac.xp } - let content = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html`, xpData); - ChatUtility.createChatMessage({ content: content }, "default", this.name); + ChatUtility.createChatMessage(this.name, "default", { + content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html`, xpData) + }); } } } @@ -1413,8 +1414,9 @@ export class RdDActor extends Actor { archetype: competence.data.niveau_archetype, archetypeWarning: competence.data.niveau > competence.data.niveau_archetype } - let content = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html`, xpData); - ChatUtility.createChatMessage({ content: content }, "default", this.name); + ChatUtility.createChatMessage(this.name, "default", { + content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html`, xpData) + }); } } } diff --git a/module/chat-utility.js b/module/chat-utility.js index 6535d1f1..4649b4cc 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -3,21 +3,20 @@ * Class providing helper methods to get the list of users, and */ export class ChatUtility { + /* -------------------------------------------- */ static removeMyChatMessageContaining(part) { const toDelete = game.messages.filter(it => it.user._id == game.user._id) .filter(it => it.data.content.includes(part)); toDelete.forEach(it => it.delete()); } - /* -------------------------------------------- */ - static chatWithRollMode(chatOptions, name) { - let rollMode = game.settings.get("core", "rollMode"); - ChatUtility.createChatMessage(chatOptions, rollMode, name); + static createChatWithRollMode(name, chatOptions) { + ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions); } /* -------------------------------------------- */ - static createChatMessage(chatOptions, rollMode, name) { + static createChatMessage(name, rollMode, chatOptions) { switch (rollMode) { case "blindroll": // GM only if (!game.user.isGM) { diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 6baaaa80..14f3966b 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -422,9 +422,9 @@ export class RdDCombat { const arme = rollData.arme; const avecArme = arme?.data.categorie_parade != 'sans-armes'; const action = (rollData.attackerRoll ? (arme ? "la parade" : "l'esquive") : "l'attaque"); - ChatUtility.chatWithRollMode({ + ChatUtility.createChatWithRollMode(this.defender.name, { content: `Echec total à ${action}! ` + await RdDRollTables.getMaladresse({ arme: avecArme }) - }, this.defender.name) + }); } /* -------------------------------------------- */ @@ -507,9 +507,9 @@ export class RdDCombat { console.log("RdDCombat._onParadeParticuliere >>>", defenderRoll); if (!defenderRoll.attackerRoll.isPart) { // TODO: attaquant doit jouer résistance et peut être désarmé p132 - ChatUtility.chatWithRollMode({ + ChatUtility.createChatWithRollMode(this.defender.name, { content: `(à gérer) L'attaquant doit jouer résistance et peut être désarmé (p132)` - }, this.defender.name) + }); } } @@ -584,10 +584,9 @@ export class RdDCombat { /* -------------------------------------------- */ _onEsquiveParticuliere(rollData) { console.log("RdDCombat._onEsquiveParticuliere >>>", rollData); - let chatOptions = { + ChatUtility.createChatWithRollMode(this.defender.name, { content: "Vous pouvez esquiver une deuxième esquive!" - } - ChatUtility.chatWithRollMode(chatOptions, this.defender.name) + }); } /* -------------------------------------------- */ @@ -757,7 +756,6 @@ export class RdDCombat { /* -------------------------------------------- */ static async displayActorCombatStatus(actor) { - let rollMode = game.settings.get("core", "rollMode"); let rollData = { alias: actor.name, etatGeneral: actor.getEtatGeneral(), @@ -773,8 +771,9 @@ export class RdDCombat { } else if (actor.countBlessuresByName("graves") > 0) { rollData.isGrave = true; } - let content = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html`, rollData); - ChatUtility.createChatMessage({ content: content }, rollMode, actor.name); + ChatUtility.createChatWithRollMode(actor.name, { + content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html`, rollData) + }); } /* -------------------------------------------- */ diff --git a/module/rdd-commands.js b/module/rdd-commands.js index 19ec34d4..53385113 100644 --- a/module/rdd-commands.js +++ b/module/rdd-commands.js @@ -192,15 +192,14 @@ export class RdDCommands { }; await RdDResolutionTable.rollData(rollData); msg.content = await RdDResolutionTable.buildRollDataHtml(rollData); - ChatUtility.chatWithRollMode(msg, game.user.name); + ChatUtility.createChatWithRollMode(game.user.name, msg); } async rollDeDraconique(msg) { - let rollMode = game.settings.get("core", "rollMode"); let ddr = new DeDraconique().evaluate(); await RdDDice.show(ddr, rollMode); msg.content = `Lancer d'un Dé draconique: ${ddr.total}`; - ChatUtility.createChatMessage(msg, rollMode, game.user.name); + ChatUtility.createChatWithRollMode(game.user.name, msg); } } diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 187a64d7..fd516b21 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -91,9 +91,9 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static async displayRollData(rollData, actor = undefined, template = 'chat-resultat-general.html') { - ChatUtility.chatWithRollMode( - { content: await RdDResolutionTable.buildRollDataHtml(rollData, actor, template) }, - actor?.userName ?? game.user.name) + ChatUtility.createChatWithRollMode(actor?.userName ?? game.user.name, { + content: await RdDResolutionTable.buildRollDataHtml(rollData, actor, template) + }); } /* -------------------------------------------- */