Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Made compatible with 0.7 and 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
cs96and committed Jun 14, 2021
1 parent 4210e6a commit 82727eb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion module/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "This is auto replaced",
"library": false,
"manifestPlusVersion": "1.0.0",
"minimumCoreVersion" : "0.8.6",
"minimumCoreVersion" : "0.7.9",
"compatibleCoreVersion": "0.8.6",
"authors": [
{
Expand Down
62 changes: 38 additions & 24 deletions module/scripts/chat-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export class ChatResolver {

static DESCRIPTION_SPEAKER_ALIAS = '#CGMP_DESCRIPTION';

static isV0_8() {
return isNewerVersion(game.data.version, "0.7.9999");
}

static wrapFoundryMethods() {
const _ChatLog_parse = function(wrapped, message) {
if (game.user.isGM)
Expand All @@ -26,7 +30,7 @@ export class ChatResolver {
};

const _ChatLog_prototype_processMessage = async function(wrapped, message) {
const cls = ChatMessage.implementation;
const cls = ChatResolver.isV0_8() ? ChatMessage.implementation : CONFIG.ChatMessage.entityClass;

// Set up basic chat data
const chatData = {
Expand Down Expand Up @@ -64,51 +68,61 @@ export class ChatResolver {
libWrapper.register('CautiousGamemastersPack', "ChatLog.prototype.processMessage", _ChatLog_prototype_processMessage, 'MIXED');
}

static _convertToOoc(messageData) {
if (ChatResolver.isV0_8()) {
messageData.update({
type: CONST.CHAT_MESSAGE_TYPES.OOC,
speaker: {
actor: null,
alias: game.users.get(messageData.user).name,
token: null
}
});
} else {
messageData.type = CONST.CHAT_MESSAGE_TYPES.OOC;
messageData.speaker.actor = null;
messageData.speaker.alias = game.users.get(messageData.user).name;
messageData.speaker.token = null;
}
}

static _resolveHiddenToken(message) {
if (!game.user.isGM) return;
if (!CGMPSettings.getSetting(CGMP_OPTIONS.BLIND_HIDDEN_TOKENS)) return;
const speaker = message.data.speaker;
const messageData = ChatResolver.isV0_8() ? message.data : message;
const speaker = messageData.speaker;
if (!speaker) return;
const token = canvas.tokens.get(speaker.token);
if (token?.data?.hidden) {
if (CONST.CHAT_MESSAGE_TYPES.IC !== message.data.type)
if (CONST.CHAT_MESSAGE_TYPES.IC !== messageData.type)
{
// Whisper any non in-character messages.
message.data.update({
whisper : ChatMessage.getWhisperRecipients("GM")
});
if (ChatResolver.isV0_8()) {
messageData.update({
whisper: ChatMessage.getWhisperRecipients("GM")
});
} else {
messageData.whisper = ChatMessage.getWhisperRecipients("GM");
}
}
else
{
// Convert in-character messages to out-of-character.
// We're assuming that the GM wanted to type something to the chat but forgot to deselect a token.
message.data.update({
type: CONST.CHAT_MESSAGE_TYPES.OOC,
speaker: {
actor: null,
alias: game.users.get(message.data.user).name,
token: null
},
});
this._convertToOoc(messageData);
}
}
}

static _resolvePCToken(message) {
if (!game.user.isGM) return;
if (!CGMPSettings.getSetting(CGMP_OPTIONS.DISABLE_GM_AS_PC)) return;
const speaker = message.data.speaker;
const messageData = ChatResolver.isV0_8() ? message.data : message;
const speaker = messageData.speaker;
if (!speaker) return;
const token = canvas.tokens.get(speaker.token);
if (!message.data.roll && token?.actor?.hasPlayerOwner) {
message.data.update({
speaker: {
actor: null,
alias: game.users.get(message.data.user).name,
token: null
},
type: CONST.CHAT_MESSAGE_TYPES.OOC
});
if (!messageData.roll && token?.actor?.hasPlayerOwner) {
this._convertToOoc(messageData);
}
}

Expand Down

0 comments on commit 82727eb

Please sign in to comment.