overte/scripts/defaultScripts.js

112 lines
3.0 KiB
JavaScript
Raw Normal View History

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.
//
// 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-08 17:54:54 -07:00
var DEFAULT_SCRIPTS = [
"system/progress.js",
"system/away.js",
"system/audio.js",
"system/hmd.js",
2017-01-25 15:02:55 -08:00
"system/menu.js",
"system/bubble.js",
"system/snapshot.js",
"system/help.js",
"system/pal.js", // "system/mod.js", // older UX, if you prefer
2017-01-25 15:02:55 -08:00
"system/goto.js",
"system/marketplaces/marketplaces.js",
"system/edit.js",
2017-02-01 15:37:54 -08:00
"system/tablet-users.js",
"system/selectAudioDevice.js",
"system/notifications.js",
"system/controllers/controllerDisplayManager.js",
"system/controllers/handControllerGrab.js",
"system/controllers/handControllerPointer.js",
"system/controllers/squeezeHands.js",
"system/controllers/grab.js",
"system/controllers/teleport.js",
2016-08-25 10:26:05 -07:00
"system/controllers/toggleAdvancedMovementForHandControllers.js",
"system/dialTone.js",
"system/firstPersonHMD.js",
2017-01-25 15:02:55 -08:00
"system/tablet-ui/tabletUI.js"
];
2016-05-05 14:55:41 -07:00
// add a menu item for debugging
var MENU_CATEGORY = "Developer";
var MENU_ITEM = "Debug defaultScripts.js";
2016-08-30 13:58:28 -07:00
var SETTINGS_KEY = '_debugDefaultScriptsIsChecked';
var previousSetting = Settings.getValue(SETTINGS_KEY);
if (previousSetting === '' || previousSetting === false || previousSetting === 'false') {
previousSetting = false;
}
if (previousSetting === true || previousSetting === 'true') {
previousSetting = true;
}
if (Menu.menuExists(MENU_CATEGORY) && !Menu.menuItemExists(MENU_CATEGORY, MENU_ITEM)) {
Menu.addMenuItem({
menuName: MENU_CATEGORY,
menuItemName: MENU_ITEM,
isCheckable: true,
2016-08-30 13:58:28 -07:00
isChecked: previousSetting,
grouping: "Advanced"
});
}
2016-08-30 13:58:28 -07:00
function runDefaultsTogether() {
for (var j in DEFAULT_SCRIPTS) {
2016-08-31 21:14:50 -07:00
Script.include(DEFAULT_SCRIPTS[j]);
2016-08-30 13:58:28 -07:00
}
}
function runDefaultsSeparately() {
for (var i in DEFAULT_SCRIPTS) {
Script.load(DEFAULT_SCRIPTS[i]);
}
}
// 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();
} else {
// include all default scripts into this ScriptEngine
2016-08-30 13:58:28 -07:00
runDefaultsTogether();
}
function menuItemEvent(menuItem) {
if (menuItem === MENU_ITEM) {
var isChecked = Menu.isOptionChecked(MENU_ITEM);
2016-08-30 13:58:28 -07:00
if (isChecked === true) {
Settings.setValue(SETTINGS_KEY, true);
} else if (isChecked === false) {
Settings.setValue(SETTINGS_KEY, false);
}
console.log('You must reload all scripts for this to take effect.');
2016-08-30 14:17:27 -07:00
}
2016-08-30 13:58:28 -07:00
}
function removeMenuItem() {
if (!Menu.isOptionChecked(MENU_ITEM)) {
Menu.removeMenuItem(MENU_CATEGORY, MENU_ITEM);
}
}
2016-08-30 13:58:28 -07:00
Script.scriptEnding.connect(function() {
removeMenuItem();
});
Menu.menuItemEvent.connect(menuItemEvent);