11var Class = require ( '../utils/Class' ) ;
2- var GetFastValue = require ( '../utils/object/GetFastValue' ) ;
32var CONST = require ( './const' ) ;
3+ var GetFastValue = require ( '../utils/object/GetFastValue' ) ;
44var GetURL = require ( './GetURL' ) ;
55var MergeXHRSettings = require ( './MergeXHRSettings' ) ;
66var XHRLoader = require ( './XHRLoader' ) ;
77var XHRSettings = require ( './XHRSettings' ) ;
88
9- // Phaser.Loader.File
10-
119var File = new Class ( {
1210
1311 initialize :
1412
1513 // old signature: type, key, url, responseType, xhrSettings, config
14+ /**
15+ * [description]
16+ *
17+ * @class File
18+ * @memberOf Phaser.Loader
19+ * @constructor
20+ * @since 3.0.0
21+ *
22+ * @param {object } fileConfig - [description]
23+ */
1624 function File ( fileConfig )
1725 {
18- // file type (image, json, etc) for sorting within the Loader
26+ /**
27+ * The file type (image, json, etc) for sorting within the Loader.
28+ *
29+ * @property {string } type
30+ * @since 3.0.0
31+ */
1932 this . type = GetFastValue ( fileConfig , 'type' , false ) ;
2033
21- // unique cache key (unique within its file type)
34+ /**
35+ * Unique cache key (unique within its file type)
36+ *
37+ * @property {string } key
38+ * @since 3.0.0
39+ */
2240 this . key = GetFastValue ( fileConfig , 'key' , false ) ;
2341
2442 if ( ! this . type || ! this . key )
2543 {
2644 throw new Error ( 'Error calling \'Loader.' + this . type + '\' invalid key provided.' ) ;
2745 }
2846
29- // The URL of the file, not including baseURL
47+ /**
48+ * The URL of the file, not including baseURL.
49+ *
50+ * @property {string } url
51+ * @since 3.0.0
52+ */
3053 this . url = GetFastValue ( fileConfig , 'url' ) ;
3154
3255 if ( this . url === undefined )
@@ -38,52 +61,146 @@ var File = new Class({
3861 this . url = GetFastValue ( fileConfig , 'path' , '' ) . concat ( this . url ) ;
3962 }
4063
41- // Set when the Loader calls 'load' on this file
64+ /**
65+ * Set when the Loader calls 'load' on this file.
66+ *
67+ * @property {string } src
68+ * @default ''
69+ * @since 3.0.0
70+ */
4271 this . src = '' ;
4372
73+ /**
74+ * [description]
75+ *
76+ * @property {object } xhrSettings
77+ * @since 3.0.0
78+ */
4479 this . xhrSettings = XHRSettings ( GetFastValue ( fileConfig , 'responseType' , undefined ) ) ;
4580
4681 if ( GetFastValue ( fileConfig , 'xhrSettings' , false ) )
4782 {
4883 this . xhrSettings = MergeXHRSettings ( this . xhrSettings , GetFastValue ( fileConfig , 'xhrSettings' , { } ) ) ;
4984 }
5085
51- // The LoaderPlugin instance that is loading this file
86+ /**
87+ * The LoaderPlugin instance that is loading this file.
88+ *
89+ * @property {Phaser.Loader.LoaderPlugin } loader
90+ * @default null
91+ * @since 3.0.0
92+ */
5293 this . loader = null ;
5394
95+ /**
96+ * [description]
97+ *
98+ * @property {Phaser.Loader.XHRLoader } xhrLoader
99+ * @default null
100+ * @since 3.0.0
101+ */
54102 this . xhrLoader = null ;
55103
104+ /**
105+ * [description]
106+ *
107+ * @property {integer } state
108+ * @since 3.0.0
109+ */
56110 this . state = CONST . FILE_PENDING ;
57111
58- // Set by onProgress (only if loading via XHR)
112+ /**
113+ * Set by onProgress (only if loading via XHR)
114+ *
115+ * @property {number } bytesTotal
116+ * @default 0
117+ * @since 3.0.0
118+ */
59119 this . bytesTotal = 0 ;
120+
121+ /**
122+ * [description]
123+ *
124+ * @property {number } bytesLoaded
125+ * @default -1
126+ * @since 3.0.0
127+ */
60128 this . bytesLoaded = - 1 ;
129+
130+ /**
131+ * [description]
132+ *
133+ * @property {float } percentComplete
134+ * @default -1
135+ * @since 3.0.0
136+ */
61137 this . percentComplete = - 1 ;
62138
63- // For CORs based loading.
64- // If this is undefined then the File will check BaseLoader.crossOrigin and use that (if set)
139+ /**
140+ * For CORs based loading.
141+ * If this is undefined then the File will check BaseLoader.crossOrigin and use that (if set)
142+ *
143+ * @property {string|undefined } crossOrigin
144+ * @since 3.0.0
145+ */
65146 this . crossOrigin = undefined ;
66147
67- // The actual processed file data
148+ /**
149+ * The processed file data, stored in here after the file has loaded.
150+ *
151+ * @property {any } data
152+ * @since 3.0.0
153+ */
68154 this . data = undefined ;
69155
70- // A config object that can be used by file types to store transitional data
156+ /**
157+ * A config object that can be used by file types to store transitional data.
158+ *
159+ * @property {[type] } config
160+ * @since 3.0.0
161+ */
71162 this . config = GetFastValue ( fileConfig , 'config' , { } ) ;
72163
73- // Multipart file? (i.e. an atlas and its json together)
164+ /**
165+ * Multipart file? i.e. an atlas and its json together.
166+ *
167+ * @property {?Phaser.Loader.File } linkFile
168+ * @since 3.0.0
169+ */
74170 this . linkFile = undefined ;
171+
172+ /**
173+ * [description]
174+ *
175+ * @property {string } linkType
176+ * @default ''
177+ * @since 3.0.0
178+ */
75179 this . linkType = '' ;
76180 } ,
77181
182+ /**
183+ * [description]
184+ *
185+ * @method Phaser.Loader.File#resetXHR
186+ * @since 3.0.0
187+ */
78188 resetXHR : function ( )
79189 {
80190 this . xhrLoader . onload = undefined ;
81191 this . xhrLoader . onerror = undefined ;
82192 this . xhrLoader . onprogress = undefined ;
83193 } ,
84194
85- // Called by the Loader, starts the actual file downloading.
86- // During the load the methods onLoad, onProgress, etc are called based on the XHR events.
195+ /**
196+ * Called by the Loader, starts the actual file downloading.
197+ * During the load the methods onLoad, onProgress, etc are called based on the XHR events.
198+ *
199+ * @method Phaser.Loader.File#load
200+ * @since 3.0.0
201+ *
202+ * @param {Phaser.Loader.LoaderPlugin } loader - [description]
203+ */
87204 load : function ( loader )
88205 {
89206 this . loader = loader ;
@@ -109,7 +226,14 @@ var File = new Class({
109226 }
110227 } ,
111228
112- // Called when the file loads, is sent a DOM ProgressEvent
229+ /**
230+ * Called when the file finishes loading, is sent a DOM ProgressEvent
231+ *
232+ * @method Phaser.Loader.File#onLoad
233+ * @since 3.0.0
234+ *
235+ * @param {ProgressEvent } event - [description]
236+ */
113237 onLoad : function ( event )
114238 {
115239 this . resetXHR ( ) ;
@@ -124,14 +248,30 @@ var File = new Class({
124248 }
125249 } ,
126250
127- // Called when the file errors, is sent a DOM ProgressEvent
251+ //
252+ /**
253+ * Called if the file errors while loading, is sent a DOM ProgressEvent
254+ *
255+ * @method Phaser.Loader.File#onError
256+ * @since 3.0.0
257+ *
258+ * @param {ProgressEvent } event - [description]
259+ */
128260 onError : function ( event )
129261 {
130262 this . resetXHR ( ) ;
131263
132264 this . loader . nextFile ( this , false ) ;
133265 } ,
134266
267+ /**
268+ * [description]
269+ *
270+ * @method Phaser.Loader.File#onProgress
271+ * @since 3.0.0
272+ *
273+ * @param {[type] } event - [description]
274+ */
135275 onProgress : function ( event )
136276 {
137277 if ( event . lengthComputable )
@@ -146,8 +286,15 @@ var File = new Class({
146286 }
147287 } ,
148288
149- // Usually overriden by the FileTypes and is called by Loader.finishedLoading.
150- // The callback is Loader.processUpdate
289+ /**
290+ * Usually overriden by the FileTypes and is called by Loader.finishedLoading.
291+ * The callback is Loader.processUpdate
292+ *
293+ * @method Phaser.Loader.File#onProcess
294+ * @since 3.0.0
295+ *
296+ * @param {[type] } callback - [description]
297+ */
151298 onProcess : function ( callback )
152299 {
153300 this . state = CONST . FILE_PROCESSING ;
@@ -157,6 +304,12 @@ var File = new Class({
157304 callback ( this ) ;
158305 } ,
159306
307+ /**
308+ * [description]
309+ *
310+ * @method Phaser.Loader.File#onComplete
311+ * @since 3.0.0
312+ */
160313 onComplete : function ( )
161314 {
162315 if ( this . linkFile )
0 commit comments