Fixed JSON Hash parsing.

This commit is contained in:
photonstorm 2016-10-19 14:29:52 +01:00
parent 0a659bcf67
commit 4f8e509f91
3 changed files with 9 additions and 10 deletions

View file

@ -699,9 +699,10 @@ Phaser.Cache.prototype = {
texture: null
};
if (Array.isArray(atlasData.frames) && format === Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
// If they (or Phaser) set the JSON Format to ARRAY, but it's an Object, then switch it
if (!Array.isArray(atlasData.frames) && format === Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY)
{
format = Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY;
format = Phaser.Loader.TEXTURE_ATLAS_JSON_HASH;
}
var manager = this.game.textures;

View file

@ -18,8 +18,7 @@ Phaser.TextureManager.Parsers.JSONArray = function (texture, sourceIndex, json)
// Malformed?
if (!json['frames'])
{
// console.warn("Phaser.AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
// console.log(json);
console.warn('Invalid Texture Atlas JSON Array given, missing \'frames\' array');
return;
}

View file

@ -13,17 +13,16 @@
* @param {object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format.
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
*/
Phaser.TextureManager.Parsers.JSONHash = function (texture, json)
Phaser.TextureManager.Parsers.JSONHash = function (texture, sourceIndex, json)
{
// Malformed?
if (!json['frames'])
{
// console.warn("Phaser.AnimationParser.JSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object");
// console.log(json);
console.warn('Invalid Texture Atlas JSON Hash given, missing \'frames\' Object');
return;
}
// By this stage frames is a fully parsed array
// By this stage frames is a fully parsed Object
var frames = json['frames'];
var newFrame;
@ -32,7 +31,7 @@ Phaser.TextureManager.Parsers.JSONHash = function (texture, json)
var src = frames[key];
// The frame values are the exact coordinates to cut the frame out of the atlas from
newFrame = texture.add(key, src.frame.x, src.frame.y, src.frame.w, src.frame.h);
newFrame = texture.add(key, sourceIndex, src.frame.x, src.frame.y, src.frame.w, src.frame.h);
// These are the original (non-trimmed) sprite values
if (src.trimmed)
@ -53,5 +52,5 @@ Phaser.TextureManager.Parsers.JSONHash = function (texture, json)
}
}
return data;
return texture;
};