Skip to content

Commit e1b252e

Browse files
committed
Removed un-used texture parsers and added in new AtlasXML parser.
1 parent 8259111 commit e1b252e

5 files changed

Lines changed: 82 additions & 205 deletions

File tree

src/textures/TextureManager.js

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -627,75 +627,26 @@ var TextureManager = new Class({
627627

628628
/**
629629
* Adds a Texture Atlas to this Texture Manager, where the atlas data is given
630-
* in the Starling XML format.
630+
* in the XML format.
631631
*
632-
* @method Phaser.Textures.TextureManager#addAtlasStarlingXML
633-
* @since 3.0.0
632+
* @method Phaser.Textures.TextureManager#addAtlasXML
633+
* @since 3.7.0
634634
*
635635
* @param {string} key - The unique string-based key of the Texture.
636636
* @param {HTMLImageElement} source - The source Image element.
637637
* @param {object} data - The Texture Atlas XML data.
638638
*
639639
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
640640
*/
641-
addAtlasStarlingXML: function (key, source, data)
641+
addAtlasXML: function (key, source, data)
642642
{
643643
var texture = null;
644644

645645
if (this.checkKey(key))
646646
{
647647
texture = this.create(key, source);
648-
649-
if (Array.isArray(data))
650-
{
651-
for (var i = 0; i < data.length; i++)
652-
{
653-
Parser.StarlingXML(texture, i, data[i]);
654-
}
655-
}
656-
else
657-
{
658-
Parser.StarlingXML(texture, 0, data);
659-
}
660-
661-
this.emit('addtexture', key, texture);
662-
}
663-
664-
return texture;
665-
},
666-
667-
/**
668-
* Adds a Texture Atlas to this Texture Manager, where the atlas data is given
669-
* in the Pyxel JSON format.
670-
*
671-
* @method Phaser.Textures.TextureManager#addAtlasPyxel
672-
* @since 3.0.0
673-
*
674-
* @param {string} key - The unique string-based key of the Texture.
675-
* @param {HTMLImageElement} source - The source Image element.
676-
* @param {object} data - The Texture Atlas XML data.
677-
*
678-
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
679-
*/
680-
addAtlasPyxel: function (key, source, data)
681-
{
682-
var texture = null;
683-
684-
if (this.checkKey(key))
685-
{
686-
texture = this.create(key, source);
687-
688-
if (Array.isArray(data))
689-
{
690-
for (var i = 0; i < data.length; i++)
691-
{
692-
Parser.Pyxel(texture, i, data[i]);
693-
}
694-
}
695-
else
696-
{
697-
Parser.Pyxel(texture, 0, data);
698-
}
648+
649+
Parser.AtlasXML(texture, 0, data);
699650

700651
this.emit('addtexture', key, texture);
701652
}

src/textures/parsers/AtlasXML.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* Parses an XML Texture Atlas object and adds all the Frames into a Texture.
9+
*
10+
* @function Phaser.Textures.Parsers.AtlasXML
11+
* @memberOf Phaser.Textures.Parsers
12+
* @private
13+
* @since 3.7.0
14+
*
15+
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
16+
* @param {integer} sourceIndex - The index of the TextureSource.
17+
* @param {*} xml - The XML data.
18+
*
19+
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
20+
*/
21+
var AtlasXML = function (texture, sourceIndex, xml)
22+
{
23+
// Malformed?
24+
if (!xml.getElementsByTagName('TextureAtlas'))
25+
{
26+
console.warn('Invalid Texture Atlas XML given');
27+
return;
28+
}
29+
30+
// Add in a __BASE entry (for the entire atlas)
31+
var source = texture.source[sourceIndex];
32+
33+
texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height);
34+
35+
// By this stage frames is a fully parsed array
36+
var frames = xml.getElementsByTagName('SubTexture');
37+
38+
var newFrame;
39+
40+
for (var i = 0; i < frames.length; i++)
41+
{
42+
var frame = frames[i].attributes;
43+
44+
var name = frame.name.value;
45+
var x = parseInt(frame.x.value, 10);
46+
var y = parseInt(frame.y.value, 10);
47+
var width = parseInt(frame.width.value, 10);
48+
var height = parseInt(frame.height.value, 10);
49+
50+
// The frame values are the exact coordinates to cut the frame out of the atlas from
51+
newFrame = texture.add(name, sourceIndex, x, y, width, height);
52+
53+
// These are the original (non-trimmed) sprite values
54+
if (frame.frameX)
55+
{
56+
frameX = Math.abs(parseInt(frame.frameX.value, 10));
57+
frameY = Math.abs(parseInt(frame.frameY.value, 10));
58+
frameWidth = parseInt(frame.frameWidth.value, 10);
59+
frameHeight = parseInt(frame.frameHeight.value, 10);
60+
61+
newFrame.setTrim(
62+
width,
63+
height,
64+
frameX,
65+
frameY,
66+
frameWidth,
67+
frameHeight
68+
);
69+
}
70+
}
71+
72+
return texture;
73+
};
74+
75+
module.exports = AtlasXML;

src/textures/parsers/Pyxel.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/textures/parsers/StarlingXML.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/textures/parsers/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010

1111
module.exports = {
1212

13+
AtlasXML: require('./AtlasXML'),
1314
Canvas: require('./Canvas'),
1415
Image: require('./Image'),
1516
JSONArray: require('./JSONArray'),
1617
JSONHash: require('./JSONHash'),
17-
Pyxel: require('./Pyxel'),
1818
SpriteSheet: require('./SpriteSheet'),
1919
SpriteSheetFromAtlas: require('./SpriteSheetFromAtlas'),
20-
StarlingXML: require('./StarlingXML'),
2120
UnityYAML: require('./UnityYAML')
2221

2322
};

0 commit comments

Comments
 (0)