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,13 +4,36 @@
*/ */
export class ChatUtility { export class ChatUtility {
/* -------------------------------------------- */ static onSocketMessage(sockmsg) {
static removeMyChatMessageContaining(part) { switch (sockmsg.msg) {
const toDelete = game.messages.filter(it => it.user._id == game.user._id) case "msg_delete_chat_message": return ChatUtility.onRemoveMessages(sockmsg.part, sockmsg.gmId);
.filter(it => it.data.content.includes(part)); }
}
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()); 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,
}});
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static createChatWithRollMode(name, chatOptions) { static createChatWithRollMode(name, chatOptions) {
ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions); ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions);

View File

@ -44,18 +44,18 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
static onPreDeleteCombat(combat, options) { static onPreDeleteCombat(combat, options) {
if (game.user.isGM) { 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 * TODO: support de plusieurs combats parallèles
* il faudrait avoir un id de combat en plus de celui de passe d'armes * il faudrait avoir un id de combat en plus de celui de passe d'armes
*/ */
for (const key in game.system.rdd.combatStore.attaques) { for (const key in game.system.rdd.combatStore.attaques) {
const attackerRoll = game.system.rdd.combatStore.attaques[key]; 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) { for (const key in game.system.rdd.combatStore.defenses) {
const defenderRoll = game.system.rdd.combatStore.defenses[key]; const defenderRoll = game.system.rdd.combatStore.defenses[key];
ChatUtility.removeMyChatMessageContaining(`<div data-passearme="${defenderRoll.passeArme}">`); ChatUtility.removeChatMessageContaining(`<div data-passearme="${defenderRoll.passeArme}">`);
} }
RdDCombat.initStorePasseArmes(); RdDCombat.initStorePasseArmes();
} }
@ -174,6 +174,7 @@ export class RdDCombat {
const defenderRoll = msg.defenderRoll; const defenderRoll = msg.defenderRoll;
RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll); RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
RdDCombat._storeDefense(defenderRoll); RdDCombat._storeDefense(defenderRoll);
rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
rddCombat._chatMessageDefense(msg.paramChatDefense); rddCombat._chatMessageDefense(msg.paramChatDefense);
} }
} }
@ -310,8 +311,8 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
removeChatMessageActionsPasseArme(passeArme) { removeChatMessageActionsPasseArme(passeArme) {
if (game.user.isGM && game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")) { if (game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")) {
ChatUtility.removeMyChatMessageContaining(`<div data-passearme="${passeArme}">`); ChatUtility.removeChatMessageContaining(`<div data-passearme="${passeArme}">`);
} }
} }
@ -560,7 +561,8 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
async choixParticuliere(rollData, choix) { async choixParticuliere(rollData, choix) {
console.log("RdDCombat.choixParticuliere >>>", rollData, choix); console.log("RdDCombat.choixParticuliere >>>", rollData, choix);
// TODO
this.removeChatMessageActionsPasseArme(rollData.passeArme);
rollData.particuliere = choix; rollData.particuliere = choix;
await this._onAttaqueNormale(rollData); await this._onAttaqueNormale(rollData);
} }

View File

@ -186,6 +186,7 @@ Hooks.once("init", async function () {
game.socket.on("system.foundryvtt-reve-de-dragon", data => { game.socket.on("system.foundryvtt-reve-de-dragon", data => {
RdDUtility.onSocketMesssage(data); RdDUtility.onSocketMesssage(data);
RdDCombat.onSocketMessage(data); RdDCombat.onSocketMessage(data);
ChatUtility.onSocketMessage(data);
}); });
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -224,14 +225,15 @@ Hooks.once("init", async function () {
/* -------------------------------------------- */ /* -------------------------------------------- */
function messageDeBienvenue() { function messageDeBienvenue() {
ChatUtility.removeMyChatMessageContaining('<div id="message-bienvenue-rdd">'); if (game.user.isGM) {
ChatUtility.removeChatMessageContaining('<div id="message-bienvenue-rdd">');
ChatMessage.create({ ChatMessage.create({
user: game.user._id, 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> 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>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> <br>La commande <code>/aide</code> dans le chat permet de voir les commandes spécifiques à Rêve de Dragon.</div>
` }); ` });
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */