From 9bc24fd32676fa6b6a2c3c642100b06138a8dfb8 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 20 Jan 2021 00:44:19 +0100 Subject: [PATCH] Fix suppression de messages --- module/chat-utility.js | 31 +++++++++++++++++++++++++++---- module/rdd-combat.js | 14 ++++++++------ module/rdd-main.js | 18 ++++++++++-------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/module/chat-utility.js b/module/chat-utility.js index 2d71979c..be3c737b 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -3,12 +3,35 @@ * Class providing helper methods to get the list of users, and */ export class ChatUtility { + + static onSocketMessage(sockmsg) { + switch (sockmsg.msg) { + case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.part, sockmsg.gmId); + } + } + + static onRemoveMessages(part, gmId) { + if (game.user._id == gmId) { + const toDelete = game.messages.filter(it => it.data.content.includes(part)); + toDelete.forEach(it => it.delete()); + } + + } /* -------------------------------------------- */ - 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 removeChatMessageContaining(part) { + const gmId = game.user.isGM ? game.user._id : game.users.entities.find(u => u.isGM)?.id; + + if (!gmId || game.user.isGM) { + ChatUtility.onRemoveMessages(part, game.user._id); + } + else { + game.socket.emit("system.foundryvtt-reve-de-dragon", { + msg: "msg_delete_chat_message", data: { + part:part, + gmId: gmId, + }}); + } } /* -------------------------------------------- */ diff --git a/module/rdd-combat.js b/module/rdd-combat.js index d4cd0726..a1347775 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -44,18 +44,18 @@ export class RdDCombat { /* -------------------------------------------- */ static onPreDeleteCombat(combat, options) { if (game.user.isGM) { - ChatUtility.removeMyChatMessageContaining(`
`) + ChatUtility.removeChatMessageContaining(`
`) /* * TODO: support de plusieurs combats parallèles * il faudrait avoir un id de combat en plus de celui de passe d'armes */ for (const key in game.system.rdd.combatStore.attaques) { const attackerRoll = game.system.rdd.combatStore.attaques[key]; - ChatUtility.removeMyChatMessageContaining(`
`); + ChatUtility.removeChatMessageContaining(`
`); } for (const key in game.system.rdd.combatStore.defenses) { const defenderRoll = game.system.rdd.combatStore.defenses[key]; - ChatUtility.removeMyChatMessageContaining(`
`); + ChatUtility.removeChatMessageContaining(`
`); } RdDCombat.initStorePasseArmes(); } @@ -174,6 +174,7 @@ export class RdDCombat { const defenderRoll = msg.defenderRoll; RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll); RdDCombat._storeDefense(defenderRoll); + rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme); rddCombat._chatMessageDefense(msg.paramChatDefense); } } @@ -310,8 +311,8 @@ export class RdDCombat { /* -------------------------------------------- */ removeChatMessageActionsPasseArme(passeArme) { - if (game.user.isGM && game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")) { - ChatUtility.removeMyChatMessageContaining(`
`); + if (game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")) { + ChatUtility.removeChatMessageContaining(`
`); } } @@ -560,7 +561,8 @@ export class RdDCombat { /* -------------------------------------------- */ async choixParticuliere(rollData, choix) { console.log("RdDCombat.choixParticuliere >>>", rollData, choix); - // TODO + + this.removeChatMessageActionsPasseArme(rollData.passeArme); rollData.particuliere = choix; await this._onAttaqueNormale(rollData); } diff --git a/module/rdd-main.js b/module/rdd-main.js index 618fe3cd..83ae02c2 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -186,6 +186,7 @@ Hooks.once("init", async function () { game.socket.on("system.foundryvtt-reve-de-dragon", data => { RdDUtility.onSocketMesssage(data); RdDCombat.onSocketMessage(data); + ChatUtility.onSocketMessage(data); }); /* -------------------------------------------- */ @@ -224,14 +225,15 @@ Hooks.once("init", async function () { /* -------------------------------------------- */ function messageDeBienvenue() { - ChatUtility.removeMyChatMessageContaining('
'); - ChatMessage.create({ - user: game.user._id, - whisper: [game.user._id], - content: `
Bienvenue dans le Rêve des Dragons ! -
Vous trouverez quelques informations pour démarrer dans ce document : @Compendium[foundryvtt-reve-de-dragon.rappel-des-regles.7uGrUHGdPu0EmIu2]{Documentation MJ/Joueurs} -
La commande /aide dans le chat permet de voir les commandes spécifiques à Rêve de Dragon.
- ` }); + if (game.user.isGM) { + ChatUtility.removeChatMessageContaining('
'); + ChatMessage.create({ + user: game.user._id, + content: `
Bienvenue dans le Rêve des Dragons ! +
Vous trouverez quelques informations pour démarrer dans ce document : @Compendium[foundryvtt-reve-de-dragon.rappel-des-regles.7uGrUHGdPu0EmIu2]{Documentation MJ/Joueurs} +
La commande /aide dans le chat permet de voir les commandes spécifiques à Rêve de Dragon.
+ ` }); + } } /* -------------------------------------------- */