From 2c5a742582633087b2b7c297f7686720740320ce Mon Sep 17 00:00:00 2001 From: Arseny Garelyshev Date: Fri, 18 Oct 2024 18:53:52 +0200 Subject: [PATCH] refactor: small cleanup for pc-does-not-understand-language feature --- MessageBroker.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/MessageBroker.js b/MessageBroker.js index f359c5400..06db2ea3c 100644 --- a/MessageBroker.js +++ b/MessageBroker.js @@ -1621,23 +1621,23 @@ class MessageBroker { let datetime = d.toISOString(); let timestamp = d.toLocaleTimeString(); let datestamp = d.toLocaleDateString(); - - if(!window.DM && data.language != undefined){ - const knownLanguages = window.pcs?.find(d=>d.characterId == window.PLAYER_ID)?.proficiencyGroups[3]?.values?.trim().split(/\s*,\s*/gi); - knownLanguages?.push('Telepathy'); - if(!knownLanguages.includes(window.ddbConfigJson.languages.find(d => d.id == data.language).name)){ + + // hide message if PC doesn't speak this language + if (!window.DM && data.language != undefined) { + const pc = find_pc_by_player_id(my_player_id()) + const knownLanguages = pc?.proficiencyGroups.find(g => g.group === "Languages")?.values?.trim().split(/\s*,\s*/gi) ?? []; + knownLanguages.push('Telepathy'); + + if (!knownLanguages.includes(window.ddbConfigJson.languages.find(d => d.id == data.language).name)) { const container = $("
").html(data.text); - const elements = container.find("*"); - const textNodes = elements.contents().not(elements); - textNodes.each(function() { - let newText = this.nodeValue.replaceAll(/[\w\d]/gi, (n) => String.fromCharCode(97 + Math.floor(Math.random() * 26))); - - $(document.createTextNode(newText)).insertBefore(this); - - $(this).remove(); - - }); - data.text = container.html(); + const elements = container.find("*"); + const textNodes = elements.contents().not(elements); + textNodes.each(function () { + let newText = this.nodeValue.replaceAll(/[\w\d]/gi, (n) => String.fromCharCode(97 + Math.floor(Math.random() * 26))); + $(document.createTextNode(newText)).insertBefore(this); + $(this).remove(); + }); + data.text = container.html(); } }