Skip to content

Commit 5f40445

Browse files
yaustarSteven Yauwilleastcott
authored
[DOCS] Updated tests and docs for sceneRegistry loadScene* functions (playcanvas#2009)
* Removed app.loadScene* callbacks from docs * Updated code sample in documentation getSceneUrl * Removed loadScene from public API * Added callbacks for the SceneRegistry load* functions * Updated tests to use SceneRegistry instead of deprecated app function * Update test to use pc.SceneRegistry * Load Scene is public again, removed unused callbacks * Removed callbacks.loadScene from private API * Better param docs for callbacks. * Remove new line * Fix callback types Co-authored-by: Steven Yau <syau@snaphcat.com> Co-authored-by: Will Eastcott <will@playcanvas.com>
1 parent 7d0c773 commit 5f40445

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/callbacks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@
5252

5353
/**
5454
* @callback pc.callbacks.LoadHierarchy
55-
* @description Callback used by {@link pc.Application#loadSceneHierarchy}.
55+
* @description Callback used by {@link pc.SceneRegistry#loadSceneHierarchy}.
5656
* @param {string|null} err - The error message in the case where the loading or parsing fails.
5757
* @param {pc.Entity} [entity] - The loaded root entity if no errors were encountered.
5858
*/
5959

6060
/**
6161
* @callback pc.callbacks.LoadSettings
62-
* @description Callback used by {@link pc.Application#loadSceneSettings}.
62+
* @description Callback used by {@link pc.SceneRegistry#loadSceneSettings}.
6363
* @param {string|null} err - The error message in the case where the loading or parsing fails.
6464
*/
6565

6666
/**
6767
* @callback pc.callbacks.LoadScene
68-
* @description Callback used by {@link pc.Application#loadScene}.
68+
* @description Callback used by {@link pc.SceneRegistry#loadScene}.
6969
* @param {string|null} err - The error message in the case where the loading or parsing fails.
7070
* @param {pc.Entity} [entity] - The loaded root entity if no errors were encountered.
7171
*/

src/framework/scene-registry.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ Object.assign(pc, function () {
129129
* @description Load a scene file, create and initialize the Entity hierarchy
130130
* and add the hierarchy to the application root Entity.
131131
* @param {string} url - The URL of the scene file. Usually this will be "scene_id.json".
132-
* @param {Function} callback - The function to call after loading, passed (err, entity) where err is null if no errors occurred.
132+
* @param {pc.callbacks.LoadHierarchy} callback - The function to call after loading,
133+
* passed (err, entity) where err is null if no errors occurred.
133134
* @example
134135
*
135-
* var url = app.getSceneUrl("Scene Name");
136-
* app.loadSceneHierarchy(url, function (err, entity) {
136+
* var url = app.scenes.getSceneUrl("Scene Name");
137+
* app.scenes.loadSceneHierarchy(url, function (err, entity) {
137138
* if (!err) {
138139
* var e = app.root.find("My New Entity");
139140
* } else {
@@ -188,7 +189,8 @@ Object.assign(pc, function () {
188189
* @name pc.SceneRegistry#loadSceneSettings
189190
* @description Load a scene file and apply the scene settings to the current scene.
190191
* @param {string} url - The URL of the scene file. This can be looked up using app.getSceneUrl.
191-
* @param {Function} callback - The function called after the settings are applied. Passed (err) where err is null if no error occurred.
192+
* @param {pc.callbacks.LoadSettings} callback - The function called after the settings
193+
* are applied. Passed (err) where err is null if no error occurred.
192194
* @example
193195
*
194196
* var url = app.getSceneUrl("Scene Name");
@@ -226,9 +228,12 @@ Object.assign(pc, function () {
226228
/**
227229
* @function
228230
* @name pc.SceneRegistry#loadScene
229-
* @description Load the scene hierarchy and scene settings. This is an internal method used by the pc.Application.
230-
* @param {string} url - The URL of the scene file.
231-
* @param {Function} callback - The function called after the settings are applied. Passed (err, scene) where err is null if no error occurred and scene is the pc.Scene.
231+
* @description Load the scene hierarchy and scene settings. This is an internal method used
232+
* by the pc.Application.
233+
* @param {string} url - The URL of the scene file.
234+
* @param {pc.callbacks.LoadScene} callback - The function called after the settings are
235+
* applied. Passed (err, scene) where err is null if no error occurred and scene is the
236+
* {@link pc.Scene}.
232237
*/
233238
SceneRegistry.prototype.loadScene = function (url, callback) {
234239
var self = this;

tests/framework/components/script/test_script_component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ describe("pc.ScriptComponent", function () {
275275
console.error(err);
276276
}
277277

278-
app.loadScene('base/tests/framework/components/script/scene1.json', function () {
278+
app.scenes.loadScene('base/tests/framework/components/script/scene1.json', function () {
279279
app.start();
280280
done();
281281
});
@@ -1878,7 +1878,7 @@ describe("pc.ScriptComponent", function () {
18781878
app.root.children[0].destroy();
18791879

18801880
window.initializeCalls.length = 0;
1881-
app.loadScene('base/tests/framework/components/script/scene2.json', function () {
1881+
app.scenes.loadScene('base/tests/framework/components/script/scene2.json', function () {
18821882
var e = app.root.findByName('A');
18831883
var other = app.root.findByName('B');
18841884

0 commit comments

Comments
 (0)