2010-11-13 11:34:49 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2009-2010 Ricardo Quesada
|
2010-11-13 11:34:49 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CC_TM_XML_PARSER__
|
|
|
|
#define __CC_TM_XML_PARSER__
|
2011-01-15 18:05:35 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCMutableArray.h"
|
|
|
|
#include "CCMutableDictionary.h"
|
|
|
|
#include "CCGeometry.h"
|
2011-01-15 18:05:35 +08:00
|
|
|
|
2010-11-13 11:34:49 +08:00
|
|
|
namespace cocos2d {
|
|
|
|
|
2010-09-29 16:33:52 +08:00
|
|
|
class CCTMXObjectGroup;
|
2010-08-27 18:07:37 +08:00
|
|
|
|
2010-09-29 16:33:52 +08:00
|
|
|
/** @file
|
2010-08-27 18:07:37 +08:00
|
|
|
* Internal TMX parser
|
|
|
|
*
|
|
|
|
* IMPORTANT: These classed should not be documented using doxygen strings
|
|
|
|
* since the user should not use them.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TMXLayerAttribNone = 1 << 0,
|
|
|
|
TMXLayerAttribBase64 = 1 << 1,
|
|
|
|
TMXLayerAttribGzip = 1 << 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TMXPropertyNone,
|
|
|
|
TMXPropertyMap,
|
|
|
|
TMXPropertyLayer,
|
|
|
|
TMXPropertyObjectGroup,
|
|
|
|
TMXPropertyObject,
|
|
|
|
TMXPropertyTile
|
|
|
|
};
|
|
|
|
|
2010-09-29 16:33:52 +08:00
|
|
|
/** @brief CCTMXLayerInfo contains the information about the layers like:
|
2010-08-27 18:07:37 +08:00
|
|
|
- Layer name
|
|
|
|
- Layer size
|
|
|
|
- Layer opacity at creation time (it can be modified at runtime)
|
|
|
|
- Whether the layer is visible (if it's not visible, then the CocosNode won't be created)
|
|
|
|
|
|
|
|
This information is obtained from the TMX file.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCTMXLayerInfo : public CCObject
|
2010-08-27 18:07:37 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
2010-08-27 18:07:37 +08:00
|
|
|
public:
|
|
|
|
std::string m_sName;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize m_tLayerSize;
|
2010-08-27 18:07:37 +08:00
|
|
|
unsigned int *m_pTiles;
|
|
|
|
bool m_bVisible;
|
|
|
|
unsigned char m_cOpacity;
|
|
|
|
bool m_bOwnTiles;
|
|
|
|
unsigned int m_uMinGID;
|
|
|
|
unsigned int m_uMaxGID;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint m_tOffset;
|
2010-08-27 18:07:37 +08:00
|
|
|
public:
|
|
|
|
CCTMXLayerInfo();
|
|
|
|
virtual ~CCTMXLayerInfo();
|
|
|
|
};
|
|
|
|
|
2010-09-29 16:33:52 +08:00
|
|
|
/** @brief CCTMXTilesetInfo contains the information about the tilesets like:
|
2010-08-27 18:07:37 +08:00
|
|
|
- Tileset name
|
|
|
|
- Tilset spacing
|
|
|
|
- Tileset margin
|
|
|
|
- size of the tiles
|
|
|
|
- Image used for the tiles
|
|
|
|
- Image size
|
|
|
|
|
|
|
|
This information is obtained from the TMX file.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCTMXTilesetInfo : public CCObject
|
2010-08-27 18:07:37 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string m_sName;
|
|
|
|
unsigned int m_uFirstGid;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize m_tTileSize;
|
2010-08-27 18:07:37 +08:00
|
|
|
unsigned int m_uSpacing;
|
|
|
|
unsigned int m_uMargin;
|
2010-09-29 12:03:21 +08:00
|
|
|
//! filename containing the tiles (should be spritesheet / texture atlas)
|
2010-08-27 18:07:37 +08:00
|
|
|
std::string m_sSourceImage;
|
2010-09-29 12:03:21 +08:00
|
|
|
//! size in pixels of the image
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize m_tImageSize;
|
2010-08-27 18:07:37 +08:00
|
|
|
public:
|
2010-08-31 18:11:31 +08:00
|
|
|
CCTMXTilesetInfo();
|
2010-08-27 18:07:37 +08:00
|
|
|
virtual ~CCTMXTilesetInfo();
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRect rectForGID(unsigned int gid);
|
2010-08-27 18:07:37 +08:00
|
|
|
};
|
2010-09-29 16:33:52 +08:00
|
|
|
|
|
|
|
/** @brief CCTMXMapInfo contains the information about the map like:
|
2010-08-27 18:07:37 +08:00
|
|
|
- Map orientation (hexagonal, isometric or orthogonal)
|
|
|
|
- Tile size
|
|
|
|
- Map size
|
|
|
|
|
|
|
|
And it also contains:
|
|
|
|
- Layers (an array of TMXLayerInfo objects)
|
|
|
|
- Tilesets (an array of TMXTilesetInfo objects)
|
|
|
|
- ObjectGroups (an array of TMXObjectGroupInfo objects)
|
|
|
|
|
|
|
|
This information is obtained from the TMX file.
|
|
|
|
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCTMXMapInfo : public CCObject
|
2010-08-27 18:07:37 +08:00
|
|
|
{
|
2010-09-06 11:59:28 +08:00
|
|
|
public:
|
2010-09-28 12:14:12 +08:00
|
|
|
/// map orientation
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SYNTHESIZE(int, m_nOrientation, Orientation);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// map width & height
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SYNTHESIZE(CCSize, m_tMapSize, MapSize);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// tiles width & height
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SYNTHESIZE(CCSize, m_tTileSize, TileSize);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// Layers
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(CCMutableArray<CCTMXLayerInfo*>*, m_pLayers, Layers);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// tilesets
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(CCMutableArray<CCTMXTilesetInfo*>*, m_pTilesets, Tilesets);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// ObjectGroups
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(CCMutableArray<CCTMXObjectGroup*>*, m_pObjectGroups, ObjectGroups);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// parent element
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SYNTHESIZE(int, m_nParentElement, ParentElement);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// parent GID
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SYNTHESIZE(unsigned int, m_uParentGID, ParentGID);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// layer attribs
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SYNTHESIZE(int, m_nLayerAttribs, LayerAttribs);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// is stroing characters?
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SYNTHESIZE(bool, m_bStoringCharacters, StoringCharacters);
|
2010-09-28 12:14:12 +08:00
|
|
|
/// properties
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
2010-08-27 18:07:37 +08:00
|
|
|
public:
|
2010-08-31 18:11:31 +08:00
|
|
|
CCTMXMapInfo();
|
2010-08-27 18:07:37 +08:00
|
|
|
virtual ~CCTMXMapInfo();
|
|
|
|
/** creates a TMX Format with a tmx file */
|
|
|
|
static CCTMXMapInfo * formatWithTMXFile(const char *tmxFile);
|
|
|
|
/** initializes a TMX format witha tmx file */
|
|
|
|
bool initWithTMXFile(const char *tmxFile);
|
2010-09-28 12:14:12 +08:00
|
|
|
/** initalises parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file */
|
2010-08-27 18:07:37 +08:00
|
|
|
bool parseXMLFile(const char *xmlFilename);
|
2010-09-06 20:26:19 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCDictionary<int, CCStringToStringDictionary*> * getTileProperties();
|
|
|
|
void setTileProperties(CCDictionary<int, CCStringToStringDictionary*> * tileProperties);
|
2010-09-06 20:26:19 +08:00
|
|
|
|
|
|
|
inline const char* getCurrentString(){ return m_sCurrentString.c_str(); }
|
|
|
|
inline void setCurrentString(const char *currentString){ m_sCurrentString = currentString; }
|
2010-09-07 18:04:57 +08:00
|
|
|
inline const char* getTMXFileName(){ return m_sTMXFileName.c_str(); }
|
|
|
|
inline void setTMXFileName(const char *fileName){ m_sTMXFileName = fileName; }
|
2010-08-27 18:07:37 +08:00
|
|
|
|
|
|
|
protected:
|
2010-09-29 12:03:21 +08:00
|
|
|
//! tmx filename
|
2010-09-07 18:04:57 +08:00
|
|
|
std::string m_sTMXFileName;
|
2010-09-29 12:03:21 +08:00
|
|
|
//! current string
|
2010-09-06 20:26:19 +08:00
|
|
|
std::string m_sCurrentString;
|
2010-09-29 12:03:21 +08:00
|
|
|
//! tile properties
|
2011-03-07 18:20:48 +08:00
|
|
|
CCDictionary<int, CCStringToStringDictionary*>* m_pTileProperties;
|
2010-08-27 18:07:37 +08:00
|
|
|
};
|
2010-11-13 11:34:49 +08:00
|
|
|
|
|
|
|
}// namespace cocos2d
|
|
|
|
#endif //__CC_TM_XML_PARSER__
|
|
|
|
|
|
|
|
|
|
|
|
|