Skip to content

Commit 529d210

Browse files
committed
Merge pull request phaserjs#329 from lucasmonteverde/dev
Custom JSON loader
2 parents 7b572b9 + 3236ea6 commit 529d210

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/loader/Loader.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,22 @@ Phaser.Loader.prototype = {
368368
return this;
369369

370370
},
371+
372+
/**
373+
* Add a custom JSON file to the Loader.
374+
*
375+
* @method Phaser.Loader#json
376+
* @param {string} key - Unique asset key of the json file.
377+
* @param {string} url - URL of the json file.
378+
* @return {Phaser.Loader} This Loader instance.
379+
*/
380+
json: function (key, url) {
381+
382+
this.addToFileList('json', key, url);
383+
384+
return this;
385+
386+
},
371387

372388
/**
373389
* Add a binary file to the Loader. It will be loaded via xhr with a responseType of "arraybuffer". You can specify an optional callback to process the file after load.
@@ -826,12 +842,12 @@ Phaser.Loader.prototype = {
826842
}
827843

828844
break;
829-
830845
case 'tilemap':
846+
case 'json':
831847
this._xhr.open("GET", this.baseURL + file.url, true);
832848
this._xhr.responseType = "text";
833849

834-
if (file.format === Phaser.Tilemap.TILED_JSON)
850+
if (!file.format || file.format === Phaser.Tilemap.TILED_JSON)
835851
{
836852
this._xhr.onload = function () {
837853
return _this.jsonLoadComplete(_this._fileIndex);
@@ -853,7 +869,6 @@ Phaser.Loader.prototype = {
853869
};
854870
this._xhr.send();
855871
break;
856-
857872
case 'text':
858873
case 'script':
859874
this._xhr.open("GET", this.baseURL + file.url, true);
@@ -1112,6 +1127,10 @@ Phaser.Loader.prototype = {
11121127
{
11131128
this.game.cache.addTilemap(file.key, file.url, data, file.format);
11141129
}
1130+
else if (file.type === 'json')
1131+
{
1132+
this.game.cache.addText(file.key, file.url, data);
1133+
}
11151134
else
11161135
{
11171136
this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);

0 commit comments

Comments
 (0)