From 192d80aece5bc628a87afea2e0be456e9c1f7ba9 Mon Sep 17 00:00:00 2001 From: Armored Dragon Date: Sat, 8 Jun 2024 11:51:25 -0500 Subject: [PATCH] Floofchat compatibility. Made conversion functions to allow communication between apps. Removed developer console.log function. Signed-off-by: Armored Dragon --- .../armored-chat/armored_chat.js | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/scripts/communityScripts/armored-chat/armored_chat.js b/scripts/communityScripts/armored-chat/armored_chat.js index 6525b83645..df8c3fb03f 100644 --- a/scripts/communityScripts/armored-chat/armored_chat.js +++ b/scripts/communityScripts/armored-chat/armored_chat.js @@ -66,7 +66,6 @@ } function toggleMainChatWindow() { appIsVisible = !appIsVisible; - console.log(`App is now ${appIsVisible ? "visible" : "hidden"}`); appButton.editProperties({ isActive: appIsVisible }); chatOverlayWindow.visible = appIsVisible; @@ -97,6 +96,9 @@ if (channel !== "chat") return; message = JSON.parse(message); + // Floofchat compatibility hook + message = floofChatCompatibilityConversion(message); + message.channel = message.channel.toLowerCase(); // Make sure the "local", "domain", etc. is formatted consistently if (!channels.includes(message.channel)) return; // Check the channel @@ -197,6 +199,8 @@ action: "send_chat_message", }) ); + + floofChatCompatibilitySendMessage(message, channel); } function _avatarAction(type, sessionId) { Script.setTimeout(() => { @@ -251,4 +255,34 @@ function _emitEvent(packet = { type: "" }) { chatOverlayWindow.sendToQml(packet); } + + // + // Floofchat compatibility functions + // Added to ease the transition between Floofchat to ArmoredChat + // These functions can be safely removed at a much later date. + function floofChatCompatibilityConversion(message) { + if (message.type === "TransmitChatMessage" && !message.forApp) { + return { + position: message.position, + message: message.message, + displayName: message.displayName, + channel: message.channel.toLowerCase(), + }; + } + return message; + } + + function floofChatCompatibilitySendMessage(message, channel) { + Messages.sendMessage( + "Chat", + JSON.stringify({ + position: MyAvatar.position, + message: message, + displayName: MyAvatar.sessionDisplayName, + channel: channel.charAt(0).toUpperCase() + channel.slice(1), + type: "TransmitChatMessage", + forApp: "Floof", + }) + ); + } })();