diff --git a/examples/example/games/satellite.js b/examples/example/games/satellite.js index db65198b87..9ae0105917 100644 --- a/examples/example/games/satellite.js +++ b/examples/example/games/satellite.js @@ -15,7 +15,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include('../utilities/tools/vector.js'); +Script.include('../../utilities/tools/vector.js'); var URL = "https://s3.amazonaws.com/hifi-public/marketplace/hificontent/Scripts/planets/"; diff --git a/examples/libraries/entityCameraTool.js b/examples/libraries/entityCameraTool.js index 88e01b29fe..e3e86cedb3 100644 --- a/examples/libraries/entityCameraTool.js +++ b/examples/libraries/entityCameraTool.js @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/overlayUtils.js"); +Script.include("overlayUtils.js"); var MOUSE_SENSITIVITY = 0.9; var SCROLL_SENSITIVITY = 0.05; diff --git a/examples/libraries/entityList.js b/examples/libraries/entityList.js index bb84ce27b4..1aa08fbe2d 100644 --- a/examples/libraries/entityList.js +++ b/examples/libraries/entityList.js @@ -1,7 +1,9 @@ +var ENTITY_LIST_HTML_URL = Script.resolvePath('../html/entityList.html'); + EntityListTool = function(opts) { var that = {}; - var url = Script.resolvePath('html/entityList.html'); + var url = ENTITY_LIST_HTML_URL; var webView = new WebWindow('Entities', url, 200, 280, true); var searchRadius = 100; diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index ed4e999be8..35d9858ace 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -1,3 +1,5 @@ +var GRID_CONTROLS_HTML_URL = Script.resolvePath('../html/gridControls.html'); + Grid = function(opts) { var that = {}; @@ -228,7 +230,7 @@ GridTool = function(opts) { var verticalGrid = opts.verticalGrid; var listeners = []; - var url = Script.resolvePath('html/gridControls.html'); + var url = GRID_CONTROLS_HTML_URL; var webView = new WebWindow('Grid', url, 200, 280, true); horizontalGrid.addListener(function(data) { diff --git a/examples/libraries/omniTool/modules/breakdanceOmniToolModule.js b/examples/libraries/omniTool/modules/breakdanceOmniToolModule.js index 36ee6b1fee..3764c5e381 100644 --- a/examples/libraries/omniTool/modules/breakdanceOmniToolModule.js +++ b/examples/libraries/omniTool/modules/breakdanceOmniToolModule.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("../toys/breakdanceCore.js"); +Script.include("../../../breakdanceCore.js"); OmniToolModules.Breakdance = function() { print("OmniToolModules.Breakdance..."); @@ -32,4 +32,4 @@ OmniToolModules.Breakdance.prototype.onUpdate = function(deltaTime) { breakdanceEnd(); } -OmniToolModuleType = "Breakdance"; \ No newline at end of file +OmniToolModuleType = "Breakdance"; diff --git a/examples/libraries/omniTool/modules/test.js b/examples/libraries/omniTool/modules/test.js index 9f7191b2d0..83472ee0f1 100644 --- a/examples/libraries/omniTool/modules/test.js +++ b/examples/libraries/omniTool/modules/test.js @@ -1,5 +1,5 @@ -Script.include("avatarRelativeOverlays.js"); +Script.include("../../avatarRelativeOverlays.js"); OmniToolModules.Test = function(omniTool, activeEntityId) { this.omniTool = omniTool; diff --git a/examples/libraries/walkApi.js b/examples/libraries/walkApi.js index 8935380150..3a51491cac 100644 --- a/examples/libraries/walkApi.js +++ b/examples/libraries/walkApi.js @@ -14,7 +14,7 @@ // // included here to ensure walkApi.js can be used as an API, separate from walk.js -Script.include("./libraries/walkConstants.js"); +Script.include("walkConstants.js"); Avatar = function() { // if Hydras are connected, the only way to enable use is to never set any arm joint rotation diff --git a/examples/libraries/walkSettings.js b/examples/libraries/walkSettings.js index 3e5ac53572..0378f305b5 100644 --- a/examples/libraries/walkSettings.js +++ b/examples/libraries/walkSettings.js @@ -13,6 +13,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +var WALK_SETTINGS_HTML_URL = Script.resolvePath('../html/walkSettings.html'); + WalkSettings = function() { var _visible = false; var _innerWidth = Window.innerWidth; @@ -69,7 +71,7 @@ WalkSettings = function() { // web window const PANEL_WIDTH = 200; const PANEL_HEIGHT = 180; - var _url = Script.resolvePath('html/walkSettings.html'); + var _url = WALK_SETTINGS_HTML_URL; var _webWindow = new WebWindow('Walk Settings', _url, PANEL_WIDTH, PANEL_HEIGHT, false); _webWindow.setVisible(false); _webWindow.eventBridge.webEventReceived.connect(function(data) { diff --git a/examples/magBalls.js b/examples/magBalls.js index c9b45164ab..bda6ccd9c3 100644 --- a/examples/magBalls.js +++ b/examples/magBalls.js @@ -7,11 +7,11 @@ // // FIXME Script paths have to be relative to the caller, in this case libraries/OmniTool.js -Script.include("../magBalls/constants.js"); -Script.include("../magBalls/graph.js"); -Script.include("../magBalls/edgeSpring.js"); -Script.include("../magBalls/magBalls.js"); -Script.include("avatarRelativeOverlays.js"); +Script.include("magBalls/constants.js"); +Script.include("magBalls/graph.js"); +Script.include("magBalls/edgeSpring.js"); +Script.include("magBalls/magBalls.js"); +Script.include("libraries/avatarRelativeOverlays.js"); OmniToolModuleType = "MagBallsController" @@ -34,7 +34,7 @@ MODE_INFO[BALL_EDIT_MODE_ADD] = { }, colors: [ COLORS.GREEN, COLORS.BLUE ], // FIXME use an http path or find a way to get the relative path to the file - url: Script.resolvePath('../html/magBalls/addMode.html'), + url: Script.resolvePath('html/magBalls/addMode.html'), }; MODE_INFO[BALL_EDIT_MODE_DELETE] = { @@ -45,7 +45,7 @@ MODE_INFO[BALL_EDIT_MODE_DELETE] = { }, colors: [ COLORS.RED, COLORS.BLUE ], // FIXME use an http path or find a way to get the relative path to the file - url: Script.resolvePath('../html/magBalls/deleteMode.html'), + url: Script.resolvePath('html/magBalls/deleteMode.html'), }; var UI_POSITION_MODE_LABEL = Vec3.multiply(0.5, diff --git a/examples/painting/closePaint.js b/examples/painting/closePaint.js index d9f70aab3c..563ed1dafb 100644 --- a/examples/painting/closePaint.js +++ b/examples/painting/closePaint.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/utils.js"); +Script.include("../libraries/utils.js"); var RIGHT_HAND = 1; diff --git a/examples/toybox/bubblewand/createWand.js b/examples/toybox/bubblewand/createWand.js index d62c2064cf..4f4bc39e2c 100644 --- a/examples/toybox/bubblewand/createWand.js +++ b/examples/toybox/bubblewand/createWand.js @@ -10,7 +10,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html /*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ -Script.include("../../utilities.js"); Script.include("../../libraries/utils.js"); var WAND_MODEL = 'http://hifi-public.s3.amazonaws.com/models/bubblewand/wand.fbx'; diff --git a/examples/toybox/bubblewand/wand.js b/examples/toybox/bubblewand/wand.js index c8ba51f51d..4bdc789612 100644 --- a/examples/toybox/bubblewand/wand.js +++ b/examples/toybox/bubblewand/wand.js @@ -14,7 +14,6 @@ (function () { - Script.include("../../utilities.js"); Script.include("../../libraries/utils.js"); var BUBBLE_MODEL = "http://hifi-public.s3.amazonaws.com/models/bubblewand/bubble.fbx"; diff --git a/examples/toybox/doll/doll.js b/examples/toybox/doll/doll.js index 8f8a8cd840..577f86cae2 100644 --- a/examples/toybox/doll/doll.js +++ b/examples/toybox/doll/doll.js @@ -13,7 +13,6 @@ /*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ (function() { - Script.include("../../utilities.js"); Script.include("../../libraries/utils.js"); var _this; // this is the "constructor" for the entity as a JS object we don't do much here diff --git a/examples/toybox/ping_pong_gun/createPingPongGun.js b/examples/toybox/ping_pong_gun/createPingPongGun.js index 9639f75320..705671e784 100644 --- a/examples/toybox/ping_pong_gun/createPingPongGun.js +++ b/examples/toybox/ping_pong_gun/createPingPongGun.js @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // /*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ -Script.include("../../utilities.js"); +Script.include("../../libraries/utils.js"); var scriptURL = Script.resolvePath('pingPongGun.js'); diff --git a/examples/toybox/ping_pong_gun/createTargets.js b/examples/toybox/ping_pong_gun/createTargets.js index fb286b1928..fde0d6f54a 100644 --- a/examples/toybox/ping_pong_gun/createTargets.js +++ b/examples/toybox/ping_pong_gun/createTargets.js @@ -10,7 +10,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // /*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ -Script.include("../../utilities.js"); + Script.include("../../libraries/utils.js"); var scriptURL = Script.resolvePath('wallTarget.js'); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 405815aa5b..0f62bf8cd5 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -902,14 +902,19 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac BatchLoader* loader = new BatchLoader(urls); auto evaluateScripts = [=](const QMap& data) { + auto parentURL = _parentURL; for (QUrl url : urls) { QString contents = data[url]; if (contents.isNull()) { qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__; } else { + // Set the parent url so that path resolution will be relative + // to this script's url during its initial evaluation + _parentURL = url.toString(); QScriptValue result = evaluate(contents, url.toString()); } } + _parentURL = parentURL; if (callback.isFunction()) { QScriptValue(callback).call();