2016-08-23 12:34:32 -07:00
|
|
|
"use strict";
|
|
|
|
/* jslint vars: true, plusplus: true */
|
|
|
|
|
2014-04-08 17:54:54 -07:00
|
|
|
//
|
2014-03-25 00:46:07 -07:00
|
|
|
// defaultScripts.js
|
2014-04-08 17:54:54 -07:00
|
|
|
// examples
|
|
|
|
//
|
|
|
|
// Copyright 2014 High Fidelity, Inc.
|
2020-08-05 23:37:45 -04:00
|
|
|
// Copyright 2020 Vircadia contributors.
|
2022-01-23 15:14:17 -05:00
|
|
|
// Copyright 2022 Overte e.V.
|
2014-04-08 17:54:54 -07:00
|
|
|
//
|
|
|
|
// Distributed under the Apache License, Version 2.0.
|
|
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
2014-04-09 09:44:38 -07:00
|
|
|
//
|
2014-04-08 17:54:54 -07:00
|
|
|
|
2017-03-15 14:31:13 +13:00
|
|
|
var DEFAULT_SCRIPTS_COMBINED = [
|
2018-06-04 12:59:08 -07:00
|
|
|
"system/request-service.js",
|
2016-08-11 18:07:29 -07:00
|
|
|
"system/progress.js",
|
|
|
|
"system/away.js",
|
2017-02-11 22:40:19 +13:00
|
|
|
"system/audio.js",
|
2016-08-11 18:07:29 -07:00
|
|
|
"system/hmd.js",
|
2017-01-25 15:02:55 -08:00
|
|
|
"system/menu.js",
|
|
|
|
"system/bubble.js",
|
|
|
|
"system/snapshot.js",
|
2017-02-22 16:28:52 -08:00
|
|
|
"system/pal.js", // "system/mod.js", // older UX, if you prefer
|
2018-04-19 11:59:26 +03:00
|
|
|
"system/avatarapp.js",
|
2020-08-05 23:37:45 -04:00
|
|
|
"system/graphicsSettings.js",
|
2017-03-13 10:15:06 -07:00
|
|
|
"system/makeUserConnection.js",
|
2018-05-30 13:36:02 -07:00
|
|
|
"system/notifications.js",
|
2019-06-24 14:01:51 -07:00
|
|
|
"system/create/edit.js",
|
2016-08-11 18:07:29 -07:00
|
|
|
"system/dialTone.js",
|
|
|
|
"system/firstPersonHMD.js",
|
2018-01-07 22:14:15 -08:00
|
|
|
"system/tablet-ui/tabletUI.js",
|
2018-08-16 10:58:14 +12:00
|
|
|
"system/emote.js",
|
2019-02-17 14:21:23 -08:00
|
|
|
"system/miniTablet.js",
|
2019-06-28 14:33:03 -07:00
|
|
|
"system/audioMuteOverlay.js",
|
2020-04-26 14:50:43 -07:00
|
|
|
"system/inspect.js",
|
2020-08-27 05:38:50 -04:00
|
|
|
"system/keyboardShortcuts/keyboardShortcuts.js",
|
2020-10-05 20:40:58 -04:00
|
|
|
"system/checkForUpdates.js",
|
2021-02-03 23:13:58 -05:00
|
|
|
"system/onEscape.js",
|
2021-01-18 19:56:12 -05:00
|
|
|
"system/onFirstRun.js",
|
2022-01-22 22:54:52 -05:00
|
|
|
"system/appreciate/appreciate_app.js",
|
|
|
|
"system/places/places.js"
|
2016-08-11 18:07:29 -07:00
|
|
|
];
|
2017-03-15 14:31:13 +13:00
|
|
|
var DEFAULT_SCRIPTS_SEPARATE = [
|
2020-01-08 00:54:48 +00:00
|
|
|
"system/controllers/controllerScripts.js",
|
2020-06-26 18:46:30 -04:00
|
|
|
"communityScripts/notificationCore/notificationCore.js",
|
2020-02-25 02:09:30 -05:00
|
|
|
"simplifiedUI/ui/simplifiedNametag/simplifiedNametag.js",
|
2020-06-10 02:54:42 -04:00
|
|
|
{"stable": "system/more/app-more.js", "beta": "https://cdn.vircadia.com/community-apps/more/app-more.js"},
|
2020-06-26 18:46:30 -04:00
|
|
|
{"stable": "communityScripts/chat/FloofChat.js", "beta": "https://content.fluffy.ws/scripts/chat/FloofChat.js"}
|
2019-12-12 11:10:01 -06:00
|
|
|
//"system/chat.js"
|
2017-03-15 14:31:13 +13:00
|
|
|
];
|
2016-05-05 14:55:41 -07:00
|
|
|
|
2018-09-26 13:48:15 -07:00
|
|
|
if (Window.interstitialModeEnabled) {
|
2018-11-09 10:53:34 +13:00
|
|
|
// Insert interstitial scripts at front so that they're started first.
|
|
|
|
DEFAULT_SCRIPTS_COMBINED.splice(0, 0, "system/interstitialPage.js", "system/redirectOverlays.js");
|
2018-09-12 15:31:03 -07:00
|
|
|
}
|
|
|
|
|
2016-08-11 18:07:29 -07:00
|
|
|
// add a menu item for debugging
|
2018-08-30 11:42:26 -07:00
|
|
|
var MENU_CATEGORY = "Developer > Scripting";
|
2016-08-11 18:07:29 -07:00
|
|
|
var MENU_ITEM = "Debug defaultScripts.js";
|
2016-08-30 13:58:28 -07:00
|
|
|
|
2020-02-28 10:08:54 -05:00
|
|
|
var MENU_BETA_DEFAULT_SCRIPTS_CATEGORY = "Developer > Scripting";
|
|
|
|
var MENU_BETA_DEFAULT_SCRIPTS_ITEM = "Enable Beta Default Scripts";
|
|
|
|
|
2016-08-30 13:58:28 -07:00
|
|
|
var SETTINGS_KEY = '_debugDefaultScriptsIsChecked';
|
2020-01-28 22:06:27 +00:00
|
|
|
var SETTINGS_KEY_BETA = '_betaDefaultScriptsIsChecked';
|
2020-01-29 19:50:23 +00:00
|
|
|
var previousSetting = Settings.getValue(SETTINGS_KEY, false);
|
2020-01-28 22:23:01 +00:00
|
|
|
var previousSettingBeta = Settings.getValue(SETTINGS_KEY_BETA, false);
|
2016-08-30 13:58:28 -07:00
|
|
|
|
2020-03-04 10:46:16 -05:00
|
|
|
if (previousSetting === '' || previousSetting === 'false') {
|
2016-08-30 13:58:28 -07:00
|
|
|
previousSetting = false;
|
|
|
|
}
|
|
|
|
|
2020-03-04 10:46:16 -05:00
|
|
|
if (previousSetting === 'true') {
|
2016-08-30 13:58:28 -07:00
|
|
|
previousSetting = true;
|
|
|
|
}
|
|
|
|
|
2020-03-04 10:46:16 -05:00
|
|
|
if (previousSettingBeta === '' || previousSettingBeta === 'false') {
|
2020-02-28 10:08:54 -05:00
|
|
|
previousSettingBeta = false;
|
|
|
|
}
|
|
|
|
|
2020-03-04 10:46:16 -05:00
|
|
|
if (previousSettingBeta === 'true') {
|
2020-02-28 10:08:54 -05:00
|
|
|
previousSettingBeta = true;
|
|
|
|
}
|
|
|
|
|
2016-08-11 18:07:29 -07:00
|
|
|
if (Menu.menuExists(MENU_CATEGORY) && !Menu.menuItemExists(MENU_CATEGORY, MENU_ITEM)) {
|
|
|
|
Menu.addMenuItem({
|
|
|
|
menuName: MENU_CATEGORY,
|
|
|
|
menuItemName: MENU_ITEM,
|
|
|
|
isCheckable: true,
|
2020-02-29 17:26:20 -05:00
|
|
|
isChecked: previousSetting
|
2016-08-11 18:07:29 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-29 17:26:20 -05:00
|
|
|
if (Menu.menuExists(MENU_BETA_DEFAULT_SCRIPTS_CATEGORY)
|
|
|
|
&& !Menu.menuItemExists(MENU_BETA_DEFAULT_SCRIPTS_CATEGORY, MENU_BETA_DEFAULT_SCRIPTS_ITEM)) {
|
|
|
|
Menu.addMenuItem({
|
|
|
|
menuName: MENU_BETA_DEFAULT_SCRIPTS_CATEGORY,
|
|
|
|
menuItemName: MENU_BETA_DEFAULT_SCRIPTS_ITEM,
|
|
|
|
isCheckable: true,
|
|
|
|
isChecked: previousSettingBeta
|
|
|
|
});
|
2020-02-28 10:08:54 -05:00
|
|
|
}
|
|
|
|
|
2017-03-15 14:31:13 +13:00
|
|
|
function loadSeparateDefaults() {
|
2019-10-08 14:48:19 -04:00
|
|
|
var currentlyRunningScripts = ScriptDiscoveryService.getRunning();
|
|
|
|
|
2017-03-15 14:31:13 +13:00
|
|
|
for (var i in DEFAULT_SCRIPTS_SEPARATE) {
|
2019-10-08 14:48:19 -04:00
|
|
|
var shouldLoadCurrentDefaultScript = true;
|
2020-01-28 22:06:27 +00:00
|
|
|
var scriptItem = DEFAULT_SCRIPTS_SEPARATE[i];
|
|
|
|
if (typeof scriptItem === "object") {
|
|
|
|
if (previousSettingBeta) {
|
2020-01-29 19:50:23 +00:00
|
|
|
console.log("Loading Beta item " + scriptItem.beta);
|
2020-01-28 22:06:27 +00:00
|
|
|
scriptItem = scriptItem.beta;
|
|
|
|
} else {
|
|
|
|
scriptItem = scriptItem.stable;
|
|
|
|
}
|
|
|
|
}
|
2019-10-08 14:48:19 -04:00
|
|
|
|
|
|
|
for (var j = 0; j < currentlyRunningScripts.length; j++) {
|
|
|
|
var currentRunningScriptObject = currentlyRunningScripts[j];
|
2020-01-28 22:06:27 +00:00
|
|
|
var currentDefaultScriptName = scriptItem.substr((scriptItem.lastIndexOf("/") + 1), scriptItem.length);
|
2019-10-08 14:48:19 -04:00
|
|
|
if (currentDefaultScriptName === currentRunningScriptObject.name) {
|
2020-01-29 19:50:23 +00:00
|
|
|
if (currentRunningScriptObject.url !== scriptItem) {
|
|
|
|
ScriptDiscoveryService.stopScript(currentRunningScriptObject.url);
|
|
|
|
} else {
|
|
|
|
shouldLoadCurrentDefaultScript = false;
|
|
|
|
}
|
2019-10-08 14:48:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldLoadCurrentDefaultScript) {
|
2020-01-28 22:06:27 +00:00
|
|
|
Script.load(scriptItem);
|
2019-10-08 14:48:19 -04:00
|
|
|
}
|
2017-03-15 14:31:13 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 13:58:28 -07:00
|
|
|
function runDefaultsTogether() {
|
2019-10-08 14:48:19 -04:00
|
|
|
var currentlyRunningScripts = ScriptDiscoveryService.getRunning();
|
|
|
|
|
|
|
|
for (var i = 0; i < DEFAULT_SCRIPTS_COMBINED.length; i++) {
|
|
|
|
var shouldIncludeCurrentDefaultScript = true;
|
|
|
|
|
|
|
|
for (var j = 0; j < currentlyRunningScripts.length; j++) {
|
|
|
|
var currentRunningScriptObject = currentlyRunningScripts[j];
|
|
|
|
var currentDefaultScriptName = DEFAULT_SCRIPTS_COMBINED[i].substr((DEFAULT_SCRIPTS_COMBINED[i].lastIndexOf("/") + 1), DEFAULT_SCRIPTS_COMBINED[i].length);
|
|
|
|
if (currentDefaultScriptName === currentRunningScriptObject.name) {
|
|
|
|
shouldIncludeCurrentDefaultScript = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldIncludeCurrentDefaultScript) {
|
|
|
|
Script.include(DEFAULT_SCRIPTS_COMBINED[i]);
|
|
|
|
}
|
2016-08-30 13:58:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function runDefaultsSeparately() {
|
2019-10-08 14:48:19 -04:00
|
|
|
var currentlyRunningScripts = ScriptDiscoveryService.getRunning();
|
|
|
|
|
2017-03-15 14:31:13 +13:00
|
|
|
for (var i in DEFAULT_SCRIPTS_COMBINED) {
|
2019-10-08 14:48:19 -04:00
|
|
|
var shouldLoadCurrentDefaultScript = true;
|
|
|
|
|
|
|
|
for (var j = 0; j < currentlyRunningScripts.length; j++) {
|
|
|
|
var currentRunningScriptObject = currentlyRunningScripts[j];
|
|
|
|
var currentDefaultScriptName = DEFAULT_SCRIPTS_COMBINED[i].substr((DEFAULT_SCRIPTS_COMBINED[i].lastIndexOf("/") + 1), DEFAULT_SCRIPTS_COMBINED[i].length);
|
|
|
|
if (currentDefaultScriptName === currentRunningScriptObject.name) {
|
|
|
|
shouldLoadCurrentDefaultScript = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldLoadCurrentDefaultScript) {
|
|
|
|
Script.load(DEFAULT_SCRIPTS_COMBINED[i]);
|
|
|
|
}
|
2016-08-30 13:58:28 -07:00
|
|
|
}
|
|
|
|
}
|
2017-02-22 16:28:52 -08:00
|
|
|
|
2016-08-11 18:07:29 -07:00
|
|
|
// start all scripts
|
|
|
|
if (Menu.isOptionChecked(MENU_ITEM)) {
|
|
|
|
// we're debugging individual default scripts
|
|
|
|
// so we load each into its own ScriptEngine instance
|
2016-08-30 13:58:28 -07:00
|
|
|
runDefaultsSeparately();
|
2016-08-11 18:07:29 -07:00
|
|
|
} else {
|
|
|
|
// include all default scripts into this ScriptEngine
|
2016-08-30 13:58:28 -07:00
|
|
|
runDefaultsTogether();
|
|
|
|
}
|
2019-10-08 14:48:19 -04:00
|
|
|
loadSeparateDefaults();
|
2016-08-30 13:58:28 -07:00
|
|
|
|
|
|
|
function menuItemEvent(menuItem) {
|
2017-02-22 16:28:52 -08:00
|
|
|
if (menuItem === MENU_ITEM) {
|
|
|
|
var isChecked = Menu.isOptionChecked(MENU_ITEM);
|
2020-02-29 17:26:20 -05:00
|
|
|
if (isChecked) {
|
2016-08-30 13:58:28 -07:00
|
|
|
Settings.setValue(SETTINGS_KEY, true);
|
2020-02-29 17:26:20 -05:00
|
|
|
} else {
|
2016-08-30 13:58:28 -07:00
|
|
|
Settings.setValue(SETTINGS_KEY, false);
|
|
|
|
}
|
2017-02-23 11:02:25 -08:00
|
|
|
Menu.triggerOption("Reload All Scripts");
|
2020-02-28 10:08:54 -05:00
|
|
|
}
|
|
|
|
if (menuItem === MENU_BETA_DEFAULT_SCRIPTS_ITEM) {
|
|
|
|
var isChecked = Menu.isOptionChecked(MENU_BETA_DEFAULT_SCRIPTS_ITEM);
|
2020-02-29 17:26:20 -05:00
|
|
|
if (isChecked) {
|
2020-02-28 10:08:54 -05:00
|
|
|
Settings.setValue(SETTINGS_KEY_BETA, true);
|
2020-02-29 17:26:20 -05:00
|
|
|
} else {
|
2020-02-28 10:08:54 -05:00
|
|
|
Settings.setValue(SETTINGS_KEY_BETA, false);
|
|
|
|
}
|
2016-08-30 14:17:27 -07:00
|
|
|
}
|
2016-08-30 13:58:28 -07:00
|
|
|
}
|
|
|
|
|
2020-02-28 10:08:54 -05:00
|
|
|
function removeMenuItems() {
|
2016-08-30 13:58:28 -07:00
|
|
|
if (!Menu.isOptionChecked(MENU_ITEM)) {
|
|
|
|
Menu.removeMenuItem(MENU_CATEGORY, MENU_ITEM);
|
2016-08-11 18:07:29 -07:00
|
|
|
}
|
2020-02-28 10:08:54 -05:00
|
|
|
if (!Menu.isOptionChecked(MENU_BETA_DEFAULT_SCRIPTS_ITEM)) {
|
|
|
|
Menu.removeMenuItem(MENU_BETA_DEFAULT_SCRIPTS_CATEGORY, MENU_BETA_DEFAULT_SCRIPTS_ITEM);
|
|
|
|
}
|
2016-08-11 18:07:29 -07:00
|
|
|
}
|
|
|
|
|
2020-01-28 22:06:27 +00:00
|
|
|
Script.scriptEnding.connect(function () {
|
2020-02-28 10:08:54 -05:00
|
|
|
removeMenuItems();
|
2016-08-30 13:58:28 -07:00
|
|
|
});
|
|
|
|
|
2016-10-21 10:40:39 -07:00
|
|
|
Menu.menuItemEvent.connect(menuItemEvent);
|