Corrected case on variables.

Signed-off-by: Armored Dragon <publicmail@armoreddragon.com>
This commit is contained in:
Armored Dragon 2024-06-08 08:41:53 -05:00
parent 7fc1a3d175
commit eb84de84b4
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B

View file

@ -10,7 +10,7 @@
(() => { (() => {
"use strict"; "use strict";
var app_is_visible = false; var appIsVisible = false;
var settings = { var settings = {
external_window: false, external_window: false,
maximum_messages: 200, maximum_messages: 200,
@ -18,22 +18,22 @@
// Global vars // Global vars
var tablet; var tablet;
var chat_overlay_window; var chatOverlayWindow;
var app_button; var appButton;
var quick_message; var quickMessage;
const channels = ["domain", "local"]; const channels = ["domain", "local"];
var message_history = Settings.getValue("ArmoredChat-Messages", []) || []; var messageHistory = Settings.getValue("ArmoredChat-Messages", []) || [];
var max_local_distance = 20; // Maximum range for the local chat var maxLocalDistance = 20; // Maximum range for the local chat
var pal_data = AvatarManager.getPalData().data; var palData = AvatarManager.getPalData().data;
Controller.keyPressEvent.connect(keyPressEvent); Controller.keyPressEvent.connect(keyPressEvent);
Messages.subscribe("chat"); Messages.subscribe("chat");
Messages.messageReceived.connect(receivedMessage); Messages.messageReceived.connect(receivedMessage);
AvatarManager.avatarAddedEvent.connect((session_id) => { AvatarManager.avatarAddedEvent.connect((sessionId) => {
_avatarAction("connected", session_id); _avatarAction("connected", sessionId);
}); });
AvatarManager.avatarRemovedEvent.connect((session_id) => { AvatarManager.avatarRemovedEvent.connect((sessionId) => {
_avatarAction("left", session_id); _avatarAction("left", sessionId);
}); });
startup(); startup();
@ -41,62 +41,61 @@
function startup() { function startup() {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
app_button = tablet.addButton({ appButton = tablet.addButton({
icon: Script.resolvePath("./img/icon_white.png"), icon: Script.resolvePath("./img/icon_white.png"),
activeIcon: Script.resolvePath("./img/icon_black.png"), activeIcon: Script.resolvePath("./img/icon_black.png"),
text: "CHAT", text: "CHAT",
isActive: app_is_visible, isActive: appIsVisible,
}); });
// When script ends, remove itself from tablet // When script ends, remove itself from tablet
Script.scriptEnding.connect(function () { Script.scriptEnding.connect(function () {
console.log("Shutting Down"); console.log("Shutting Down");
tablet.removeButton(app_button); tablet.removeButton(appButton);
chat_overlay_window.close(); chatOverlayWindow.close();
}); });
// Overlay button toggle // Overlay button toggle
app_button.clicked.connect(toggleMainChatWindow); appButton.clicked.connect(toggleMainChatWindow);
quick_message = new OverlayWindow({ quickMessage = new OverlayWindow({
source: Script.resolvePath("./armored_chat_quick_message.qml"), source: Script.resolvePath("./armored_chat_quick_message.qml"),
}); });
_openWindow(); _openWindow();
} }
function toggleMainChatWindow() { function toggleMainChatWindow() {
app_is_visible = !app_is_visible; appIsVisible = !appIsVisible;
console.log(`App is now ${app_is_visible ? "visible" : "hidden"}`); console.log(`App is now ${appIsVisible ? "visible" : "hidden"}`);
app_button.editProperties({ isActive: app_is_visible }); appButton.editProperties({ isActive: appIsVisible });
chat_overlay_window.visible = app_is_visible; chatOverlayWindow.visible = appIsVisible;
// External window was closed; the window does not exist anymore // External window was closed; the window does not exist anymore
if (chat_overlay_window.title == "" && app_is_visible) { if (chatOverlayWindow.title == "" && appIsVisible) {
_openWindow(); _openWindow();
} }
} }
function _openWindow() { function _openWindow() {
chat_overlay_window = new Desktop.createWindow( chatOverlayWindow = new Desktop.createWindow(
Script.resolvePath("./armored_chat.qml"), Script.resolvePath("./armored_chat.qml"),
{ {
title: "Chat", title: "Chat",
size: { x: 550, y: 400 }, size: { x: 550, y: 400 },
additionalFlags: Desktop.ALWAYS_ON_TOP, additionalFlags: Desktop.ALWAYS_ON_TOP,
visible: app_is_visible, visible: appIsVisible,
presentationMode: Desktop.PresentationMode.VIRTUAL, presentationMode: Desktop.PresentationMode.VIRTUAL,
} }
); );
chat_overlay_window.closed.connect(toggleMainChatWindow); chatOverlayWindow.closed.connect(toggleMainChatWindow);
chat_overlay_window.fromQml.connect(fromQML); chatOverlayWindow.fromQml.connect(fromQML);
quick_message.fromQml.connect(fromQML); quickMessage.fromQml.connect(fromQML);
} }
function receivedMessage(channel, message) { function receivedMessage(channel, message) {
// Is the message a chat message? // Is the message a chat message?
channel = channel.toLowerCase(); channel = channel.toLowerCase();
if (channel !== "chat") return; if (channel !== "chat") return;
console.log(`Received message:\n${message}`); message = JSON.parse(message);
var message = JSON.parse(message);
message.channel = message.channel.toLowerCase(); // Make sure the "local", "domain", etc. is formatted consistently message.channel = message.channel.toLowerCase(); // Make sure the "local", "domain", etc. is formatted consistently
@ -104,7 +103,7 @@
if ( if (
message.channel == "local" && message.channel == "local" &&
Vec3.distance(MyAvatar.position, message.position) > Vec3.distance(MyAvatar.position, message.position) >
max_local_distance maxLocalDistance
) )
return; // If message is local, and if player is too far away from location, don't do anything return; // If message is local, and if player is too far away from location, don't do anything
@ -120,25 +119,23 @@
); );
// Save message to history // Save message to history
let saved_message = message; let savedMessage = message;
delete saved_message.position; delete savedMessage.position;
saved_message.timeString = new Date().toLocaleTimeString(undefined, { savedMessage.timeString = new Date().toLocaleTimeString(undefined, {
hour12: false, hour12: false,
}); });
saved_message.dateString = new Date().toLocaleDateString(undefined, { savedMessage.dateString = new Date().toLocaleDateString(undefined, {
year: "numeric", year: "numeric",
month: "long", month: "long",
day: "numeric", day: "numeric",
}); });
message_history.push(saved_message); messageHistory.push(savedMessage);
while (message_history.length > settings.maximum_messages) { while (messageHistory.length > settings.maximum_messages) {
message_history.shift(); messageHistory.shift();
} }
Settings.setValue("ArmoredChat-Messages", message_history); Settings.setValue("ArmoredChat-Messages", messageHistory);
} }
function fromQML(event) { function fromQML(event) {
console.log(`New QML event:\n${JSON.stringify(event)}`);
switch (event.type) { switch (event.type) {
case "send_message": case "send_message":
_sendMessage(event.message, event.channel); _sendMessage(event.message, event.channel);
@ -149,7 +146,7 @@
switch (event.setting) { switch (event.setting) {
case "external_window": case "external_window":
chat_overlay_window.presentationMode = event.value chatOverlayWindow.presentationMode = event.value
? Desktop.PresentationMode.NATIVE ? Desktop.PresentationMode.NATIVE
: Desktop.PresentationMode.VIRTUAL; : Desktop.PresentationMode.VIRTUAL;
break; break;
@ -171,7 +168,7 @@
break; break;
case "initialized": case "initialized":
// https://github.com/overte-org/overte/issues/824 // https://github.com/overte-org/overte/issues/824
chat_overlay_window.visible = app_is_visible; // The "visible" field in the Desktop.createWindow does not seem to work. Force set it to the initial state (false) chatOverlayWindow.visible = appIsVisible; // The "visible" field in the Desktop.createWindow does not seem to work. Force set it to the initial state (false)
_loadSettings(); _loadSettings();
break; break;
} }
@ -181,7 +178,7 @@
case "16777220": // Enter key case "16777220": // Enter key
if (HMD.active) return; // Don't allow in VR if (HMD.active) return; // Don't allow in VR
quick_message.sendToQml({ quickMessage.sendToQml({
type: "change_visibility", type: "change_visibility",
value: true, value: true,
}); });
@ -201,28 +198,28 @@
}) })
); );
} }
function _avatarAction(type, session_id) { function _avatarAction(type, sessionId) {
Script.setTimeout(() => { Script.setTimeout(() => {
if (type == "connected") { if (type == "connected") {
pal_data = AvatarManager.getPalData().data; palData = AvatarManager.getPalData().data;
} }
// Get the display name of the user // Get the display name of the user
let display_name = ""; let displayName = "";
display_name = displayName =
AvatarManager.getPalData([session_id])?.data[0] AvatarManager.getPalData([sessionId])?.data[0]
?.sessionDisplayName || null; ?.sessionDisplayName || null;
if (display_name == null) { if (displayName == null) {
for (let i = 0; i < pal_data.length; i++) { for (let i = 0; i < palData.length; i++) {
if (pal_data[i].sessionUUID == session_id) { if (palData[i].sessionUUID == sessionId) {
display_name = pal_data[i].sessionDisplayName; displayName = palData[i].sessionDisplayName;
} }
} }
} }
// Format the packet // Format the packet
let message = {}; let message = {};
message.message = `${display_name} ${type}`; message.message = `${displayName} ${type}`;
_emitEvent({ type: "notification", ...message }); _emitEvent({ type: "notification", ...message });
}, 1500); }, 1500);
@ -230,9 +227,9 @@
function _loadSettings() { function _loadSettings() {
settings = Settings.getValue("ArmoredChat-Config", settings); settings = Settings.getValue("ArmoredChat-Config", settings);
if (message_history) { if (messageHistory) {
// Load message history // Load message history
message_history.forEach((message) => { messageHistory.forEach((message) => {
delete message.action; delete message.action;
_emitEvent({ type: "show_message", ...message }); _emitEvent({ type: "show_message", ...message });
}); });
@ -240,8 +237,6 @@
// Send current settings to the app // Send current settings to the app
_emitEvent({ type: "initial_settings", settings: settings }); _emitEvent({ type: "initial_settings", settings: settings });
console.log(`\n\n\n` + JSON.stringify(settings));
} }
function _saveSettings() { function _saveSettings() {
console.log("Saving config"); console.log("Saving config");
@ -254,6 +249,6 @@
* @param {("show_message"|"clear_messages"|"notification"|"initial_settings")} packet.type - The type of packet it is * @param {("show_message"|"clear_messages"|"notification"|"initial_settings")} packet.type - The type of packet it is
*/ */
function _emitEvent(packet = { type: "" }) { function _emitEvent(packet = { type: "" }) {
chat_overlay_window.sendToQml(packet); chatOverlayWindow.sendToQml(packet);
} }
})(); })();