Fix suppression de messages

This commit is contained in:
Vincent Vandemeulebrouck 2021-01-20 00:44:19 +01:00
parent cf1c7003d1
commit 9bc24fd326
3 changed files with 45 additions and 18 deletions

View File

@ -4,11 +4,34 @@
*/
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,
}});
}
}
/* -------------------------------------------- */

View File

@ -44,18 +44,18 @@ export class RdDCombat {
/* -------------------------------------------- */
static onPreDeleteCombat(combat, options) {
if (game.user.isGM) {
ChatUtility.removeMyChatMessageContaining(`<div data-combatid="${combat.id}" data-combatmessage="actor-turn-summary">`)
ChatUtility.removeChatMessageContaining(`<div data-combatid="${combat.id}" data-combatmessage="actor-turn-summary">`)
/*
* 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(`<div data-passearme="${attackerRoll.passeArme}">`);
ChatUtility.removeChatMessageContaining(`<div data-passearme="${attackerRoll.passeArme}">`);
}
for (const key in game.system.rdd.combatStore.defenses) {
const defenderRoll = game.system.rdd.combatStore.defenses[key];
ChatUtility.removeMyChatMessageContaining(`<div data-passearme="${defenderRoll.passeArme}">`);
ChatUtility.removeChatMessageContaining(`<div data-passearme="${defenderRoll.passeArme}">`);
}
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(`<div data-passearme="${passeArme}">`);
if (game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")) {
ChatUtility.removeChatMessageContaining(`<div data-passearme="${passeArme}">`);
}
}
@ -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);
}

View File

@ -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('<div id="message-bienvenue-rdd">');
ChatMessage.create({
user: game.user._id,
whisper: [game.user._id],
content: `<div id="message-bienvenue-rdd"><span class="rdd-roll-part">Bienvenue dans le Rêve des Dragons !</span>
<br>Vous trouverez quelques informations pour démarrer dans ce document : @Compendium[foundryvtt-reve-de-dragon.rappel-des-regles.7uGrUHGdPu0EmIu2]{Documentation MJ/Joueurs}
<br>La commande <code>/aide</code> dans le chat permet de voir les commandes spécifiques à Rêve de Dragon.</div>
` });
if (game.user.isGM) {
ChatUtility.removeChatMessageContaining('<div id="message-bienvenue-rdd">');
ChatMessage.create({
user: game.user._id,
content: `<div id="message-bienvenue-rdd"><span class="rdd-roll-part">Bienvenue dans le Rêve des Dragons !</span>
<br>Vous trouverez quelques informations pour démarrer dans ce document : @Compendium[foundryvtt-reve-de-dragon.rappel-des-regles.7uGrUHGdPu0EmIu2]{Documentation MJ/Joueurs}
<br>La commande <code>/aide</code> dans le chat permet de voir les commandes spécifiques à Rêve de Dragon.</div>
` });
}
}
/* -------------------------------------------- */