@@ -302,6 +302,7 @@ Phaser.Loader.prototype = {
302302 * @param {string } key - Unique asset key of this image file.
303303 * @param {string } url - URL of image file.
304304 * @param {boolean } [overwrite=false] - If an unloaded file with a matching key already exists in the queue, this entry will overwrite it.
305+ * @return {Phaser.Loader } This Loader instance.
305306 */
306307 image : function ( key , url , overwrite ) {
307308
@@ -327,6 +328,7 @@ Phaser.Loader.prototype = {
327328 * @param {string } key - Unique asset key of the text file.
328329 * @param {string } url - URL of the text file.
329330 * @param {boolean } [overwrite=false] - If an unloaded file with a matching key already exists in the queue, this entry will overwrite it.
331+ * @return {Phaser.Loader } This Loader instance.
330332 */
331333 text : function ( key , url , overwrite ) {
332334
@@ -351,6 +353,7 @@ Phaser.Loader.prototype = {
351353 * @method Phaser.Loader#script
352354 * @param {string } key - Unique asset key of the script file.
353355 * @param {string } url - URL of the JavaScript file.
356+ * @return {Phaser.Loader } This Loader instance.
354357 */
355358 script : function ( key , url ) {
356359
@@ -369,6 +372,7 @@ Phaser.Loader.prototype = {
369372 * @param {number } frameWidth - Width of each single frame.
370373 * @param {number } frameHeight - Height of each single frame.
371374 * @param {number } [frameMax=-1] - How many frames in this sprite sheet. If not specified it will divide the whole image into frames.
375+ * @return {Phaser.Loader } This Loader instance.
372376 */
373377 spritesheet : function ( key , url , frameWidth , frameHeight , frameMax ) {
374378
@@ -391,6 +395,7 @@ Phaser.Loader.prototype = {
391395 * @param {number } [tileMax=-1] - How many tiles in this tileset. If not specified it will divide the whole image into tiles.
392396 * @param {number } [tileMargin=0] - If the tiles have been drawn with a margin, specify the amount here.
393397 * @param {number } [tileSpacing=0] - If the tiles have been drawn with spacing between them, specify the amount here.
398+ * @return {Phaser.Loader } This Loader instance.
394399 */
395400 tileset : function ( key , url , tileWidth , tileHeight , tileMax , tileMargin , tileSpacing ) {
396401
@@ -411,6 +416,7 @@ Phaser.Loader.prototype = {
411416 * @param {string } key - Unique asset key of the audio file.
412417 * @param {Array|string } urls - An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ] or a single string containing just one URL.
413418 * @param {boolean } autoDecode - When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process.
419+ * @return {Phaser.Loader } This Loader instance.
414420 */
415421 audio : function ( key , urls , autoDecode ) {
416422
@@ -427,10 +433,10 @@ Phaser.Loader.prototype = {
427433 *
428434 * @method Phaser.Loader#tilemap
429435 * @param {string } key - Unique asset key of the tilemap data.
430- * @param {string } tilesetURL - The url of the tile set image file.
431436 * @param {string } [mapDataURL] - The url of the map data file (csv/json)
432- * @param {object } [mapData] - An optional JSON data object (can be given in place of a URL).
433- * @param {string } [format] - The format of the map data.
437+ * @param {object } [mapData] - An optional JSON data object. If given then the mapDataURL is ignored and this JSON object is used for map data instead.
438+ * @param {string } [format=Phaser.Tilemap.CSV] - The format of the map data. Either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON.
439+ * @return {Phaser.Loader } This Loader instance.
434440 */
435441 tilemap : function ( key , mapDataURL , mapData , format ) {
436442
@@ -445,12 +451,8 @@ Phaser.Loader.prototype = {
445451 return this ;
446452 }
447453
448- // A URL to a json/csv file has been given
449- if ( mapDataURL )
450- {
451- this . addToFileList ( 'tilemap' , key , mapDataURL , { format : format } ) ;
452- }
453- else
454+ // A map data object has been given
455+ if ( mapData )
454456 {
455457 switch ( format )
456458 {
@@ -470,6 +472,10 @@ Phaser.Loader.prototype = {
470472
471473 this . game . cache . addTilemap ( key , null , mapData , format ) ;
472474 }
475+ else
476+ {
477+ this . addToFileList ( 'tilemap' , key , mapDataURL , { format : format } ) ;
478+ }
473479
474480 return this ;
475481
@@ -483,6 +489,7 @@ Phaser.Loader.prototype = {
483489 * @param {string } textureURL - The url of the font image file.
484490 * @param {string } [xmlURL] - The url of the font data file (xml/fnt)
485491 * @param {object } [xmlData] - An optional XML data object.
492+ * @return {Phaser.Loader } This Loader instance.
486493 */
487494 bitmapFont : function ( key , textureURL , xmlURL , xmlData ) {
488495
@@ -542,6 +549,7 @@ Phaser.Loader.prototype = {
542549 * @param {string } textureURL - The url of the texture atlas image file.
543550 * @param {string } [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
544551 * @param {object } [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
552+ * @return {Phaser.Loader } This Loader instance.
545553 */
546554 atlasJSONArray : function ( key , textureURL , atlasURL , atlasData ) {
547555
@@ -557,6 +565,7 @@ Phaser.Loader.prototype = {
557565 * @param {string } textureURL - The url of the texture atlas image file.
558566 * @param {string } [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
559567 * @param {object } [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
568+ * @return {Phaser.Loader } This Loader instance.
560569 */
561570 atlasJSONHash : function ( key , textureURL , atlasURL , atlasData ) {
562571
@@ -572,6 +581,7 @@ Phaser.Loader.prototype = {
572581 * @param {string } textureURL - The url of the texture atlas image file.
573582 * @param {string } [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
574583 * @param {object } [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
584+ * @return {Phaser.Loader } This Loader instance.
575585 */
576586 atlasXML : function ( key , textureURL , atlasURL , atlasData ) {
577587
@@ -588,6 +598,7 @@ Phaser.Loader.prototype = {
588598 * @param {string } [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
589599 * @param {object } [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
590600 * @param {number } [format] - A value describing the format of the data, the default is Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY.
601+ * @return {Phaser.Loader } This Loader instance.
591602 */
592603 atlas : function ( key , textureURL , atlasURL , atlasData , format ) {
593604
@@ -728,6 +739,12 @@ Phaser.Loader.prototype = {
728739 */
729740 loadFile : function ( ) {
730741
742+ if ( ! this . _fileList [ this . _fileIndex ] )
743+ {
744+ console . warn ( 'Phaser.Loader loadFile invalid index ' + this . _fileIndex ) ;
745+ return ;
746+ }
747+
731748 var file = this . _fileList [ this . _fileIndex ] ;
732749 var _this = this ;
733750
@@ -805,13 +822,13 @@ Phaser.Loader.prototype = {
805822 this . _xhr . open ( "GET" , this . baseURL + file . url , true ) ;
806823 this . _xhr . responseType = "text" ;
807824
808- if ( file . format == Phaser . Tilemap . TILED_JSON )
825+ if ( file . format === Phaser . Tilemap . TILED_JSON )
809826 {
810827 this . _xhr . onload = function ( ) {
811828 return _this . jsonLoadComplete ( _this . _fileIndex ) ;
812829 } ;
813830 }
814- else if ( file . format == Phaser . Tilemap . CSV )
831+ else if ( file . format === Phaser . Tilemap . CSV )
815832 {
816833 this . _xhr . onload = function ( ) {
817834 return _this . csvLoadComplete ( _this . _fileIndex ) ;
@@ -1061,10 +1078,18 @@ Phaser.Loader.prototype = {
10611078 */
10621079 jsonLoadComplete : function ( index ) {
10631080
1064- var data = JSON . parse ( this . _xhr . responseText ) ;
1081+ if ( ! this . _fileList [ index ] )
1082+ {
1083+ console . warn ( 'Phaser.Loader jsonLoadComplete invalid index ' + index ) ;
1084+ return ;
1085+ }
1086+
10651087 var file = this . _fileList [ index ] ;
1088+ var data = JSON . parse ( this . _xhr . responseText ) ;
1089+
1090+ file . loaded = true ;
10661091
1067- if ( file . type == 'tilemap' )
1092+ if ( file . type === 'tilemap' )
10681093 {
10691094 this . game . cache . addTilemap ( file . key , file . url , data , file . format ) ;
10701095 }
@@ -1085,8 +1110,16 @@ Phaser.Loader.prototype = {
10851110 */
10861111 csvLoadComplete : function ( index ) {
10871112
1088- var data = this . _xhr . responseText ;
1113+ if ( ! this . _fileList [ index ] )
1114+ {
1115+ console . warn ( 'Phaser.Loader csvLoadComplete invalid index ' + index ) ;
1116+ return ;
1117+ }
1118+
10891119 var file = this . _fileList [ index ] ;
1120+ var data = this . _xhr . responseText ;
1121+
1122+ file . loaded = true ;
10901123
10911124 this . game . cache . addTilemap ( file . key , file . url , data , file . format ) ;
10921125
@@ -1104,6 +1137,7 @@ Phaser.Loader.prototype = {
11041137
11051138 var file = this . _fileList [ index ] ;
11061139
1140+ file . loaded = true ;
11071141 file . error = true ;
11081142
11091143 console . warn ( "Phaser.Loader dataLoadError: " + file . key ) ;
@@ -1148,6 +1182,7 @@ Phaser.Loader.prototype = {
11481182 }
11491183
11501184 var file = this . _fileList [ index ] ;
1185+ file . loaded = true ;
11511186
11521187 if ( file . type == 'bitmapfont' )
11531188 {
0 commit comments