foundryvtt-reve-de-dragon/module/chat-utility.js

81 lines
2.5 KiB
JavaScript
Raw Normal View History

/**
* Class providing helper methods to get the list of users, and
*/
export class ChatUtility {
static chatWithRollMode(chatOptions, name) {
let rollMode = game.settings.get("core", "rollMode");
ChatUtility.createChatMessage(chatOptions, rollMode, name);
}
2020-12-11 08:29:24 +01:00
/* -------------------------------------------- */
static createChatMessage( chatOptions, rollMode, name) {
switch (rollMode) {
case "blindroll": // GM only
if (!game.user.isGM) {
ChatUtility.blindMessageToGM(chatOptions);
chatOptions.whisper = [game.user._id];
chatOptions.content = "Message envoyé en aveugle au Gardien";
}
else {
chatOptions.whisper = ChatUtility.getUsers(user => user.isGM);
}
break;
default:
chatOptions.whisper = ChatUtility.getWhisperRecipients(rollMode, name);
break;
}
ChatMessage.create(chatOptions);
}
2020-12-11 08:29:24 +01:00
/* -------------------------------------------- */
static prepareChatMessage( rollMode, name) {
return {
user: game.user._id,
whisper: ChatUtility.getWhisperRecipients(rollMode, name)
}
}
2020-12-11 08:29:24 +01:00
/* -------------------------------------------- */
static getWhisperRecipients( rollMode, name) {
switch (rollMode) {
case "blindroll": return ChatUtility.getUsers(user => user.isGM);
case "gmroll": return ChatUtility.getWhisperRecipientsAndGMs(name);
case "selfroll": return [game.user._id];
}
return undefined;
}
2020-12-11 08:29:24 +01:00
/* -------------------------------------------- */
static getWhisperRecipientsAndGMs(name) {
return ChatMessage.getWhisperRecipients(name)
.concat(this.getUsers(user => user.isGM));
}
2020-12-11 08:29:24 +01:00
/* -------------------------------------------- */
static getUsers(filter) {
return game.users.filter(filter).map(user => user.data._id);
}
2020-12-11 08:29:24 +01:00
/* -------------------------------------------- */
static blindMessageToGM(chatOptions) {
let chatGM = duplicate(chatOptions);
chatGM.whisper = ChatUtility.getUsers(user => user.isGM);
chatGM.content = "Message aveugle de " + game.user.name + "<br>" + chatOptions.content;
console.log("blindMessageToGM", chatGM);
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_gm_chat_message", data: chatGM });
}
2020-12-11 08:29:24 +01:00
/* -------------------------------------------- */
static handleGMChatMessage(data) {
console.log("blindMessageToGM", data);
if (game.user.isGM) { // message privé pour GM only
data.user = game.user._id;
ChatMessage.create(data);
}
}
}