mirror of https://github.com/axmolengine/axmol.git
fixed #129, use NSString to make dictionary
This commit is contained in:
parent
4a52e5aaf9
commit
1c1971255e
|
@ -60,12 +60,6 @@ namespace cocos2d {
|
|||
*/
|
||||
class CCX_DLL CCTMXLayer : public CCSpriteSheet
|
||||
{
|
||||
/** name of the layer */
|
||||
protected:
|
||||
std::string m_sLayerName;
|
||||
public:
|
||||
inline const char* getLayerName(){ return m_sLayerName.c_str(); }
|
||||
inline void setLayerName(const char *layerName){ m_sLayerName = layerName; }
|
||||
/** size of the layer in tiles */
|
||||
CCX_SYNTHESIZE(CGSize, m_tLayerSize, LayerSize);
|
||||
/** size of the map's tile (could be differnt from the tile's size) */
|
||||
|
@ -77,7 +71,7 @@ namespace cocos2d {
|
|||
/** Layer orientation, which is the same as the map orientation */
|
||||
CCX_SYNTHESIZE(int, m_nLayerOrientation, LayerOrientation);
|
||||
/** properties from the layer. They can be added using Tiled */
|
||||
CCX_SYNTHESIZE(StringToStringDictionary*, m_pProperties, Properties);
|
||||
CCX_PROPERTY(StringToStringDictionary*, m_pProperties, Properties);
|
||||
public:
|
||||
CCTMXLayer();
|
||||
virtual ~CCTMXLayer();
|
||||
|
@ -120,7 +114,7 @@ namespace cocos2d {
|
|||
CGPoint positionAt(CGPoint tileCoordinate);
|
||||
|
||||
/** return the value for the specific property name */
|
||||
const char *propertyNamed(const char *propertyName);
|
||||
NSString *propertyNamed(const char *propertyName);
|
||||
|
||||
/** Creates the tiles */
|
||||
void setupTiles();
|
||||
|
@ -132,6 +126,9 @@ namespace cocos2d {
|
|||
// super method
|
||||
void removeChild(CCNode* child, bool cleanup);
|
||||
void draw();
|
||||
|
||||
inline const char* getLayerName(){ return m_sLayerName.c_str(); }
|
||||
inline void setLayerName(const char *layerName){ m_sLayerName = layerName; }
|
||||
private:
|
||||
CGPoint positionForIsoAt(CGPoint pos);
|
||||
CGPoint positionForOrthoAt(CGPoint pos);
|
||||
|
@ -152,6 +149,9 @@ namespace cocos2d {
|
|||
unsigned int atlasIndexForExistantZ(unsigned int z);
|
||||
unsigned int atlasIndexForNewZ(int z);
|
||||
protected:
|
||||
/** name of the layer */
|
||||
std::string m_sLayerName;
|
||||
|
||||
unsigned char m_cOpacity; // TMX Layer supports opacity
|
||||
|
||||
unsigned int m_uMinGID;
|
||||
|
|
|
@ -23,48 +23,42 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
#ifndef __CCTMX_OBJECT_GROUP_H__
|
||||
#define __CCTMX_OBJECT_GROUP_H__
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "Cocos2dDefine.h"
|
||||
#include "CGGeometry.h"
|
||||
#include "NSString.h"
|
||||
#include "NSMutableArray.h"
|
||||
#include "NSMutableDictionary.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
typedef std::map<std::string, std::string> StringToStringDictionary;
|
||||
typedef std::pair<std::string, std::string> StringToStringPair;
|
||||
/** only used in StringToStringDictionary, return "" if not found*/
|
||||
CCX_DLL const char * valueForKey(const char* key, StringToStringDictionary *dict);
|
||||
|
||||
/** CCTMXObjectGroup represents the TMX object group.
|
||||
@since v0.99.0
|
||||
*/
|
||||
class CCX_DLL CCTMXObjectGroup : public NSObject
|
||||
{
|
||||
/** name of the group */
|
||||
protected:
|
||||
std::string m_sGroupName;
|
||||
public:
|
||||
inline const char* getGroupName(){ return m_sGroupName.c_str(); }
|
||||
inline void setGroupName(const char *groupName){ m_sGroupName = groupName; }
|
||||
/** offset position of child objects */
|
||||
CCX_SYNTHESIZE(CGPoint, m_tPositionOffset, PositionOffset);
|
||||
/** array of the objects */
|
||||
CCX_SYNTHESIZE(std::vector<StringToStringDictionary*>*, m_pObjects, Objects);
|
||||
/** list of properties stored in a dictionary */
|
||||
CCX_SYNTHESIZE(StringToStringDictionary*, m_pProperties, Properties);
|
||||
CCX_PROPERTY(StringToStringDictionary*, m_pProperties, Properties);
|
||||
/** array of the objects */
|
||||
CCX_PROPERTY(NSArray<StringToStringDictionary*>*, m_pObjects, Objects);
|
||||
public:
|
||||
CCTMXObjectGroup();
|
||||
virtual ~CCTMXObjectGroup();
|
||||
|
||||
inline const char* getGroupName(){ return m_sGroupName.c_str(); }
|
||||
inline void setGroupName(const char *groupName){ m_sGroupName = groupName; }
|
||||
|
||||
/** return the value for the specific property name */
|
||||
const char *propertyNamed(const char* propertyName);
|
||||
NSString *propertyNamed(const char* propertyName);
|
||||
|
||||
/** return the dictionary for the specific object name.
|
||||
It will return the 1st object found on the array for the given name.
|
||||
*/
|
||||
StringToStringDictionary *objectNamed(const char *objectName);
|
||||
protected:
|
||||
/** name of the group */
|
||||
std::string m_sGroupName;
|
||||
};
|
||||
|
||||
}// namespace cocos2d
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace cocos2d {
|
|||
/** object groups */
|
||||
CCX_PROPERTY(NSMutableArray<CCTMXObjectGroup*>*, m_pObjectGroups, ObjectGroups);
|
||||
/** properties */
|
||||
CCX_SYNTHESIZE(StringToStringDictionary*, m_pProperties, Properties);
|
||||
CCX_PROPERTY(StringToStringDictionary*, m_pProperties, Properties);
|
||||
public:
|
||||
CCTMXTiledMap();
|
||||
virtual ~CCTMXTiledMap();
|
||||
|
@ -131,10 +131,10 @@ namespace cocos2d {
|
|||
CCTMXObjectGroup* groupNamed(const char *groupName);
|
||||
|
||||
/** return the value for the specific property name */
|
||||
const char *propertyNamed(const char *propertyName);
|
||||
NSString *propertyNamed(const char *propertyName);
|
||||
|
||||
/** return properties dictionary for tile GID */
|
||||
StringToStringDictionary *propertiesForGID(int GID);
|
||||
NSDictionary<std::string, NSString*> *propertiesForGID(int GID);
|
||||
|
||||
private:
|
||||
CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
|
||||
|
@ -142,7 +142,7 @@ namespace cocos2d {
|
|||
|
||||
protected:
|
||||
// tile properties
|
||||
std::map<int, StringToStringDictionary*> *m_pTileProperties;
|
||||
NSDictionary<int, StringToStringDictionary*> *m_pTileProperties;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -23,8 +23,10 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
#ifndef __CC_TM_XML_PARSER__
|
||||
#define __CC_TM_XML_PARSER__
|
||||
#include "CCTMXObjectGroup.h"
|
||||
#include "NSMutableArray.h"
|
||||
#include "NSMutableDictionary.h"
|
||||
#include "CGGeometry.h"
|
||||
#include "Cocos2dDefine.h"
|
||||
namespace cocos2d {
|
||||
|
||||
/*
|
||||
|
@ -117,14 +119,10 @@ namespace cocos2d {
|
|||
This information is obtained from the TMX file.
|
||||
|
||||
*/
|
||||
class CCTMXObjectGroup;
|
||||
class CCX_DLL CCTMXMapInfo : public NSObject
|
||||
{
|
||||
// tmx filename
|
||||
protected:
|
||||
std::string m_sFileName;
|
||||
public:
|
||||
inline const char* getFileName(){ return m_sFileName.c_str(); }
|
||||
inline void setFileName(const char *fileName){ m_sFileName = fileName; }
|
||||
// map orientation
|
||||
CCX_SYNTHESIZE(int, m_nOrientation, Orientation);
|
||||
// map width & height
|
||||
|
@ -143,16 +141,10 @@ namespace cocos2d {
|
|||
CCX_SYNTHESIZE(unsigned int, m_uParentGID, ParentGID);
|
||||
// layer attribs
|
||||
CCX_SYNTHESIZE(int, m_nLayerAttribs, LayerAttribs);
|
||||
// current string
|
||||
protected:
|
||||
std::string m_sCurrentString;
|
||||
public:
|
||||
inline const char* getCurrentString(){ return m_sCurrentString.c_str(); }
|
||||
inline void setCurrentString(const char *currentString){ m_sCurrentString = currentString; }
|
||||
// is stroing characters?
|
||||
CCX_SYNTHESIZE(bool, m_bStoringCharacters, StoringCharacters);
|
||||
// properties
|
||||
CCX_SYNTHESIZE(StringToStringDictionary*, m_pProperties, Properties);
|
||||
CCX_PROPERTY(StringToStringDictionary*, m_pProperties, Properties);
|
||||
public:
|
||||
CCTMXMapInfo();
|
||||
virtual ~CCTMXMapInfo();
|
||||
|
@ -162,12 +154,22 @@ namespace cocos2d {
|
|||
bool initWithTMXFile(const char *tmxFile);
|
||||
/* initalises parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file */
|
||||
bool parseXMLFile(const char *xmlFilename);
|
||||
|
||||
NSDictionary<int, StringToStringDictionary*> * getTileProperties();
|
||||
void setTileProperties(NSDictionary<int, StringToStringDictionary*> * tileProperties);
|
||||
|
||||
inline const char* getCurrentString(){ return m_sCurrentString.c_str(); }
|
||||
inline void setCurrentString(const char *currentString){ m_sCurrentString = currentString; }
|
||||
inline const char* getFileName(){ return m_sFileName.c_str(); }
|
||||
inline void setFileName(const char *fileName){ m_sFileName = fileName; }
|
||||
|
||||
inline std::map<int, StringToStringDictionary*>* getTileProperties(){return m_pTileProperties;}
|
||||
inline void setTileProperties(std::map<int, StringToStringDictionary*> * var){m_pTileProperties = var;}
|
||||
protected:
|
||||
// tmx filename
|
||||
std::string m_sFileName;
|
||||
// current string
|
||||
std::string m_sCurrentString;
|
||||
// tile properties
|
||||
std::map<int, StringToStringDictionary*>* m_pTileProperties;
|
||||
NSDictionary<int, StringToStringDictionary*>* m_pTileProperties;
|
||||
};
|
||||
|
||||
}// namespace cocos2d
|
||||
|
|
|
@ -221,6 +221,7 @@ public:
|
|||
};
|
||||
|
||||
#define NSDictionary NSMutableDictionary
|
||||
typedef NSDictionary<std::string, NSString*> StringToStringDictionary;
|
||||
}//namespace cocos2d
|
||||
|
||||
|
||||
|
|
|
@ -35,11 +35,19 @@ namespace cocos2d {
|
|||
NSString()
|
||||
:m_sString("")
|
||||
{}
|
||||
NSString(const char * str)
|
||||
{
|
||||
m_sString = str;
|
||||
}
|
||||
virtual ~NSString(){ m_sString.clear(); }
|
||||
int toInt()
|
||||
{
|
||||
return atoi(m_sString.c_str());
|
||||
}
|
||||
unsigned int toUInt()
|
||||
{
|
||||
return (unsigned int)atoi(m_sString.c_str());
|
||||
}
|
||||
float toFloat()
|
||||
{
|
||||
return (float)atof(m_sString.c_str());
|
||||
|
|
|
@ -65,15 +65,7 @@ namespace cocos2d {
|
|||
m_uMinGID = layerInfo->m_uMinGID;
|
||||
m_uMaxGID = layerInfo->m_uMaxGID;
|
||||
m_cOpacity = layerInfo->m_cOpacity;
|
||||
m_pProperties = new StringToStringDictionary();
|
||||
if (layerInfo->m_pProperties && layerInfo->m_pProperties->size()>0)
|
||||
{
|
||||
StringToStringDictionary::iterator it;
|
||||
for (it = layerInfo->m_pProperties->begin(); it != layerInfo->m_pProperties->end(); ++it)
|
||||
{
|
||||
m_pProperties->insert(StringToStringPair(it->first, it->second));
|
||||
}
|
||||
}
|
||||
m_pProperties = StringToStringDictionary::dictionaryWithDictionary(layerInfo->m_pProperties);
|
||||
|
||||
// tilesetInfo
|
||||
m_pTileSet = tilesetInfo;
|
||||
|
@ -112,12 +104,7 @@ namespace cocos2d {
|
|||
{
|
||||
CCX_SAFE_RELEASE(m_pTileSet);
|
||||
CCX_SAFE_RELEASE(m_pReusedTile);
|
||||
if (m_pProperties)
|
||||
{
|
||||
m_pProperties->clear();
|
||||
delete m_pProperties;
|
||||
m_pProperties = NULL;
|
||||
}
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
|
||||
if( m_pAtlasIndexArray )
|
||||
{
|
||||
|
@ -204,29 +191,32 @@ namespace cocos2d {
|
|||
}
|
||||
|
||||
// CCTMXLayer - Properties
|
||||
const char *CCTMXLayer::propertyNamed(const char *propertyName)
|
||||
NSString *CCTMXLayer::propertyNamed(const char *propertyName)
|
||||
{
|
||||
return valueForKey(propertyName, m_pProperties);
|
||||
return m_pProperties->objectForKey(propertyName);
|
||||
}
|
||||
void CCTMXLayer::parseInternalProperties()
|
||||
{
|
||||
// if cc_vertex=automatic, then tiles will be rendered using vertexz
|
||||
|
||||
std::string vertexz = propertyNamed("cc_vertexz");
|
||||
if( vertexz != "" )
|
||||
NSString *vertexz = propertyNamed("cc_vertexz");
|
||||
if( vertexz )
|
||||
{
|
||||
if( vertexz == "automatic" )
|
||||
if( vertexz->m_sString == "automatic" )
|
||||
{
|
||||
m_bUseAutomaticVertexZ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nVertexZvalue = atoi(vertexz.c_str());
|
||||
m_nVertexZvalue = vertexz->toInt();
|
||||
}
|
||||
}
|
||||
|
||||
std::string alphaFuncVal = propertyNamed("cc_alpha_func");
|
||||
m_fAlphaFuncValue = (float)atof(alphaFuncVal.c_str());
|
||||
NSString *alphaFuncVal = propertyNamed("cc_alpha_func");
|
||||
if (alphaFuncVal)
|
||||
{
|
||||
m_fAlphaFuncValue = alphaFuncVal->toFloat();
|
||||
}
|
||||
}
|
||||
|
||||
// CCTMXLayer - obtaining tiles/gids
|
||||
|
@ -633,6 +623,16 @@ namespace cocos2d {
|
|||
}
|
||||
}
|
||||
|
||||
StringToStringDictionary * CCTMXLayer::getProperties()
|
||||
{
|
||||
return m_pProperties;
|
||||
}
|
||||
void CCTMXLayer::setProperties(StringToStringDictionary* var)
|
||||
{
|
||||
CCX_SAFE_RETAIN(m_pProperties);
|
||||
m_pProperties = var;
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
}
|
||||
|
||||
}// namespace cocos2d
|
||||
|
||||
|
|
|
@ -25,63 +25,62 @@ THE SOFTWARE.
|
|||
#include "ccMacros.h"
|
||||
namespace cocos2d {
|
||||
|
||||
const char * valueForKey(const char* key, StringToStringDictionary *dict)
|
||||
{
|
||||
std::string pKey = key;
|
||||
if (!dict)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
StringToStringDictionary::iterator it = dict->find(pKey);
|
||||
return it!=dict->end() ? it->second.c_str() : "";
|
||||
}
|
||||
|
||||
//implementation CCTMXObjectGroup
|
||||
|
||||
CCTMXObjectGroup::CCTMXObjectGroup()
|
||||
:m_sGroupName("")
|
||||
,m_tPositionOffset(CGPointZero)
|
||||
{
|
||||
m_pObjects = new std::vector<StringToStringDictionary*>();
|
||||
m_pObjects = new NSArray<StringToStringDictionary*>();
|
||||
m_pProperties = new StringToStringDictionary();
|
||||
}
|
||||
CCTMXObjectGroup::~CCTMXObjectGroup()
|
||||
{
|
||||
CCLOGINFO( "cocos2d: deallocing.");
|
||||
if (m_pProperties)
|
||||
{
|
||||
m_pProperties->clear();
|
||||
delete m_pProperties;
|
||||
m_pProperties = NULL;
|
||||
}
|
||||
if (m_pObjects)
|
||||
{
|
||||
std::vector<StringToStringDictionary*>::iterator it;
|
||||
for (it = m_pObjects->begin(); it != m_pObjects->end(); ++it)
|
||||
{
|
||||
CCX_SAFE_DELETE(*it);
|
||||
}
|
||||
m_pObjects->clear();
|
||||
delete m_pObjects;
|
||||
m_pObjects = NULL;
|
||||
}
|
||||
CCX_SAFE_RELEASE(m_pObjects);
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
}
|
||||
StringToStringDictionary * CCTMXObjectGroup::objectNamed(const char *objectName)
|
||||
{
|
||||
std::vector<StringToStringDictionary*>::iterator it;
|
||||
for (it = m_pObjects->begin(); it != m_pObjects->end(); ++it)
|
||||
if (m_pObjects && m_pObjects->count() > 0)
|
||||
{
|
||||
if ( *it && strcmp(valueForKey("name", *it), objectName)==0 )
|
||||
NSArray<StringToStringDictionary*>::NSMutableArrayIterator it;
|
||||
for (it = m_pObjects->begin(); it != m_pObjects->end(); ++it)
|
||||
{
|
||||
return *it;
|
||||
NSString *name = (*it)->objectForKey("name");
|
||||
if (name && name->m_sString == objectName)
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
}
|
||||
// object not found
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
const char *CCTMXObjectGroup::propertyNamed(const char* propertyName)
|
||||
NSString *CCTMXObjectGroup::propertyNamed(const char* propertyName)
|
||||
{
|
||||
return valueForKey(propertyName, m_pProperties);
|
||||
return m_pProperties->objectForKey(propertyName);
|
||||
}
|
||||
|
||||
StringToStringDictionary * CCTMXObjectGroup::getProperties()
|
||||
{
|
||||
return m_pProperties;
|
||||
}
|
||||
void CCTMXObjectGroup::setProperties(StringToStringDictionary * properties)
|
||||
{
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
m_pProperties = properties;
|
||||
CCX_SAFE_RETAIN(m_pProperties);
|
||||
}
|
||||
NSArray<StringToStringDictionary*> *CCTMXObjectGroup::getObjects()
|
||||
{
|
||||
return m_pObjects;
|
||||
}
|
||||
void CCTMXObjectGroup::setObjects(NSArray<StringToStringDictionary*> * objects)
|
||||
{
|
||||
CCX_SAFE_RELEASE(m_pObjects);
|
||||
m_pObjects = objects;
|
||||
CCX_SAFE_RETAIN(m_pObjects);
|
||||
}
|
||||
|
||||
}// namespace cocos2d
|
|
@ -96,28 +96,9 @@ namespace cocos2d{
|
|||
}
|
||||
CCTMXTiledMap::~CCTMXTiledMap()
|
||||
{
|
||||
m_pObjectGroups->release();
|
||||
if (m_pProperties)
|
||||
{
|
||||
m_pProperties->clear();
|
||||
delete m_pProperties;
|
||||
m_pProperties = NULL;
|
||||
}
|
||||
if (m_pTileProperties)
|
||||
{
|
||||
std::map<int, StringToStringDictionary*>::iterator it;
|
||||
for (it = m_pTileProperties->begin(); it != m_pTileProperties->end(); ++it)
|
||||
{
|
||||
if (it->second)
|
||||
{
|
||||
it->second->clear();
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
m_pTileProperties->clear();
|
||||
delete m_pTileProperties;
|
||||
m_pTileProperties = NULL;
|
||||
}
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
CCX_SAFE_RELEASE(m_pObjectGroups);
|
||||
CCX_SAFE_RELEASE(m_pTileProperties);
|
||||
}
|
||||
NSMutableArray<CCTMXObjectGroup*> * CCTMXTiledMap::getObjectGroups()
|
||||
{
|
||||
|
@ -129,6 +110,16 @@ namespace cocos2d{
|
|||
m_pObjectGroups = var;
|
||||
CCX_SAFE_RETAIN(m_pObjectGroups);
|
||||
}
|
||||
StringToStringDictionary * CCTMXTiledMap::getProperties()
|
||||
{
|
||||
return m_pProperties;
|
||||
}
|
||||
void CCTMXTiledMap::setProperties(StringToStringDictionary* var)
|
||||
{
|
||||
CCX_SAFE_RETAIN(m_pProperties);
|
||||
m_pProperties = var;
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
}
|
||||
// private
|
||||
CCTMXLayer * CCTMXTiledMap::parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
|
||||
{
|
||||
|
@ -238,17 +229,15 @@ namespace cocos2d{
|
|||
{
|
||||
return objectGroupNamed(groupName);
|
||||
}
|
||||
const char * CCTMXTiledMap::propertyNamed(const char *propertyName)
|
||||
NSString * CCTMXTiledMap::propertyNamed(const char *propertyName)
|
||||
{
|
||||
return valueForKey(propertyName, m_pProperties);
|
||||
return m_pProperties->objectForKey(propertyName);
|
||||
}
|
||||
StringToStringDictionary * CCTMXTiledMap::propertiesForGID(int GID)
|
||||
NSDictionary<std::string, NSString*> * CCTMXTiledMap::propertiesForGID(int GID)
|
||||
{
|
||||
std::map<int, StringToStringDictionary*>::iterator it;
|
||||
it = m_pTileProperties->find(GID);
|
||||
return it!=m_pTileProperties->end() ? it->second : NULL;
|
||||
return m_pTileProperties->objectForKey(GID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}// namespace cocos2d
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ THE SOFTWARE.
|
|||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/xmlmemory.h>
|
||||
#include <map>
|
||||
#include "CCTMXXMLParser.h"
|
||||
#include "CCTMXTiledMap.h"
|
||||
#include "ccMacros.h"
|
||||
|
@ -37,7 +38,15 @@ namespace cocos2d {
|
|||
void tmx_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
||||
void tmx_endElement(void *ctx, const xmlChar *name);
|
||||
void tmx_characters(void *ctx, const xmlChar *ch, int len);
|
||||
|
||||
const char* valueForKey(const char *key, std::map<std::string, std::string>* dict)
|
||||
{
|
||||
if (dict)
|
||||
{
|
||||
std::map<std::string, std::string>::iterator it = dict->find(key);
|
||||
return it!=dict->end() ? it->second.c_str() : "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
// implementation CCTMXLayerInfo
|
||||
CCTMXLayerInfo::CCTMXLayerInfo()
|
||||
:m_bOwnTiles(true)
|
||||
|
@ -52,12 +61,7 @@ namespace cocos2d {
|
|||
CCTMXLayerInfo::~CCTMXLayerInfo()
|
||||
{
|
||||
CCLOGINFO("cocos2d: deallocing.");
|
||||
if (m_pProperties)
|
||||
{
|
||||
m_pProperties->clear();
|
||||
delete m_pProperties;
|
||||
m_pProperties = NULL;
|
||||
}
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
if( m_bOwnTiles && m_pTiles )
|
||||
{
|
||||
delete [] m_pTiles;
|
||||
|
@ -110,7 +114,7 @@ namespace cocos2d {
|
|||
m_sFileName = CCFileUtils::fullPathFromRelativePath(tmxFile);
|
||||
m_pObjectGroups = new NSMutableArray<CCTMXObjectGroup*>();
|
||||
m_pProperties = new StringToStringDictionary();
|
||||
m_pTileProperties = new std::map<int, StringToStringDictionary*>();
|
||||
m_pTileProperties = new NSDictionary<int, StringToStringDictionary*>();
|
||||
|
||||
// tmp vars
|
||||
m_sCurrentString = "";
|
||||
|
@ -132,30 +136,11 @@ namespace cocos2d {
|
|||
CCTMXMapInfo::~CCTMXMapInfo()
|
||||
{
|
||||
CCLOGINFO("cocos2d: deallocing.");
|
||||
m_pTilesets->release();
|
||||
m_pLayers->release();
|
||||
m_pObjectGroups->release();
|
||||
if (m_pProperties)
|
||||
{
|
||||
m_pProperties->clear();
|
||||
delete m_pProperties;
|
||||
m_pProperties = NULL;
|
||||
}
|
||||
if (m_pTileProperties)
|
||||
{
|
||||
std::map<int, StringToStringDictionary*>::iterator it;
|
||||
for (it = m_pTileProperties->begin(); it != m_pTileProperties->end(); ++it)
|
||||
{
|
||||
if (it->second)
|
||||
{
|
||||
it->second->clear();
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
m_pTileProperties->clear();
|
||||
delete m_pTileProperties;
|
||||
m_pTileProperties = NULL;
|
||||
}
|
||||
CCX_SAFE_RELEASE(m_pTilesets);
|
||||
CCX_SAFE_RELEASE(m_pLayers);
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
CCX_SAFE_RELEASE(m_pTileProperties);
|
||||
CCX_SAFE_RELEASE(m_pObjectGroups);
|
||||
}
|
||||
NSMutableArray<CCTMXLayerInfo*> * CCTMXMapInfo::getLayers()
|
||||
{
|
||||
|
@ -187,6 +172,27 @@ namespace cocos2d {
|
|||
m_pObjectGroups = var;
|
||||
CCX_SAFE_RETAIN(m_pObjectGroups);
|
||||
}
|
||||
StringToStringDictionary * CCTMXMapInfo::getProperties()
|
||||
{
|
||||
return m_pProperties;
|
||||
}
|
||||
void CCTMXMapInfo::setProperties(StringToStringDictionary* var)
|
||||
{
|
||||
CCX_SAFE_RELEASE(m_pProperties);
|
||||
m_pProperties = var;
|
||||
CCX_SAFE_RETAIN(m_pProperties);
|
||||
}
|
||||
NSDictionary<int, StringToStringDictionary*> * CCTMXMapInfo::getTileProperties()
|
||||
{
|
||||
return m_pTileProperties;
|
||||
}
|
||||
void CCTMXMapInfo::setTileProperties(NSDictionary<int, StringToStringDictionary*> * tileProperties)
|
||||
{
|
||||
CCX_SAFE_RELEASE(m_pTileProperties);
|
||||
m_pTileProperties = tileProperties;
|
||||
CCX_SAFE_RETAIN(m_pTileProperties);
|
||||
}
|
||||
|
||||
bool CCTMXMapInfo::parseXMLFile(const char *xmlFilename)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
|
@ -237,14 +243,14 @@ namespace cocos2d {
|
|||
{
|
||||
CCTMXMapInfo *pTMXMapInfo = (CCTMXMapInfo*)(ctx);
|
||||
std::string elementName = (char*)name;
|
||||
StringToStringDictionary *attributeDict = new StringToStringDictionary();
|
||||
std::map<std::string, std::string> *attributeDict = new std::map<std::string, std::string>();
|
||||
if(atts && atts[0])
|
||||
{
|
||||
for(int i = 0; atts[i]; i += 2)
|
||||
{
|
||||
std::string key = (char*)atts[i];
|
||||
std::string value = (char*)atts[i+1];
|
||||
attributeDict->insert(StringToStringPair(key, value));
|
||||
attributeDict->insert(pair<std::string, std::string>(key, value));
|
||||
}
|
||||
}
|
||||
if(elementName == "map")
|
||||
|
@ -306,8 +312,8 @@ namespace cocos2d {
|
|||
CCTMXTilesetInfo* info = pTMXMapInfo->getTilesets()->getLastObject();
|
||||
StringToStringDictionary *dict = new StringToStringDictionary();
|
||||
pTMXMapInfo->setParentGID(info->m_uFirstGid + atoi(valueForKey("id", attributeDict)));
|
||||
pTMXMapInfo->getTileProperties()->insert(std::pair<int, StringToStringDictionary*>(pTMXMapInfo->getParentGID(), dict));
|
||||
|
||||
pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
|
||||
|
||||
pTMXMapInfo->setParentElement(TMXPropertyTile);
|
||||
|
||||
}
|
||||
|
@ -402,40 +408,45 @@ namespace cocos2d {
|
|||
|
||||
// Set the name of the object to the value for "name"
|
||||
std::string key = "name";
|
||||
std::string value = valueForKey("name", attributeDict);
|
||||
dict->insert(StringToStringPair(key, value));
|
||||
NSString *value = new NSString(valueForKey("name", attributeDict));
|
||||
dict->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
// Assign all the attributes as key/name pairs in the properties dictionary
|
||||
key = "type";
|
||||
value = valueForKey("type", attributeDict);
|
||||
dict->insert(StringToStringPair(key, value));
|
||||
value = new NSString(valueForKey("type", attributeDict));
|
||||
dict->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
int x = atoi(valueForKey("x", attributeDict)) + (int)objectGroup->getPositionOffset().x;
|
||||
key = "x";
|
||||
/*value = itoa(x, buffer, 10);*/
|
||||
sprintf(buffer, "%d", x);
|
||||
value = buffer;
|
||||
dict->insert(StringToStringPair(key, value));
|
||||
value = new NSString(buffer);
|
||||
dict->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
int y = atoi(valueForKey("y", attributeDict)) + (int)objectGroup->getPositionOffset().y;
|
||||
// Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
|
||||
y = (int)(pTMXMapInfo->getMapSize().height * pTMXMapInfo->getTileSize().height) - y - atoi(valueForKey("height", attributeDict));
|
||||
key = "y";
|
||||
/*value = itoa(y, buffer, 10);*/
|
||||
sprintf(buffer, "%d", y);
|
||||
value = buffer;
|
||||
dict->insert(StringToStringPair(key, value));
|
||||
value = new NSString(buffer);
|
||||
dict->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
key = "width";
|
||||
value = valueForKey("width", attributeDict);
|
||||
dict->insert(StringToStringPair(key, value));
|
||||
value = new NSString(valueForKey("width", attributeDict));
|
||||
dict->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
key = "height";
|
||||
value = valueForKey("height", attributeDict);
|
||||
dict->insert(StringToStringPair(key, value));
|
||||
value = new NSString(valueForKey("height", attributeDict));
|
||||
dict->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
// Add the object to the objectGroup
|
||||
objectGroup->getObjects()->insert(objectGroup->getObjects()->begin(), dict);
|
||||
objectGroup->getObjects()->addObject(dict);
|
||||
dict->release();
|
||||
|
||||
// The parent element is now "object"
|
||||
pTMXMapInfo->setParentElement(TMXPropertyObject);
|
||||
|
@ -451,48 +462,53 @@ namespace cocos2d {
|
|||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyMap )
|
||||
{
|
||||
// The parent element is the map
|
||||
std::string value = valueForKey("value", attributeDict);
|
||||
NSString *value = new NSString(valueForKey("value", attributeDict));
|
||||
std::string key = valueForKey("name", attributeDict);
|
||||
pTMXMapInfo->getProperties()->insert(StringToStringPair(key, value));
|
||||
pTMXMapInfo->getProperties()->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
}
|
||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
|
||||
{
|
||||
// The parent element is the last layer
|
||||
CCTMXLayerInfo *layer = pTMXMapInfo->getLayers()->getLastObject();
|
||||
std::string value = valueForKey("value", attributeDict);
|
||||
NSString *value = new NSString(valueForKey("value", attributeDict));
|
||||
std::string key = valueForKey("name", attributeDict);
|
||||
// Add the property to the layer
|
||||
layer->m_pProperties->insert(StringToStringPair(key, value));
|
||||
layer->m_pProperties->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
}
|
||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
||||
{
|
||||
// The parent element is the last object group
|
||||
CCTMXObjectGroup *objectGroup = pTMXMapInfo->getObjectGroups()->getLastObject();
|
||||
NSString *value = new NSString(valueForKey("value", attributeDict));
|
||||
std::string key = valueForKey("name", attributeDict);
|
||||
std::string value = valueForKey("value", attributeDict);
|
||||
objectGroup->getProperties()->insert(StringToStringPair(key, value));
|
||||
objectGroup->getProperties()->setObject(value, key);
|
||||
value->release();
|
||||
|
||||
}
|
||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
|
||||
{
|
||||
// The parent element is the last object
|
||||
CCTMXObjectGroup *objectGroup = pTMXMapInfo->getObjectGroups()->getLastObject();
|
||||
StringToStringDictionary *dict = *objectGroup->getObjects()->begin();
|
||||
StringToStringDictionary *dict = objectGroup->getObjects()->getLastObject();
|
||||
|
||||
std::string propertyName = valueForKey("name", attributeDict);
|
||||
std::string propertyValue = valueForKey("value", attributeDict);
|
||||
|
||||
dict->insert(StringToStringPair(propertyName, propertyValue));
|
||||
NSString *propertyValue = new NSString(valueForKey("value", attributeDict));
|
||||
dict->setObject(propertyValue, propertyName);
|
||||
propertyValue->release();
|
||||
}
|
||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile )
|
||||
{
|
||||
StringToStringDictionary *dict;
|
||||
dict = pTMXMapInfo->getTileProperties()->find(pTMXMapInfo->getParentGID())->second;
|
||||
dict = pTMXMapInfo->getTileProperties()->objectForKey(pTMXMapInfo->getParentGID());
|
||||
|
||||
std::string propertyName = valueForKey("name", attributeDict);
|
||||
std::string propertyValue = valueForKey("value", attributeDict);
|
||||
dict->insert(StringToStringPair(propertyName, propertyValue));
|
||||
NSString *propertyValue = new NSString(valueForKey("value", attributeDict));
|
||||
dict->setObject(propertyValue, propertyName);
|
||||
propertyValue->release();
|
||||
}
|
||||
}
|
||||
if (attributeDict)
|
||||
|
|
|
@ -604,10 +604,10 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest()
|
|||
|
||||
////----UXLOG("----> Iterating over all the group objets");
|
||||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||
std::vector<StringToStringDictionary*> * objects = group->getObjects();
|
||||
NSArray<StringToStringDictionary*> * objects = group->getObjects();
|
||||
|
||||
StringToStringDictionary* dict;
|
||||
std::vector<StringToStringDictionary*>::iterator it;
|
||||
NSArray<StringToStringDictionary*>::NSMutableArrayIterator it;
|
||||
for( it = objects->begin(); it != objects->end(); it++)
|
||||
{
|
||||
dict = (*it);//dynamic_cast<StringToStringDictionary*>(*it);
|
||||
|
@ -628,9 +628,9 @@ void TMXOrthoObjectsTest::draw()
|
|||
CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
||||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||
|
||||
std::vector<StringToStringDictionary*> * objects = group->getObjects();
|
||||
NSArray<StringToStringDictionary*> * objects = group->getObjects();
|
||||
StringToStringDictionary* dict;
|
||||
std::vector<StringToStringDictionary*>::iterator it;
|
||||
NSArray<StringToStringDictionary*>::NSMutableArrayIterator it;
|
||||
|
||||
for( it = objects->begin(); it != objects->end(); it++)
|
||||
{
|
||||
|
@ -638,11 +638,14 @@ void TMXOrthoObjectsTest::draw()
|
|||
|
||||
if(!dict)
|
||||
break;
|
||||
|
||||
int x = atoi(valueForKey("x", dict));
|
||||
int y = atoi(valueForKey("y", dict));//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
||||
int width = atoi(valueForKey("width", dict));//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
||||
int height = atoi(valueForKey("height", dict));//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
||||
std::string key = "x";
|
||||
int x = dict->objectForKey(key)->toInt();
|
||||
key = "y";
|
||||
int y = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
||||
key = "width";
|
||||
int width = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
||||
key = "height";
|
||||
int height = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
||||
|
||||
glLineWidth(3);
|
||||
|
||||
|
@ -683,11 +686,11 @@ TMXIsoObjectsTest::TMXIsoObjectsTest()
|
|||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||
|
||||
//UxMutableArray* objects = group->objects();
|
||||
std::vector<StringToStringDictionary*> * objects = group->getObjects();
|
||||
NSArray<StringToStringDictionary*> * objects = group->getObjects();
|
||||
//UxMutableDictionary<std::string>* dict;
|
||||
StringToStringDictionary* dict;
|
||||
//NSMutableArray<NSObject*>::NSMutableArrayIterator it;
|
||||
std::vector<StringToStringDictionary*>::iterator it;
|
||||
NSArray<StringToStringDictionary*>::NSMutableArrayIterator it;
|
||||
|
||||
for( it = objects->begin(); it != objects->end(); it++)
|
||||
{
|
||||
|
@ -705,9 +708,9 @@ void TMXIsoObjectsTest::draw()
|
|||
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
||||
CCTMXObjectGroup *group = map->objectGroupNamed("Object Group 1");
|
||||
|
||||
std::vector<StringToStringDictionary*> * objects = group->getObjects();
|
||||
NSArray<StringToStringDictionary*> * objects = group->getObjects();
|
||||
StringToStringDictionary* dict;
|
||||
std::vector<StringToStringDictionary*>::iterator it;
|
||||
NSArray<StringToStringDictionary*>::NSMutableArrayIterator it;
|
||||
|
||||
for( it = objects->begin(); it != objects->end(); it++)
|
||||
{
|
||||
|
@ -715,11 +718,14 @@ void TMXIsoObjectsTest::draw()
|
|||
|
||||
if(!dict)
|
||||
break;
|
||||
|
||||
int x = atoi(valueForKey("x", dict));//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
|
||||
int y = atoi(valueForKey("y", dict));//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
||||
int width = atoi(valueForKey("width", dict));//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
||||
int height = atoi(valueForKey("height", dict));//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
||||
std::string key = "x";
|
||||
int x = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
|
||||
key = "y";
|
||||
int y = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
||||
key = "width";
|
||||
int width = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
||||
key = "height";
|
||||
int height = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
||||
|
||||
glLineWidth(3);
|
||||
|
||||
|
|
Loading…
Reference in New Issue