Skip to content

Commit

Permalink
Fix chat bubles
Browse files Browse the repository at this point in the history
Fix #373
  • Loading branch information
mclemente committed Jun 10, 2024
1 parent 5433f47 commit b53a9ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
35 changes: 18 additions & 17 deletions src/module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,29 @@ export class Polyglot {
}
} else {
// Find the message out of the last 10 chat messages, last to first
const messages = game.messages.contents
const msg = game.messages.contents
.slice(-10)
.reverse()
.find((m) => m.content === message);
.find(
(m) => m.content === message && m.style === CONST.CHAT_MESSAGE_STYLES.IC
);
// Message was sent in-character (no /ooc or /emote)
if (messages?.type === CONST.CHAT_MESSAGE_STYLES.IC) {
lang = messages.getFlag("polyglot", "language") || "";
randomId = messages.id;
if (msg) {
lang = msg.getFlag("polyglot", "language") || "";
randomId = msg.id;
}
}
if (lang) {
// Language isn't truespeech, isn't known and user isn't under Comprehend Languages effect
const unknown = !this.isLanguageknownOrUnderstood(lang);
if (unknown) {
message = this.scrambleString(message, randomId, lang);
document.documentElement.style.setProperty(
"--polyglot-chat-bubble-font",
this._getFontStyle(lang).replace(/\d+%\s/g, ""),
);
if (cssClasses === undefined) cssClasses = [];
cssClasses.push("polyglot", "polyglot-chat-bubble");
}
// Language isn't truespeech, isn't known and user isn't under Comprehend Languages effect
if (lang && !this.isLanguageknownOrUnderstood(lang)) {
message = this.scrambleString(message, randomId, lang);
document.documentElement.style.setProperty(
"--polyglot-chat-bubble-font",
this._getFontStyle(lang).replace(/\d+%\s/g, ""),
);
if (cssClasses === undefined) cssClasses = [];
// circumventing core issue https://github.com/foundryvtt/foundryvtt/issues/11178
// cssClasses.push("polyglot, polyglot-chat-bubble");
cssClasses.push("polyglot polyglot-chat-bubble");
}
return wrapped(token, message, { cssClasses, requireVisible, pan });
},
Expand Down
2 changes: 1 addition & 1 deletion src/styles/polyglot.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

.polyglot {
.polyglot-chat-bubble {
&.polyglot-chat-bubble {
font-family: $font-family_1;
}

Expand Down

0 comments on commit b53a9ba

Please sign in to comment.