Last active
November 10, 2018 21:40
-
-
Save cozza13/78e80d13ac33540c43cc8087e8cea58a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
/* jslint vars: true, plusplus: true */ | |
// | |
// defaultScripts.js | |
// 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 | |
// | |
var DEFAULT_SCRIPTS = [ | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/progress.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/away.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/users.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/mute.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/goto.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/hmd.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/marketplaces/marketplaces.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/edit.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/mod.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/selectAudioDevice.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/notifications.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/controllers/controllerDisplayManager.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/controllers/handControllerGrab.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/controllers/handControllerPointer.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/controllers/squeezeHands.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/controllers/grab.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/controllers/teleport.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/system/controllers/toggleAdvancedMovementForHandControllers.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/system/dialTone.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/firstPersonHMD.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/snapshot.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/help.js", | |
"https://rawgit.com/ctrlaltdavid/hifi/c4c2a95e837ca226693e03dd4b3c88f4c2b04914/scripts/system/bubble.js" | |
]; | |
// add a menu item for debugging | |
var MENU_CATEGORY = "Developer"; | |
var MENU_ITEM = "Debug defaultScripts.js"; | |
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, | |
isChecked: previousSetting, | |
grouping: "Advanced" | |
}); | |
} | |
function runDefaultsTogether() { | |
for (var j in DEFAULT_SCRIPTS) { | |
Script.include(DEFAULT_SCRIPTS[j]); | |
} | |
} | |
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 | |
debuggingDefaultScripts = true; | |
runDefaultsSeparately(); | |
} else { | |
// include all default scripts into this ScriptEngine | |
runDefaultsTogether(); | |
} | |
function menuItemEvent(menuItem) { | |
if (menuItem == MENU_ITEM) { | |
isChecked = Menu.isOptionChecked(MENU_ITEM); | |
if (isChecked === true) { | |
Settings.setValue(SETTINGS_KEY, true); | |
} else if (isChecked === false) { | |
Settings.setValue(SETTINGS_KEY, false); | |
} | |
Window.alert('You must reload all scripts for this to take effect.') | |
} | |
} | |
function stopLoadedScripts() { | |
// remove debug script loads | |
var runningScripts = ScriptDiscoveryService.getRunning(); | |
for (var i in runningScripts) { | |
var scriptName = runningScripts[i].name; | |
for (var j in DEFAULT_SCRIPTS) { | |
if (DEFAULT_SCRIPTS[j].slice(-scriptName.length) === scriptName) { | |
ScriptDiscoveryService.stopScript(runningScripts[i].url); | |
} | |
} | |
} | |
} | |
function removeMenuItem() { | |
if (!Menu.isOptionChecked(MENU_ITEM)) { | |
Menu.removeMenuItem(MENU_CATEGORY, MENU_ITEM); | |
} | |
} | |
Script.scriptEnding.connect(function() { | |
stopLoadedScripts(); | |
removeMenuItem(); | |
}); | |
Menu.menuItemEvent.connect(menuItemEvent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment