Skip to content

Commit 4f8e509

Browse files
committed
Fixed JSON Hash parsing.
1 parent 0a659bc commit 4f8e509

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/loader/Cache.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,10 @@ Phaser.Cache.prototype = {
699699
texture: null
700700
};
701701

702-
if (Array.isArray(atlasData.frames) && format === Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
702+
// If they (or Phaser) set the JSON Format to ARRAY, but it's an Object, then switch it
703+
if (!Array.isArray(atlasData.frames) && format === Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY)
703704
{
704-
format = Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY;
705+
format = Phaser.Loader.TEXTURE_ATLAS_JSON_HASH;
705706
}
706707

707708
var manager = this.game.textures;

src/textures/parsers/JSONArray.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ Phaser.TextureManager.Parsers.JSONArray = function (texture, sourceIndex, json)
1818
// Malformed?
1919
if (!json['frames'])
2020
{
21-
// console.warn("Phaser.AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
22-
// console.log(json);
21+
console.warn('Invalid Texture Atlas JSON Array given, missing \'frames\' array');
2322
return;
2423
}
2524

src/textures/parsers/JSONHash.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
* @param {object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format.
1414
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
1515
*/
16-
Phaser.TextureManager.Parsers.JSONHash = function (texture, json)
16+
Phaser.TextureManager.Parsers.JSONHash = function (texture, sourceIndex, json)
1717
{
1818
// Malformed?
1919
if (!json['frames'])
2020
{
21-
// console.warn("Phaser.AnimationParser.JSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object");
22-
// console.log(json);
21+
console.warn('Invalid Texture Atlas JSON Hash given, missing \'frames\' Object');
2322
return;
2423
}
2524

26-
// By this stage frames is a fully parsed array
25+
// By this stage frames is a fully parsed Object
2726
var frames = json['frames'];
2827
var newFrame;
2928

@@ -32,7 +31,7 @@ Phaser.TextureManager.Parsers.JSONHash = function (texture, json)
3231
var src = frames[key];
3332

3433
// The frame values are the exact coordinates to cut the frame out of the atlas from
35-
newFrame = texture.add(key, src.frame.x, src.frame.y, src.frame.w, src.frame.h);
34+
newFrame = texture.add(key, sourceIndex, src.frame.x, src.frame.y, src.frame.w, src.frame.h);
3635

3736
// These are the original (non-trimmed) sprite values
3837
if (src.trimmed)
@@ -53,5 +52,5 @@ Phaser.TextureManager.Parsers.JSONHash = function (texture, json)
5352
}
5453
}
5554

56-
return data;
55+
return texture;
5756
};

0 commit comments

Comments
 (0)