123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- #ifndef __CC_TM_XML_PARSER__
- #define __CC_TM_XML_PARSER__
- #include "math/CCGeometry.h"
- #include "platform/CCSAXParser.h"
- #include "base/CCVector.h"
- #include "base/CCValue.h"
- #include "2d/CCTMXObjectGroup.h"
- #include <string>
- NS_CC_BEGIN
- class TMXLayerInfo;
- class TMXTilesetInfo;
- enum {
- TMXLayerAttribNone = 1 << 0,
- TMXLayerAttribBase64 = 1 << 1,
- TMXLayerAttribGzip = 1 << 2,
- TMXLayerAttribZlib = 1 << 3,
- TMXLayerAttribCSV = 1 << 4,
- };
- enum {
- TMXPropertyNone,
- TMXPropertyMap,
- TMXPropertyLayer,
- TMXPropertyObjectGroup,
- TMXPropertyObject,
- TMXPropertyTile
- };
- typedef enum TMXTileFlags_ {
- kTMXTileHorizontalFlag = 0x80000000,
- kTMXTileVerticalFlag = 0x40000000,
- kTMXTileDiagonalFlag = 0x20000000,
- kTMXFlipedAll = (kTMXTileHorizontalFlag|kTMXTileVerticalFlag|kTMXTileDiagonalFlag),
- kTMXFlippedMask = ~(kTMXFlipedAll)
- } TMXTileFlags;
- class CC_DLL TMXLayerInfo : public Ref
- {
- public:
-
- TMXLayerInfo();
-
- virtual ~TMXLayerInfo();
- void setProperties(ValueMap properties);
- ValueMap& getProperties();
- ValueMap _properties;
- std::string _name;
- Size _layerSize;
- uint32_t *_tiles;
- bool _visible;
- unsigned char _opacity;
- bool _ownTiles;
- Vec2 _offset;
- };
- class CC_DLL TMXTilesetInfo : public Ref
- {
- public:
- std::string _name;
- int _firstGid;
- Size _tileSize;
- int _spacing;
- int _margin;
- Vec2 _tileOffset;
-
- std::string _sourceImage;
-
- Size _imageSize;
- std::string _originSourceImage;
- public:
-
- TMXTilesetInfo();
-
- virtual ~TMXTilesetInfo();
- Rect getRectForGID(uint32_t gid);
- };
- class CC_DLL TMXMapInfo : public Ref, public SAXDelegator
- {
- public:
-
- static TMXMapInfo * create(const std::string& tmxFile);
-
- static TMXMapInfo * createWithXML(const std::string& tmxString, const std::string& resourcePath);
-
-
- CC_DEPRECATED_ATTRIBUTE static TMXMapInfo * formatWithTMXFile(const char *tmxFile) { return TMXMapInfo::create(tmxFile); };
-
- CC_DEPRECATED_ATTRIBUTE static TMXMapInfo * formatWithXML(const char* tmxString, const char* resourcePath) { return TMXMapInfo::createWithXML(tmxString, resourcePath); };
-
- TMXMapInfo();
-
- virtual ~TMXMapInfo();
-
-
- bool initWithTMXFile(const std::string& tmxFile);
-
- bool initWithXML(const std::string& tmxString, const std::string& resourcePath);
-
- bool parseXMLFile(const std::string& xmlFilename);
-
- bool parseXMLString(const std::string& xmlString);
- ValueMapIntKey& getTileProperties() { return _tileProperties; };
- void setTileProperties(const ValueMapIntKey& tileProperties) {
- _tileProperties = tileProperties;
- }
-
- int getOrientation() const { return _orientation; }
- void setOrientation(int orientation) { _orientation = orientation; }
-
-
- int getStaggerAxis() const { return _staggerAxis; }
- void setStaggerAxis(int staggerAxis) { _staggerAxis = staggerAxis; }
-
- int getStaggerIndex() const { return _staggerIndex; }
- void setStaggerIndex(int staggerIndex) { _staggerIndex = staggerIndex; }
-
- int getHexSideLength() const { return _hexSideLength; }
- void setHexSideLength(int hexSideLength) { _hexSideLength = hexSideLength; }
-
- const Size& getMapSize() const { return _mapSize; }
- void setMapSize(const Size& mapSize) { _mapSize = mapSize; }
-
- const Size& getTileSize() const { return _tileSize; }
- void setTileSize(const Size& tileSize) { _tileSize = tileSize; }
-
-
- const Vector<TMXLayerInfo*>& getLayers() const { return _layers; }
- Vector<TMXLayerInfo*>& getLayers() { return _layers; }
- void setLayers(const Vector<TMXLayerInfo*>& layers) {
- _layers = layers;
- }
-
- const Vector<TMXTilesetInfo*>& getTilesets() const { return _tilesets; }
- Vector<TMXTilesetInfo*>& getTilesets() { return _tilesets; }
- void setTilesets(const Vector<TMXTilesetInfo*>& tilesets) {
- _tilesets = tilesets;
- }
-
- const Vector<TMXObjectGroup*>& getObjectGroups() const { return _objectGroups; }
- Vector<TMXObjectGroup*>& getObjectGroups() { return _objectGroups; }
- void setObjectGroups(const Vector<TMXObjectGroup*>& groups) {
- _objectGroups = groups;
- }
-
- int getParentElement() const { return _parentElement; }
- void setParentElement(int element) { _parentElement = element; }
-
- int getParentGID() const { return _parentGID; }
- void setParentGID(int gid) { _parentGID = gid; }
-
- int getLayerAttribs() const { return _layerAttribs; }
- void setLayerAttribs(int layerAttribs) { _layerAttribs = layerAttribs; }
-
- bool isStoringCharacters() const { return _storingCharacters; }
- CC_DEPRECATED_ATTRIBUTE bool getStoringCharacters() const { return isStoringCharacters(); }
- void setStoringCharacters(bool storingCharacters) { _storingCharacters = storingCharacters; }
-
- const ValueMap& getProperties() const { return _properties; }
- ValueMap& getProperties() { return _properties; }
- void setProperties(const ValueMap& properties) {
- _properties = properties;
- }
-
-
-
- void startElement(void *ctx, const char *name, const char **atts) override;
-
- void endElement(void *ctx, const char *name) override;
-
- void textHandler(void *ctx, const char *ch, size_t len) override;
-
- const std::string& getCurrentString() const { return _currentString; }
- void setCurrentString(const std::string& currentString){ _currentString = currentString; }
- const std::string& getTMXFileName() const { return _TMXFileName; }
- void setTMXFileName(const std::string& fileName){ _TMXFileName = fileName; }
- const std::string& getExternalTilesetFileName() const { return _externalTilesetFilename; }
- protected:
- void internalInit(const std::string& tmxFileName, const std::string& resourcePath);
-
- int _orientation;
-
- int _staggerAxis;
-
- int _staggerIndex;
-
- int _hexSideLength;
-
- Size _mapSize;
-
- Size _tileSize;
-
- Vector<TMXLayerInfo*> _layers;
-
- Vector<TMXTilesetInfo*> _tilesets;
-
- Vector<TMXObjectGroup*> _objectGroups;
-
- int _parentElement;
-
- int _parentGID;
-
- int _layerAttribs;
-
- bool _storingCharacters;
-
- ValueMap _properties;
-
- int _xmlTileIndex;
-
-
- std::string _TMXFileName;
-
- std::string _resources;
-
- std::string _currentString;
-
- ValueMapIntKey _tileProperties;
- int _currentFirstGID;
- bool _recordFirstGID;
- std::string _externalTilesetFilename;
- };
- NS_CC_END
- #endif
|