Skip to content

Commit 3a3141d

Browse files
Make pc.SceneRegistry public (playcanvas#1949)
* rename internal reference for `pc.SceneRegistry` from `_sceneRegistry` to `scenes` * add jsdoc comments for pc.Application#scenes * remove jsdoc private tag for pc.Registry and pc.RegistryItem * add jsdoc for pc.RegistryItem properties * mark old scene functions as private and deprecated * add console warning (if debug build) in deprecated scene functions Co-authored-by: Will Eastcott <will@playcanvas.com>
1 parent e660369 commit 3a3141d

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

src/framework/application.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ Object.assign(pc, function () {
7777
* this.app.maxDeltaTime = 0.2;
7878
*/
7979

80+
/**
81+
* @name pc.Application#scenes
82+
* @type {pc.SceneRegistry}
83+
* @description The scene registry managed by the application.
84+
* @example
85+
* // Search the scene registry for a item with the name 'racetrack1'
86+
* var sceneItem = this.app.scenes.find('racetrack1');
87+
*
88+
* // Load the scene using the item's url
89+
* this.app.scenes.loadScene(sceneItem.url);
90+
*/
91+
8092
/**
8193
* @name pc.Application#assets
8294
* @type {pc.AssetRegistry}
@@ -302,7 +314,7 @@ Object.assign(pc, function () {
302314

303315
this.i18n = new pc.I18n(this);
304316

305-
this._sceneRegistry = new pc.SceneRegistry(this);
317+
this.scenes = new pc.SceneRegistry(this);
306318

307319
var self = this;
308320
this.defaultLayerWorld = new pc.Layer({
@@ -817,22 +829,28 @@ Object.assign(pc, function () {
817829
},
818830

819831
/**
832+
* @private
833+
* @deprecated
820834
* @function
821835
* @name pc.Application#getSceneUrl
822836
* @description Look up the URL of the scene hierarchy file via the name given to the scene in the editor. Use this to in {@link pc.Application#loadSceneHierarchy}.
823837
* @param {string} name - The name of the scene file given in the Editor.
824838
* @returns {string} The URL of the scene file.
825839
*/
826840
getSceneUrl: function (name) {
827-
var entry = this._sceneRegistry.find(name);
841+
// #ifdef DEBUG
842+
console.warn("DEPRECATED: pc.Application#getSceneUrl is deprecated. Use pc.Application#scenes and pc.SceneRegistry#find instead.");
843+
// #endif
844+
var entry = this.scenes.find(name);
828845
if (entry) {
829846
return entry.url;
830847
}
831848
return null;
832-
833849
},
834850

835851
/**
852+
* @private
853+
* @deprecated
836854
* @function
837855
* @name pc.Application#loadSceneHierarchy
838856
* @description Load a scene file, create and initialize the Entity hierarchy
@@ -850,10 +868,15 @@ Object.assign(pc, function () {
850868
* });
851869
*/
852870
loadSceneHierarchy: function (url, callback) {
853-
this._sceneRegistry.loadSceneHierarchy(url, callback);
871+
// #ifdef DEBUG
872+
console.warn("DEPRECATED: pc.Application#loadSceneHierarchy is deprecated. Use pc.Application#scenes and pc.SceneRegistry#loadSceneHierarchy instead.");
873+
// #endif
874+
this.scenes.loadSceneHierarchy(url, callback);
854875
},
855876

856877
/**
878+
* @private
879+
* @deprecated
857880
* @function
858881
* @name pc.Application#loadSceneSettings
859882
* @description Load a scene file and automatically apply the scene settings to the current scene.
@@ -869,10 +892,15 @@ Object.assign(pc, function () {
869892
* });
870893
*/
871894
loadSceneSettings: function (url, callback) {
872-
this._sceneRegistry.loadSceneSettings(url, callback);
895+
// #ifdef DEBUG
896+
console.warn("DEPRECATED: pc.Application#loadSceneSettings is deprecated. Use pc.Application#scenes and pc.SceneRegistry#loadSceneSettings instead.");
897+
// #endif
898+
this.scenes.loadSceneSettings(url, callback);
873899
},
874900

875901
/**
902+
* @private
903+
* @deprecated
876904
* @function
877905
* @name pc.Application#loadScene
878906
* @description Load a scene file.
@@ -889,7 +917,10 @@ Object.assign(pc, function () {
889917
* });
890918
*/
891919
loadScene: function (url, callback) {
892-
this._sceneRegistry.loadScene(url, callback);
920+
// #ifdef DEBUG
921+
console.warn("DEPRECATED: pc.Application#loadScene is deprecated. Use pc.Application#scenes and pc.SceneRegistry#loadScene instead.");
922+
// #endif
923+
this.scenes.loadScene(url, callback);
893924
},
894925

895926
_preloadScripts: function (sceneData, callback) {
@@ -1042,7 +1073,7 @@ Object.assign(pc, function () {
10421073
if (!scenes) return;
10431074

10441075
for (var i = 0; i < scenes.length; i++) {
1045-
this._sceneRegistry.add(scenes[i].name, scenes[i].url);
1076+
this.scenes.add(scenes[i].name, scenes[i].url);
10461077
}
10471078
},
10481079

@@ -1776,8 +1807,8 @@ Object.assign(pc, function () {
17761807
this.scripts.destroy();
17771808
this.scripts = null;
17781809

1779-
this._sceneRegistry.destroy();
1780-
this._sceneRegistry = null;
1810+
this.scenes.destroy();
1811+
this.scenes = null;
17811812

17821813
this.lightmapper.destroy();
17831814
this.lightmapper = null;

src/framework/scene-registry.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
Object.assign(pc, function () {
22

33
/**
4-
* @private
54
* @class
65
* @name pc.SceneRegistryItem
76
* @description Item to be stored in the {@link pc.SceneRegistry}.
87
* @param {string} name - The name of the scene.
98
* @param {string} url - The url of the scene file.
9+
* @property {string} name - The name of the scene.
10+
* @property {string} url - The url of the scene file.
1011
*/
1112
var SceneRegistryItem = function (name, url) {
1213
this.name = name;
1314
this.url = url;
1415
};
1516

1617
/**
17-
* @private
1818
* @class
1919
* @name pc.SceneRegistry
2020
* @description Container for storing the name and url for scene files.
@@ -32,7 +32,6 @@ Object.assign(pc, function () {
3232
};
3333

3434
/**
35-
* @private
3635
* @function
3736
* @name pc.SceneRegistry#list
3837
* @description Return the list of scene.
@@ -43,7 +42,6 @@ Object.assign(pc, function () {
4342
};
4443

4544
/**
46-
* @private
4745
* @function
4846
* @name pc.SceneRegistry#add
4947
* @description Add a new item to the scene registry.
@@ -69,7 +67,6 @@ Object.assign(pc, function () {
6967
};
7068

7169
/**
72-
* @private
7370
* @function
7471
* @name pc.SceneRegistry#find
7572
* @description Find a Scene by name and return the {@link pc.SceneRegistryItem}.
@@ -85,7 +82,6 @@ Object.assign(pc, function () {
8582
};
8683

8784
/**
88-
* @private
8985
* @function
9086
* @name pc.SceneRegistry#findByUrl
9187
* @description Find a scene by the URL and return the {@link pc.SceneRegistryItem}.
@@ -100,7 +96,6 @@ Object.assign(pc, function () {
10096
};
10197

10298
/**
103-
* @private
10499
* @function
105100
* @name pc.SceneRegistry#remove
106101
* @description Remove an item from the scene registry.
@@ -129,7 +124,6 @@ Object.assign(pc, function () {
129124

130125

131126
/**
132-
* @private
133127
* @function
134128
* @name pc.SceneRegistry#loadSceneHierarchy
135129
* @description Load a scene file, create and initialize the Entity hierarchy
@@ -190,7 +184,6 @@ Object.assign(pc, function () {
190184
};
191185

192186
/**
193-
* @private
194187
* @function
195188
* @name pc.SceneRegistry#loadSceneSettings
196189
* @description Load a scene file and apply the scene settings to the current scene.
@@ -231,7 +224,6 @@ Object.assign(pc, function () {
231224
};
232225

233226
/**
234-
* @private
235227
* @function
236228
* @name pc.SceneRegistry#loadScene
237229
* @description Load the scene hierarchy and scene settings. This is an internal method used by the pc.Application.

0 commit comments

Comments
 (0)