difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
 Copyright (c) 2008-2010 Ricardo Quesada
 Copyright (c) 2011-2012 cocos2d-x.org
 Copyright (c) 2013-2016 Chukong Technologies Inc.
 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
 
 http://www.cocos2d-x.org
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/
 
'use strict';
 
const codec = require('../compression/ZipUtils');
const zlib = require('../compression/zlib.min');
const js = require('../core/platform/js');
require('../core/platform/CCSAXParser');
 
function uint8ArrayToUint32Array (uint8Arr) {
    if(uint8Arr.length % 4 !== 0)
        return null;
 
    let arrLen = uint8Arr.length /4;
    let retArr = window.Uint32Array? new Uint32Array(arrLen) : [];
    for(let i = 0; i < arrLen; i++){
        let offset = i * 4;
        retArr[i] = uint8Arr[offset]  + uint8Arr[offset + 1] * (1 << 8) + uint8Arr[offset + 2] * (1 << 16) + uint8Arr[offset + 3] * (1<<24);
    }
    return retArr;
}
 
// Bits on the far end of the 32-bit global tile ID (GID's) are used for tile flags
 
/**
 * <p>cc.TMXLayerInfo contains the information about the layers like: <br />
 * - Layer name<br />
 * - Layer size <br />
 * - Layer opacity at creation time (it can be modified at runtime)  <br />
 * - Whether the layer is visible (if it's not visible, then the CocosNode won't be created) <br />
 *  <br />
 * This information is obtained from the TMX file.</p>
 * @class TMXLayerInfo
 *
 * @property {Array}    properties  - Properties of the layer info.
 */
cc.TMXLayerInfo = function () {
    this.properties = {};
    this.name = "";
    this._layerSize = null;
    this._tiles = [];
    this.visible = true;
    this._opacity = 0;
    this.ownTiles = true;
    this._minGID = 100000;
    this._maxGID = 0;
    this.offset = cc.v2(0,0);
};
 
cc.TMXLayerInfo.prototype = {
    constructor: cc.TMXLayerInfo,
    /**
     * Gets the Properties.
     * @return {Array}
     */
    getProperties () {
        return this.properties;
    },
 
    /**
     * Set the Properties.
     * @param {object} value
     */
    setProperties (value) {
        this.properties = value;
    }
};
 
/**
 * <p>cc.TMXObjectGroupInfo contains the information about the object group like: <br />
 * - group name<br />
 * - group size <br />
 * - group opacity at creation time (it can be modified at runtime)  <br />
 * - Whether the group is visible <br />
 *  <br />
 * This information is obtained from the TMX file.</p>
 * @class TMXObjectGroupInfo
 *
 * @property {Array}    properties  - Properties of the ObjectGroup info.
 */
cc.TMXObjectGroupInfo = function () {
    this.properties = {};
    this.name = "";
    this._objects = [];
    this.visible = true;
    this._opacity = 0;
    this._color = new cc.Color(255, 255, 255, 255);
    this.offset = cc.v2(0,0);
    this._draworder = 'topdown';
};
 
cc.TMXObjectGroupInfo.prototype = {
    constructor: cc.TMXObjectGroupInfo,
    /**
     * Gets the Properties.
     * @return {Array}
     */
    getProperties () {
        return this.properties;
    },
 
    /**
     * Set the Properties.
     * @param {object} value
     */
    setProperties (value) {
        this.properties = value;
    }
};
 
/**
 * <p>cc.TMXTilesetInfo contains the information about the tilesets like: <br />
 * - Tileset name<br />
 * - Tileset spacing<br />
 * - Tileset margin<br />
 * - size of the tiles<br />
 * - Image used for the tiles<br />
 * - Image size<br />
 *
 * This information is obtained from the TMX file. </p>
 * @class TMXTilesetInfo
 *
 * @property {string} name - Tileset name
 * @property {number} firstGid - First grid
 * @property {number} spacing - Spacing
 * @property {number} margin - Margin
 * @property {null} sourceImage - Texture containing the tiles (should be sprite sheet / texture atlas)
 * @property {cc.Size} imageSize - Size in pixels of the image
 */
cc.TMXTilesetInfo = function () {
    // Tileset name
    this.name = "";
    // First grid
    this.firstGid = 0;
    // Spacing
    this.spacing = 0;
    // Margin
    this.margin = 0;
    // Texture containing the tiles (should be sprite sheet / texture atlas)
    this.sourceImage = null;
    // Size in pixels of the image
    this.imageSize = cc.size(0, 0);
 
    this.tileOffset = cc.v2(0, 0);
 
    this._tileSize = cc.size(0, 0);
};
 
cc.TMXTilesetInfo.prototype = {
    constructor: cc.TMXTilesetInfo,
    /**
     * Return rect
     * @param {Number} gid
     * @return {Rect}
     */
    rectForGID (gid, result) {
        let rect = result || cc.rect(0, 0, 0, 0);
        rect.width = this._tileSize.width;
        rect.height = this._tileSize.height;
        gid &= cc.TiledMap.TileFlag.FLIPPED_MASK;
        gid = gid - parseInt(this.firstGid, 10);
        let max_x = parseInt((this.imageSize.width - this.margin * 2 + this.spacing) / (this._tileSize.width + this.spacing), 10);
        rect.x = parseInt((gid % max_x) * (this._tileSize.width + this.spacing) + this.margin, 10);
        rect.y = parseInt(parseInt(gid / max_x, 10) * (this._tileSize.height + this.spacing) + this.margin, 10);
        return rect;
    }
};
 
function getPropertyList (node, map) {
    let res = [];
    let properties = node.getElementsByTagName("properties");
    for (let i = 0; i < properties.length; ++i) {
        let property = properties[i].getElementsByTagName("property");
        for (let j = 0; j < property.length; ++j) {
            res.push(property[j]);
        }
    }
 
    map = map || {};
    for (let i = 0; i < res.length; i++) {
        let element = res[i];
        let name = element.getAttribute('name');
        let type = element.getAttribute('type') || 'string';
 
        let value = element.getAttribute('value');
        if (type === 'int') {
            value = parseInt(value);
        }
        else if (type === 'float') {
            value = parseFloat(value);
        }
        else if (type === 'bool') {
            value = value === 'true';
        }
        else if (type === 'color') {
            value = (value.indexOf('#') === 0) ? value.substring(1) : value;
            let a = parseInt(value.substr(0, 2), 16) || 255;
            let r = parseInt(value.substr(2, 2), 16) || 0;
            let g = parseInt(value.substr(4, 2), 16) || 0;
            let b = parseInt(value.substr(6, 2), 16) || 0;
            value = cc.color(r, g, b, a);
        }
 
        map[name] = value;
    }
 
    return map;
}
 
/**
 * <p>cc.TMXMapInfo contains the information about the map like: <br/>
 *- Map orientation (hexagonal, isometric or orthogonal)<br/>
 *- Tile size<br/>
 *- Map size</p>
 *
 * <p>And it also contains: <br/>
 * - Layers (an array of TMXLayerInfo objects)<br/>
 * - Tilesets (an array of TMXTilesetInfo objects) <br/>
 * - ObjectGroups (an array of TMXObjectGroupInfo objects) </p>
 *
 * <p>This information is obtained from the TMX file. </p>
 * @class
 *
 * @property {Array}    properties          - Properties of the map info.
 * @property {Number}   orientation         - Map orientation.
 * @property {Object}   parentElement       - Parent element.
 * @property {Number}   parentGID           - Parent GID.
 * @property {Object}   layerAttrs        - Layer attributes.
 * @property {Boolean}  storingCharacters   - Is reading storing characters stream.
 * @property {String}   currentString       - Current string stored from characters stream.
 * @property {Number}   mapWidth            - Width of the map
 * @property {Number}   mapHeight           - Height of the map
 * @property {Number}   tileWidth           - Width of a tile
 * @property {Number}   tileHeight          - Height of a tile
 * @example
 * 1.
 * //create a TMXMapInfo with file name
 * let tmxMapInfo = new cc.TMXMapInfo("res/orthogonal-test1.tmx");
 * 2.
 * //create a TMXMapInfo with content string and resource path
 * let resources = "res/TileMaps";
 * let filePath = "res/TileMaps/orthogonal-test1.tmx";
 * let xmlStr = cc.loader.getRes(filePath);
 * let tmxMapInfo = new cc.TMXMapInfo(xmlStr, resources);
 */
 
/**
 * Creates a TMX Format with a tmx file or content string                           <br/>
 * Constructor of cc.TMXMapInfo
 * @method constructor
 * @param {String} tmxFile content string
 * @param {Object} tsxMap
 * @param {Object} textures
 */
cc.TMXMapInfo = function (tmxFile, tsxMap, textures) {
    this.properties = [];
    this.orientation = null;
    this.parentElement = null;
    this.parentGID = null;
    this.layerAttrs = 0;
    this.storingCharacters = false;
    this.currentString = null;
 
    this._parser = new cc.SAXParser();
    this._objectGroups = [];
    this._allChildren = [];
    this._mapSize = cc.size(0, 0);
    this._tileSize = cc.size(0, 0);
    this._layers = [];
    this._tilesets = [];
    this._tileProperties = {};
    this._tsxMap = null;
 
    // map of textures indexed by name
    this._textures = null;
 
    // hex map values
    this._staggerAxis = null;
    this._staggerIndex = null;
    this._hexSideLength = 0;
 
    this.initWithXML(tmxFile, tsxMap, textures);
};
cc.TMXMapInfo.prototype = {
    constructor: cc.TMXMapInfo,
    /**
     * Gets Map orientation.
     * @return {Number}
     */
    getOrientation () {
        return this.orientation;
    },
 
    /**
     * Set the Map orientation.
     * @param {Number} value
     */
    setOrientation (value) {
        this.orientation = value;
    },
 
    /**
     * Gets the staggerAxis of map.
     * @return {cc.TiledMap.StaggerAxis}
     */
    getStaggerAxis () {
        return this._staggerAxis;
    },
 
    /**
     * Set the staggerAxis of map.
     * @param {cc.TiledMap.StaggerAxis} value
     */
    setStaggerAxis (value) {
        this._staggerAxis = value;
    },
 
    /**
     * Gets stagger index
     * @return {cc.TiledMap.StaggerIndex}
     */
    getStaggerIndex () {
        return this._staggerIndex;
    },
 
    /**
     * Set the stagger index.
     * @param {cc.TiledMap.StaggerIndex} value
     */
    setStaggerIndex (value) {
        this._staggerIndex = value;
    },
 
    /**
     * Gets Hex side length.
     * @return {Number}
     */
    getHexSideLength () {
        return this._hexSideLength;
    },
 
    /**
     * Set the Hex side length.
     * @param {Number} value
     */
    setHexSideLength (value) {
        this._hexSideLength = value;
    },
 
    /**
     * Map width & height
     * @return {Size}
     */
    getMapSize () {
        return cc.size(this._mapSize.width, this._mapSize.height);
    },
 
    /**
     * Map width & height
     * @param {Size} value
     */
    setMapSize (value) {
        this._mapSize.width = value.width;
        this._mapSize.height = value.height;
    },
 
    _getMapWidth () {
        return this._mapSize.width;
    },
    _setMapWidth (width) {
        this._mapSize.width = width;
    },
    _getMapHeight () {
        return this._mapSize.height;
    },
    _setMapHeight (height) {
        this._mapSize.height = height;
    },
 
    /**
     * Tiles width & height
     * @return {Size}
     */
    getTileSize () {
        return cc.size(this._tileSize.width, this._tileSize.height);
    },
 
    /**
     * Tiles width & height
     * @param {Size} value
     */
    setTileSize (value) {
        this._tileSize.width = value.width;
        this._tileSize.height = value.height;
    },
 
    _getTileWidth () {
        return this._tileSize.width;
    },
    _setTileWidth (width) {
        this._tileSize.width = width;
    },
    _getTileHeight () {
        return this._tileSize.height;
    },
    _setTileHeight (height) {
        this._tileSize.height = height;
    },
 
    /**
     * Layers
     * @return {Array}
     */
    getLayers () {
        return this._layers;
    },
 
    /**
     * Layers
     * @param {cc.TMXLayerInfo} value
     */
    setLayers (value) {
        this._allChildren.push(value);
        this._layers.push(value);
    },
 
    /**
     * tilesets
     * @return {Array}
     */
    getTilesets () {
        return this._tilesets;
    },
 
    /**
     * tilesets
     * @param {cc.TMXTilesetInfo} value
     */
    setTilesets (value) {
        this._tilesets.push(value);
    },
 
    /**
     * ObjectGroups
     * @return {Array}
     */
    getObjectGroups () {
        return this._objectGroups;
    },
 
    /**
     * ObjectGroups
     * @param {cc.TMXObjectGroup} value
     */
    setObjectGroups (value) {
        this._allChildren.push(value);
        this._objectGroups.push(value);
    },
 
    getAllChildren () {
        return this._allChildren;
    },
 
    /**
     * parent element
     * @return {Object}
     */
    getParentElement () {
        return this.parentElement;
    },
 
    /**
     * parent element
     * @param {Object} value
     */
    setParentElement (value) {
        this.parentElement = value;
    },
 
    /**
     * parent GID
     * @return {Number}
     */
    getParentGID () {
        return this.parentGID;
    },
 
    /**
     * parent GID
     * @param {Number} value
     */
    setParentGID (value) {
        this.parentGID = value;
    },
 
    /**
     * Layer attribute
     * @return {Object}
     */
    getLayerAttribs () {
        return this.layerAttrs;
    },
 
    /**
     * Layer attribute
     * @param {Object} value
     */
    setLayerAttribs (value) {
        this.layerAttrs = value;
    },
 
    /**
     * Is reading storing characters stream
     * @return {Boolean}
     */
    getStoringCharacters () {
        return this.storingCharacters;
    },
 
    /**
     * Is reading storing characters stream
     * @param {Boolean} value
     */
    setStoringCharacters (value) {
        this.storingCharacters = value;
    },
 
    /**
     * Properties
     * @return {Array}
     */
    getProperties () {
        return this.properties;
    },
 
    /**
     * Properties
     * @param {object} value
     */
    setProperties (value) {
        this.properties = value;
    },
 
    /**
     * initializes a TMX format with an XML string and a TMX resource path
     * @param {String} tmxString
     * @param {Object} tsxMap
     * @param {Object} textures
     * @return {Boolean}
     */
    initWithXML (tmxString, tsxMap, textures) {
        this._tilesets.length = 0;
        this._layers.length = 0;
 
        this._tsxMap = tsxMap;
        this._textures = textures;
 
        this._objectGroups.length = 0;
        this._allChildren.length = 0;
        this.properties.length = 0;
        this._tileProperties.length = 0;
 
        // tmp vars
        this.currentString = "";
        this.storingCharacters = false;
        this.layerAttrs = cc.TMXLayerInfo.ATTRIB_NONE;
        this.parentElement = cc.TiledMap.NONE;
 
        return this.parseXMLString(tmxString);
    },
 
    /**
     * Initializes parsing of an XML string, either a tmx (Map) string or tsx (Tileset) string
     * @param {String} xmlString
     * @param {Number} tilesetFirstGid
     * @return {Element}
     */
    parseXMLString (xmlStr, tilesetFirstGid) {
        let mapXML = this._parser._parseXML(xmlStr);
        let i, j;
 
        // PARSE <map>
        let map = mapXML.documentElement;
 
        let version = map.getAttribute('version');
        let orientationStr = map.getAttribute('orientation');
        let staggerAxisStr = map.getAttribute('staggeraxis');
        let staggerIndexStr = map.getAttribute('staggerindex');
        let hexSideLengthStr = map.getAttribute('hexsidelength');
 
        if (map.nodeName === "map") {
            if (version !== "1.0" && version !== null)
                cc.logID(7216, version);
 
            if (orientationStr === "orthogonal")
                this.orientation = cc.TiledMap.Orientation.ORTHO;
            else if (orientationStr === "isometric")
                this.orientation = cc.TiledMap.Orientation.ISO;
            else if (orientationStr === "hexagonal")
                this.orientation = cc.TiledMap.Orientation.HEX;
            else if (orientationStr !== null)
                cc.logID(7217, orientationStr);
 
            if (staggerAxisStr === 'x') {
                this.setStaggerAxis(cc.TiledMap.StaggerAxis.STAGGERAXIS_X);
            }
            else if (staggerAxisStr === 'y') {
                this.setStaggerAxis(cc.TiledMap.StaggerAxis.STAGGERAXIS_Y);
            }
 
            if (staggerIndexStr === 'odd') {
                this.setStaggerIndex(cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD);
            }
            else if (staggerIndexStr === 'even') {
                this.setStaggerIndex(cc.TiledMap.StaggerIndex.STAGGERINDEX_EVEN);
            }
 
            if (hexSideLengthStr) {
                this.setHexSideLength(parseFloat(hexSideLengthStr));
            }
 
            let mapSize = cc.size(0, 0);
            mapSize.width = parseFloat(map.getAttribute('width'));
            mapSize.height = parseFloat(map.getAttribute('height'));
            this.setMapSize(mapSize);
 
            mapSize = cc.size(0, 0);
            mapSize.width = parseFloat(map.getAttribute('tilewidth'));
            mapSize.height = parseFloat(map.getAttribute('tileheight'));
            this.setTileSize(mapSize);
 
            // The parent element is the map
            this.properties = getPropertyList(map);
        }
 
        // PARSE <tileset>
        let tilesets = map.getElementsByTagName('tileset');
        if (map.nodeName !== "map") {
            tilesets = [];
            tilesets.push(map);
        }
 
        for (i = 0; i < tilesets.length; i++) {
            let selTileset = tilesets[i];
            // If this is an external tileset then start parsing that
            let tsxName = selTileset.getAttribute('source');
            if (tsxName) {
                let currentFirstGID = parseInt(selTileset.getAttribute('firstgid'));
                let tsxXmlString = this._tsxMap[tsxName];
                if (tsxXmlString) {
                    this.parseXMLString(tsxXmlString, currentFirstGID);
                }
            } else {
                let tileset = new cc.TMXTilesetInfo();
                tileset.name = selTileset.getAttribute('name') || "";
                if (tilesetFirstGid) {
                    tileset.firstGid = tilesetFirstGid;
                } else {
                    tileset.firstGid = parseInt(selTileset.getAttribute('firstgid')) || 0;
                }
 
                tileset.spacing = parseInt(selTileset.getAttribute('spacing')) || 0;
                tileset.margin = parseInt(selTileset.getAttribute('margin')) || 0;
 
                let tilesetSize = cc.size(0, 0);
                tilesetSize.width = parseFloat(selTileset.getAttribute('tilewidth'));
                tilesetSize.height = parseFloat(selTileset.getAttribute('tileheight'));
                tileset._tileSize = tilesetSize;
 
                let image = selTileset.getElementsByTagName('image')[0];
                let imagename = image.getAttribute('source');
                imagename.replace(/\\/g, '\/');
                tileset.sourceImage = this._textures[imagename];
                if (!tileset.sourceImage) {
                    cc.errorID(7221, imagename);
                }
 
                this.setTilesets(tileset);
 
                // parse tile offset
                let offset = selTileset.getElementsByTagName('tileoffset')[0];
                if (offset) {
                    let offsetX = parseFloat(offset.getAttribute('x'));
                    let offsetY = parseFloat(offset.getAttribute('y'));
                    tileset.tileOffset = cc.v2(offsetX, offsetY);
                }
 
                // PARSE  <tile>
                let tiles = selTileset.getElementsByTagName('tile');
                if (tiles) {
                    for (let tIdx = 0; tIdx < tiles.length; tIdx++) {
                        let t = tiles[tIdx];
                        this.parentGID = parseInt(tileset.firstGid) + parseInt(t.getAttribute('id') || 0);
                        this._tileProperties[this.parentGID] = getPropertyList(t);
                    }
                }
            }
        }
 
        // PARSE <layer> & <objectgroup> in order
        let childNodes = map.childNodes;
        for (i = 0; i < childNodes.length; i++) {
            let childNode = childNodes[i];
            if (this._shouldIgnoreNode(childNode)) {
                continue;
            }
 
            if (childNode.nodeName === 'layer') {
                let layer = this._parseLayer(childNode);
                this.setLayers(layer);
            }
 
            if (childNode.nodeName === 'objectgroup') {
                let objectGroup = this._parseObjectGroup(childNode);
                this.setObjectGroups(objectGroup);
            }
        }
 
        return map;
    },
 
    _shouldIgnoreNode (node) {
        return node.nodeType === 3 // text
            || node.nodeType === 8   // comment
            || node.nodeType === 4;  // cdata
    },
 
    _parseLayer (selLayer) {
        let data = selLayer.getElementsByTagName('data')[0];
 
        let layer = new cc.TMXLayerInfo();
        layer.name = selLayer.getAttribute('name');
 
        let layerSize = cc.size(0, 0);
        layerSize.width = parseFloat(selLayer.getAttribute('width'));
        layerSize.height = parseFloat(selLayer.getAttribute('height'));
        layer._layerSize = layerSize;
 
        let visible = selLayer.getAttribute('visible');
        layer.visible = !(visible === "0");
 
        let opacity = selLayer.getAttribute('opacity') || 1;
        if (opacity)
            layer._opacity = parseInt(255 * parseFloat(opacity));
        else
            layer._opacity = 255;
        layer.offset = cc.v2(parseFloat(selLayer.getAttribute('x')) || 0, parseFloat(selLayer.getAttribute('y')) || 0);
 
        let nodeValue = '';
        for (let j = 0; j < data.childNodes.length; j++) {
            nodeValue += data.childNodes[j].nodeValue
        }
        nodeValue = nodeValue.trim();
 
        // Unpack the tilemap data
        let compression = data.getAttribute('compression');
        let encoding = data.getAttribute('encoding');
        if (compression && compression !== "gzip" && compression !== "zlib") {
            cc.logID(7218);
            return null;
        }
        let tiles;
        switch (compression) {
            case 'gzip':
                tiles = codec.unzipBase64AsArray(nodeValue, 4);
                break;
            case 'zlib':
                let inflator = new zlib.Inflate(codec.Base64.decodeAsArray(nodeValue, 1));
                tiles = uint8ArrayToUint32Array(inflator.decompress());
                break;
            case null:
            case '':
                // Uncompressed
                if (encoding === "base64")
                    tiles = codec.Base64.decodeAsArray(nodeValue, 4);
                else if (encoding === "csv") {
                    tiles = [];
                    let csvTiles = nodeValue.split(',');
                    for (let csvIdx = 0; csvIdx < csvTiles.length; csvIdx++)
                        tiles.push(parseInt(csvTiles[csvIdx]));
                } else {
                    //XML format
                    let selDataTiles = data.getElementsByTagName("tile");
                    tiles = [];
                    for (let xmlIdx = 0; xmlIdx < selDataTiles.length; xmlIdx++)
                        tiles.push(parseInt(selDataTiles[xmlIdx].getAttribute("gid")));
                }
                break;
            default:
                if (this.layerAttrs === cc.TMXLayerInfo.ATTRIB_NONE)
                    cc.logID(7219);
                break;
        }
        if (tiles) {
            layer._tiles = new Uint32Array(tiles);
        }
 
        // The parent element is the last layer
        layer.properties = getPropertyList(selLayer);
 
        return layer;
    },
 
    _parseObjectGroup (selGroup) {
        let objectGroup = new cc.TMXObjectGroupInfo();
        objectGroup.name = selGroup.getAttribute('name') || '';
        objectGroup.offset = cc.v2(parseFloat(selGroup.getAttribute('offsetx')), parseFloat(selGroup.getAttribute('offsety')));
 
        let opacity = selGroup.getAttribute('opacity') || 1;
        if (opacity)
            objectGroup._opacity = parseInt(255 * parseFloat(opacity));
        else
            objectGroup._opacity = 255;
 
        let visible = selGroup.getAttribute('visible');
        if (visible && parseInt(visible) === 0)
            objectGroup.visible = false;
 
        let color = selGroup.getAttribute('color');
        if (color)
            objectGroup._color.fromHEX(color);
 
        let draworder = selGroup.getAttribute('draworder');
        if (draworder)
            objectGroup._draworder = draworder;
 
        // set the properties to the group
        objectGroup.setProperties(getPropertyList(selGroup));
 
        let objects = selGroup.getElementsByTagName('object');
        if (objects) {
            for (let j = 0; j < objects.length; j++) {
                let selObj = objects[j];
                // The value for "type" was blank or not a valid class name
                // Create an instance of TMXObjectInfo to store the object and its properties
                let objectProp = {};
 
                // Set the id of the object
                objectProp['id'] = selObj.getAttribute('id') || 0;
 
                // Set the name of the object to the value for "name"
                objectProp["name"] = selObj.getAttribute('name') || "";
 
                // Assign all the attributes as key/name pairs in the properties dictionary
                objectProp["width"] = parseFloat(selObj.getAttribute('width')) || 0;
                objectProp["height"] = parseFloat(selObj.getAttribute('height')) || 0;
 
                objectProp["x"] = parseFloat(selObj.getAttribute('x')) || 0;
                objectProp["y"] = parseFloat(selObj.getAttribute('y')) || 0;
 
                objectProp["rotation"] = parseFloat(selObj.getAttribute('rotation')) || 0;
 
                getPropertyList(selObj, objectProp);
 
                // visible
                let visibleAttr = selObj.getAttribute('visible');
                objectProp['visible'] = !(visibleAttr && parseInt(visibleAttr) === 0);
 
                // image
                let gid = selObj.getAttribute('gid');
                if (gid) {
                    objectProp['gid'] = parseInt(gid);
                    objectProp['type'] = cc.TiledMap.TMXObjectType.IMAGE;
                }
 
                // ellipse
                let ellipse = selObj.getElementsByTagName('ellipse');
                if (ellipse && ellipse.length > 0) {
                    objectProp['type'] = cc.TiledMap.TMXObjectType.ELLIPSE;
                }
 
                //polygon
                let polygonProps = selObj.getElementsByTagName("polygon");
                if (polygonProps && polygonProps.length > 0) {
                    objectProp['type'] = cc.TiledMap.TMXObjectType.POLYGON;
                    let selPgPointStr = polygonProps[0].getAttribute('points');
                    if (selPgPointStr)
                        objectProp["points"] = this._parsePointsString(selPgPointStr);
                }
 
                //polyline
                let polylineProps = selObj.getElementsByTagName("polyline");
                if (polylineProps && polylineProps.length > 0) {
                    objectProp['type'] = cc.TiledMap.TMXObjectType.POLYLINE;
                    let selPlPointStr = polylineProps[0].getAttribute('points');
                    if (selPlPointStr)
                        objectProp["polylinePoints"] = this._parsePointsString(selPlPointStr);
                }
 
                if (!objectProp['type']) {
                    objectProp['type'] = cc.TiledMap.TMXObjectType.RECT;
                }
 
                // Add the object to the objectGroup
                objectGroup._objects.push(objectProp);
            }
        }
        return objectGroup;
    },
 
    _parsePointsString (pointsString) {
        if (!pointsString)
            return null;
 
        let points = [];
        let pointsStr = pointsString.split(' ');
        for (let i = 0; i < pointsStr.length; i++) {
            let selPointStr = pointsStr[i].split(',');
            points.push({'x': parseFloat(selPointStr[0]), 'y': parseFloat(selPointStr[1])});
        }
        return points;
    },
 
    /**
     * Gets the tile properties.
     * @return {object}
     */
    getTileProperties () {
        return this._tileProperties;
    },
 
    /**
     * Set the tile properties.
     * @param {object} tileProperties
     */
    setTileProperties (tileProperties) {
        this._tileProperties.push(tileProperties);
    },
 
    /**
     * Gets the currentString
     * @return {String}
     */
    getCurrentString () {
        return this.currentString;
    },
 
    /**
     * Set the currentString
     * @param {String} currentString
     */
    setCurrentString (currentString) {
        this.currentString = currentString;
    }
};
 
let _p = cc.TMXMapInfo.prototype;
 
// Extended properties
js.getset(_p, "mapWidth", _p._getMapWidth, _p._setMapWidth);
js.getset(_p, "mapHeight", _p._getMapHeight, _p._setMapHeight);
js.getset(_p, "tileWidth", _p._getTileWidth, _p._setTileWidth);
js.getset(_p, "tileHeight", _p._getTileHeight, _p._setTileHeight);
 
 
/**
 * @constant
 * @type Number
 */
cc.TMXLayerInfo.ATTRIB_NONE = 1 << 0;
/**
 * @constant
 * @type Number
 */
cc.TMXLayerInfo.ATTRIB_BASE64 = 1 << 1;
/**
 * @constant
 * @type Number
 */
cc.TMXLayerInfo.ATTRIB_GZIP = 1 << 2;
/**
 * @constant
 * @type Number
 */
cc.TMXLayerInfo.ATTRIB_ZLIB = 1 << 3;