Skip to content

Commit faef344

Browse files
committed
Added jsdocs
1 parent 0415dfb commit faef344

4 files changed

Lines changed: 94 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ The Loader has been given an overhaul to improve its performance and extensibili
8787
* The Graphics Creator would automatically add the Graphics to the display list by mistake. The default should be to remain hidden. Fix #3637 (thanks @mikuso)
8888
* BitmapText, both static and dynamic, can now take any data-type, including numbers, for the `text` argument in the constructor. Before they only worked via `setText` (thanks @Jelaw21)
8989
* The Forward Diffuse Light Pipeline was hard coded to assume the normal map would be stored in the source index zero. It now correctly obtains the normal map from the frame source index, which means all Game Objects that used frames from multi-atlas textures will now work with lights properly.
90+
* The Tiled Base64Decode function worked off the wrong array length, causing extra undefined values at the end (thanks @tamagokun)
9091

9192
### Examples, Documentation and TypeScript
9293

src/loader/File.js

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ var MergeXHRSettings = require('./MergeXHRSettings');
1212
var XHRLoader = require('./XHRLoader');
1313
var XHRSettings = require('./XHRSettings');
1414

15-
/**
16-
* @callback FileProcessCallback
17-
*
18-
* @param {Phaser.Loader.File} file - [description]
19-
*/
20-
2115
/**
2216
* @typedef {object} FileConfig
2317
*
@@ -33,15 +27,16 @@ var XHRSettings = require('./XHRSettings');
3327

3428
/**
3529
* @classdesc
36-
* [description]
30+
* The base File class used by all File Types that the Loader can support.
31+
* You shouldn't create an instance of a File directly, but should extend it with your own class, setting a custom type and processing methods.
3732
*
3833
* @class File
3934
* @memberOf Phaser.Loader
4035
* @constructor
4136
* @since 3.0.0
4237
*
4338
* @param {Phaser.Loader.LoaderPlugin} loader - The Loader that is going to load this File.
44-
* @param {FileConfig} fileConfig - [description]
39+
* @param {FileConfig} fileConfig - The file configuration object, as created by the file type.
4540
*/
4641
var File = new Class({
4742

@@ -99,6 +94,7 @@ var File = new Class({
9994

10095
/**
10196
* The URL of the file, not including baseURL.
97+
* Automatically has Loader.path prepended to it.
10298
*
10399
* @name Phaser.Loader.File#url
104100
* @type {string}
@@ -116,7 +112,8 @@ var File = new Class({
116112
}
117113

118114
/**
119-
* Set when the Loader calls 'load' on this file.
115+
* The final URL this file will load from, including baseURL and path.
116+
* Set automatically when the Loader calls 'load' on this file.
120117
*
121118
* @name Phaser.Loader.File#src
122119
* @type {string}
@@ -200,7 +197,7 @@ var File = new Class({
200197
this.crossOrigin = undefined;
201198

202199
/**
203-
* The processed file data, stored in here after the file has loaded.
200+
* The processed file data, stored here after the file has loaded.
204201
*
205202
* @name Phaser.Loader.File#data
206203
* @type {*}
@@ -212,14 +209,14 @@ var File = new Class({
212209
* A config object that can be used by file types to store transitional data.
213210
*
214211
* @name Phaser.Loader.File#config
215-
* @type {object}
212+
* @type {*}
216213
* @since 3.0.0
217214
*/
218215
this.config = GetFastValue(fileConfig, 'config', {});
219216

220217
/**
221218
* If this is a multipart file, i.e. an atlas and its json together, then this is a reference
222-
* to the linked file. Set and used internally by the Loader.
219+
* to the parent MultiFile. Set and used internally by the Loader or specific file types.
223220
*
224221
* @name Phaser.Loader.File#multiFile
225222
* @type {?Phaser.Loader.MultiFile}
@@ -239,6 +236,14 @@ var File = new Class({
239236
this.linkFile;
240237
},
241238

239+
/**
240+
* Links this File with another, so they depend upon each other for loading and processing.
241+
*
242+
* @method Phaser.Loader.File#setLink
243+
* @since 3.7.0
244+
*
245+
* @param {Phaser.Loader.File} fileB - The file to link to this one.
246+
*/
242247
setLink: function (fileB)
243248
{
244249
this.linkFile = fileB;
@@ -247,7 +252,7 @@ var File = new Class({
247252
},
248253

249254
/**
250-
* Resets the XHRLoader instance.
255+
* Resets the XHRLoader instance this file is using.
251256
*
252257
* @method Phaser.Loader.File#resetXHR
253258
* @since 3.0.0
@@ -264,7 +269,8 @@ var File = new Class({
264269

265270
/**
266271
* Called by the Loader, starts the actual file downloading.
267-
* During the load the methods onLoad, onProgress, etc are called based on the XHR events.
272+
* During the load the methods onLoad, onError and onProgress are called, based on the XHR events.
273+
* You shouldn't normally call this method directly, it's meant to be invoked by the Loader.
268274
*
269275
* @method Phaser.Loader.File#load
270276
* @since 3.0.0
@@ -289,9 +295,9 @@ var File = new Class({
289295
// The creation of this XHRLoader starts the load process going.
290296
// It will automatically call the following, based on the load outcome:
291297
//
292-
// xhr.onload = file.onLoad.bind(file);
293-
// xhr.onerror = file.onError.bind(file);
294-
// xhr.onprogress = file.onProgress.bind(file);
298+
// xhr.onload = this.onLoad
299+
// xhr.onerror = this.onError
300+
// xhr.onprogress = this.onProgress
295301

296302
this.xhrLoader = XHRLoader(this, this.loader.xhr);
297303
}
@@ -352,7 +358,8 @@ var File = new Class({
352358
},
353359

354360
/**
355-
* Usually overridden by the FileTypes and is called by Loader.finishedLoading.
361+
* Usually overridden by the FileTypes and is called by Loader.nextFile.
362+
* This method controls what extra work this File does with its loaded data, for example a JSON file will parse itself during this stage.
356363
*
357364
* @method Phaser.Loader.File#onProcess
358365
* @since 3.0.0
@@ -365,7 +372,7 @@ var File = new Class({
365372
},
366373

367374
/**
368-
* Called when the File has completed loading.
375+
* Called when the File has completed processing.
369376
* Checks on the state of its multifile, if set.
370377
*
371378
* @method Phaser.Loader.File#onProcessComplete
@@ -384,7 +391,7 @@ var File = new Class({
384391
},
385392

386393
/**
387-
* Called when the File has completed loading.
394+
* Called when the File has completed processing but it generated an error.
388395
* Checks on the state of its multifile, if set.
389396
*
390397
* @method Phaser.Loader.File#onProcessError
@@ -419,7 +426,6 @@ var File = new Class({
419426

420427
/**
421428
* Adds this file to its target cache upon successful loading and processing.
422-
* It will emit a `filecomplete` event from the LoaderPlugin.
423429
* This method is often overridden by specific file types.
424430
*
425431
* @method Phaser.Loader.File#addToCache
@@ -435,12 +441,20 @@ var File = new Class({
435441
this.pendingDestroy();
436442
},
437443

444+
/**
445+
* @event Phaser.Loader.File#fileCompleteEvent
446+
* @param {string} key - The key of the file that just loaded and finished processing.
447+
* @param {string} type - The type of the file that just loaded and finished processing.
448+
* @param {any} data - The data of the file.
449+
*/
450+
438451
/**
439452
* Adds this file to its target cache upon successful loading and processing.
440453
* It will emit a `filecomplete` event from the LoaderPlugin.
441454
* This method is often overridden by specific file types.
442455
*
443456
* @method Phaser.Loader.File#pendingDestroy
457+
* @fires Phaser.Loader.File#fileCompleteEvent
444458
* @since 3.7.0
445459
*/
446460
pendingDestroy: function (data)

src/loader/FileTypesManager.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ var types = {};
88

99
var FileTypesManager = {
1010

11+
/**
12+
* Static method called when a LoaderPlugin is created.
13+
*
14+
* Loops through the local types object and injects all of them as
15+
* properties into the LoaderPlugin instance.
16+
*
17+
* @method Phaser.Loader.FileTypesManager.register
18+
* @since 3.0.0
19+
*
20+
* @param {Phaser.Loader.LoaderPlugin} loader - The LoaderPlugin to install the types into.
21+
*/
1122
install: function (loader)
1223
{
1324
for (var key in types)
@@ -16,13 +27,28 @@ var FileTypesManager = {
1627
}
1728
},
1829

30+
/**
31+
* Static method called directly by the File Types.
32+
*
33+
* The key is a reference to the function used to load the files via the Loader, i.e. `image`.
34+
*
35+
* @method Phaser.Loader.FileTypesManager.register
36+
* @since 3.0.0
37+
*
38+
* @param {string} key - The key that will be used as the method name in the LoaderPlugin.
39+
* @param {function} factoryFunction - The function that will be called when LoaderPlugin.key is invoked.
40+
*/
1941
register: function (key, factoryFunction)
2042
{
2143
types[key] = factoryFunction;
22-
23-
// console.log('FileTypesManager.register', key);
2444
},
2545

46+
/**
47+
* Removed all associated file types.
48+
*
49+
* @method Phaser.Loader.FileTypesManager.destroy
50+
* @since 3.0.0
51+
*/
2652
destroy: function ()
2753
{
2854
types = {};

src/loader/MultiFile.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ var Class = require('../utils/Class');
88

99
/**
1010
* @classdesc
11-
* [description]
11+
* A MultiFile is a special kind of parent that contains two, or more, Files as children and looks after
12+
* the loading and processing of them all. It is commonly extended and used as a base class for file types such as AtlasJSON or BitmapFont.
13+
*
14+
* You shouldn't create an instance of a MultiFile directly, but should extend it with your own class, setting a custom type and processing methods.
1215
*
1316
* @class MultiFile
1417
* @memberOf Phaser.Loader
@@ -67,6 +70,7 @@ var MultiFile = new Class({
6770
*
6871
* @name Phaser.Loader.MultiFile#complete
6972
* @type {boolean}
73+
* @default false
7074
* @since 3.7.0
7175
*/
7276
this.complete = false;
@@ -91,6 +95,13 @@ var MultiFile = new Class({
9195
*/
9296
this.failed = 0;
9397

98+
/**
99+
* A storage container for transient data that the loading files need.
100+
*
101+
* @name Phaser.Loader.MultiFile#config
102+
* @type {any}
103+
* @since 3.7.0
104+
*/
94105
this.config = {};
95106

96107
// Link the files
@@ -100,11 +111,29 @@ var MultiFile = new Class({
100111
}
101112
},
102113

114+
/**
115+
* Checks if this MultiFile is ready to process its children or not.
116+
*
117+
* @method Phaser.Loader.MultiFile#isReadyToProcess
118+
* @since 3.7.0
119+
*
120+
* @return {boolean} `true` if all children of this MultiFile have loaded, otherwise `false`.
121+
*/
103122
isReadyToProcess: function ()
104123
{
105124
return (this.pending === 0 && this.failed === 0 && !this.complete);
106125
},
107126

127+
/**
128+
* Adds another child to this MultiFile, increases the pending count and resets the completion status.
129+
*
130+
* @method Phaser.Loader.MultiFile#addToMultiFile
131+
* @since 3.7.0
132+
*
133+
* @param {Phaser.Loader.File} files - The File to add to this MultiFile.
134+
*
135+
* @return {Phaser.Loader.MultiFile} This MultiFile instance.
136+
*/
108137
addToMultiFile: function (file)
109138
{
110139
this.files.push(file);

0 commit comments

Comments
 (0)