mirror of https://github.com/axmolengine/axmol.git
Add missing white spaces and some minor cleanups
* Add missing white space * Fix if-else statement without curly braces * Fix indentation * Clean up code
This commit is contained in:
parent
abeb269534
commit
279604bac5
|
@ -51,7 +51,7 @@ TMXLayerInfo::TMXLayerInfo()
|
||||||
TMXLayerInfo::~TMXLayerInfo()
|
TMXLayerInfo::~TMXLayerInfo()
|
||||||
{
|
{
|
||||||
CCLOGINFO("deallocing TMXLayerInfo: %p", this);
|
CCLOGINFO("deallocing TMXLayerInfo: %p", this);
|
||||||
if( _ownTiles && _tiles )
|
if (_ownTiles && _tiles)
|
||||||
{
|
{
|
||||||
free(_tiles);
|
free(_tiles);
|
||||||
_tiles = nullptr;
|
_tiles = nullptr;
|
||||||
|
@ -62,6 +62,7 @@ ValueMap& TMXLayerInfo::getProperties()
|
||||||
{
|
{
|
||||||
return _properties;
|
return _properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TMXLayerInfo::setProperties(ValueMap var)
|
void TMXLayerInfo::setProperties(ValueMap var)
|
||||||
{
|
{
|
||||||
_properties = var;
|
_properties = var;
|
||||||
|
@ -100,7 +101,7 @@ Rect TMXTilesetInfo::getRectForGID(uint32_t gid)
|
||||||
TMXMapInfo * TMXMapInfo::create(const std::string& tmxFile)
|
TMXMapInfo * TMXMapInfo::create(const std::string& tmxFile)
|
||||||
{
|
{
|
||||||
TMXMapInfo *ret = new (std::nothrow) TMXMapInfo();
|
TMXMapInfo *ret = new (std::nothrow) TMXMapInfo();
|
||||||
if(ret->initWithTMXFile(tmxFile))
|
if (ret->initWithTMXFile(tmxFile))
|
||||||
{
|
{
|
||||||
ret->autorelease();
|
ret->autorelease();
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -112,7 +113,7 @@ TMXMapInfo * TMXMapInfo::create(const std::string& tmxFile)
|
||||||
TMXMapInfo * TMXMapInfo::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
TMXMapInfo * TMXMapInfo::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||||
{
|
{
|
||||||
TMXMapInfo *ret = new (std::nothrow) TMXMapInfo();
|
TMXMapInfo *ret = new (std::nothrow) TMXMapInfo();
|
||||||
if(ret->initWithXML(tmxString, resourcePath))
|
if (ret->initWithXML(tmxString, resourcePath))
|
||||||
{
|
{
|
||||||
ret->autorelease();
|
ret->autorelease();
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -142,6 +143,7 @@ void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string&
|
||||||
_parentElement = TMXPropertyNone;
|
_parentElement = TMXPropertyNone;
|
||||||
_currentFirstGID = -1;
|
_currentFirstGID = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMXMapInfo::initWithXML(const std::string& tmxString, const std::string& resourcePath)
|
bool TMXMapInfo::initWithXML(const std::string& tmxString, const std::string& resourcePath)
|
||||||
{
|
{
|
||||||
internalInit("", resourcePath);
|
internalInit("", resourcePath);
|
||||||
|
@ -202,7 +204,6 @@ bool TMXMapInfo::parseXMLFile(const std::string& xmlFilename)
|
||||||
return parser.parse(FileUtils::getInstance()->fullPathForFilename(xmlFilename).c_str());
|
return parser.parse(FileUtils::getInstance()->fullPathForFilename(xmlFilename).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// the XML parser calls here with all the elements
|
// the XML parser calls here with all the elements
|
||||||
void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
{
|
{
|
||||||
|
@ -212,7 +213,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
ValueMap attributeDict;
|
ValueMap attributeDict;
|
||||||
if (atts && atts[0])
|
if (atts && atts[0])
|
||||||
{
|
{
|
||||||
for(int i = 0; atts[i]; i += 2)
|
for (int i = 0; atts[i]; i += 2)
|
||||||
{
|
{
|
||||||
std::string key = atts[i];
|
std::string key = atts[i];
|
||||||
std::string value = atts[i+1];
|
std::string value = atts[i+1];
|
||||||
|
@ -227,16 +228,21 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
CCLOG("cocos2d: TMXFormat: Unsupported TMX version: %s", version.c_str());
|
CCLOG("cocos2d: TMXFormat: Unsupported TMX version: %s", version.c_str());
|
||||||
}
|
}
|
||||||
std::string orientationStr = attributeDict["orientation"].asString();
|
std::string orientationStr = attributeDict["orientation"].asString();
|
||||||
if (orientationStr == "orthogonal")
|
if (orientationStr == "orthogonal") {
|
||||||
tmxMapInfo->setOrientation(TMXOrientationOrtho);
|
tmxMapInfo->setOrientation(TMXOrientationOrtho);
|
||||||
else if (orientationStr == "isometric")
|
}
|
||||||
|
else if (orientationStr == "isometric") {
|
||||||
tmxMapInfo->setOrientation(TMXOrientationIso);
|
tmxMapInfo->setOrientation(TMXOrientationIso);
|
||||||
else if(orientationStr == "hexagonal")
|
}
|
||||||
|
else if (orientationStr == "hexagonal") {
|
||||||
tmxMapInfo->setOrientation(TMXOrientationHex);
|
tmxMapInfo->setOrientation(TMXOrientationHex);
|
||||||
else if(orientationStr == "staggered")
|
}
|
||||||
|
else if (orientationStr == "staggered") {
|
||||||
tmxMapInfo->setOrientation(TMXOrientationStaggered);
|
tmxMapInfo->setOrientation(TMXOrientationStaggered);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", tmxMapInfo->getOrientation());
|
CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", tmxMapInfo->getOrientation());
|
||||||
|
}
|
||||||
|
|
||||||
Size s;
|
Size s;
|
||||||
s.width = attributeDict["width"].asFloat();
|
s.width = attributeDict["width"].asFloat();
|
||||||
|
@ -356,7 +362,6 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
|
|
||||||
// The parent element is now "layer"
|
// The parent element is now "layer"
|
||||||
tmxMapInfo->setParentElement(TMXPropertyLayer);
|
tmxMapInfo->setParentElement(TMXPropertyLayer);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (elementName == "objectgroup")
|
else if (elementName == "objectgroup")
|
||||||
{
|
{
|
||||||
|
@ -372,7 +377,6 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
|
|
||||||
// The parent element is now "objectgroup"
|
// The parent element is now "objectgroup"
|
||||||
tmxMapInfo->setParentElement(TMXPropertyObjectGroup);
|
tmxMapInfo->setParentElement(TMXPropertyObjectGroup);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (elementName == "image")
|
else if (elementName == "image")
|
||||||
{
|
{
|
||||||
|
@ -416,7 +420,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribBase64);
|
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribBase64);
|
||||||
tmxMapInfo->setStoringCharacters(true);
|
tmxMapInfo->setStoringCharacters(true);
|
||||||
|
|
||||||
if( compression == "gzip" )
|
if (compression == "gzip")
|
||||||
{
|
{
|
||||||
layerAttribs = tmxMapInfo->getLayerAttribs();
|
layerAttribs = tmxMapInfo->getLayerAttribs();
|
||||||
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip);
|
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip);
|
||||||
|
@ -428,7 +432,6 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
}
|
}
|
||||||
CCASSERT( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
|
CCASSERT( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (elementName == "object")
|
else if (elementName == "object")
|
||||||
{
|
{
|
||||||
|
@ -440,7 +443,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
// Parse everything automatically
|
// Parse everything automatically
|
||||||
const char* array[] = {"name", "type", "width", "height", "gid"};
|
const char* array[] = {"name", "type", "width", "height", "gid"};
|
||||||
|
|
||||||
for(size_t i = 0; i < sizeof(array)/sizeof(array[0]); ++i )
|
for (size_t i = 0; i < sizeof(array)/sizeof(array[0]); ++i)
|
||||||
{
|
{
|
||||||
const char* key = array[i];
|
const char* key = array[i];
|
||||||
Value value = attributeDict[key];
|
Value value = attributeDict[key];
|
||||||
|
@ -470,7 +473,6 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
|
|
||||||
// The parent element is now "object"
|
// The parent element is now "object"
|
||||||
tmxMapInfo->setParentElement(TMXPropertyObject);
|
tmxMapInfo->setParentElement(TMXPropertyObject);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (elementName == "property")
|
else if (elementName == "property")
|
||||||
{
|
{
|
||||||
|
@ -536,23 +538,23 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
// parse points string into a space-separated set of points
|
// parse points string into a space-separated set of points
|
||||||
stringstream pointsStream(value);
|
stringstream pointsStream(value);
|
||||||
string pointPair;
|
string pointPair;
|
||||||
while(std::getline(pointsStream, pointPair, ' '))
|
while (std::getline(pointsStream, pointPair, ' '))
|
||||||
{
|
{
|
||||||
// parse each point combo into a comma-separated x,y point
|
// parse each point combo into a comma-separated x,y point
|
||||||
stringstream pointStream(pointPair);
|
stringstream pointStream(pointPair);
|
||||||
string xStr,yStr;
|
string xStr, yStr;
|
||||||
|
|
||||||
ValueMap pointDict;
|
ValueMap pointDict;
|
||||||
|
|
||||||
// set x
|
// set x
|
||||||
if(std::getline(pointStream, xStr, ','))
|
if (std::getline(pointStream, xStr, ','))
|
||||||
{
|
{
|
||||||
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
||||||
pointDict["x"] = Value(x);
|
pointDict["x"] = Value(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set y
|
// set y
|
||||||
if(std::getline(pointStream, yStr, ','))
|
if (std::getline(pointStream, yStr, ','))
|
||||||
{
|
{
|
||||||
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
||||||
pointDict["y"] = Value(y);
|
pointDict["y"] = Value(y);
|
||||||
|
@ -581,23 +583,23 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
// parse points string into a space-separated set of points
|
// parse points string into a space-separated set of points
|
||||||
stringstream pointsStream(value);
|
stringstream pointsStream(value);
|
||||||
string pointPair;
|
string pointPair;
|
||||||
while(std::getline(pointsStream, pointPair, ' '))
|
while (std::getline(pointsStream, pointPair, ' '))
|
||||||
{
|
{
|
||||||
// parse each point combo into a comma-separated x,y point
|
// parse each point combo into a comma-separated x,y point
|
||||||
stringstream pointStream(pointPair);
|
stringstream pointStream(pointPair);
|
||||||
string xStr,yStr;
|
string xStr, yStr;
|
||||||
|
|
||||||
ValueMap pointDict;
|
ValueMap pointDict;
|
||||||
|
|
||||||
// set x
|
// set x
|
||||||
if(std::getline(pointStream, xStr, ','))
|
if (std::getline(pointStream, xStr, ','))
|
||||||
{
|
{
|
||||||
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
||||||
pointDict["x"] = Value(x);
|
pointDict["x"] = Value(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set y
|
// set y
|
||||||
if(std::getline(pointStream, yStr, ','))
|
if (std::getline(pointStream, yStr, ','))
|
||||||
{
|
{
|
||||||
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
||||||
pointDict["y"] = Value(y);
|
pointDict["y"] = Value(y);
|
||||||
|
@ -620,7 +622,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
if(elementName == "data")
|
if (elementName == "data")
|
||||||
{
|
{
|
||||||
if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribBase64)
|
if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribBase64)
|
||||||
{
|
{
|
||||||
|
@ -631,13 +633,13 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
std::string currentString = tmxMapInfo->getCurrentString();
|
std::string currentString = tmxMapInfo->getCurrentString();
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
|
len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
|
||||||
if( ! buffer )
|
if (!buffer)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: TiledMap: decode data error");
|
CCLOG("cocos2d: TiledMap: decode data error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( tmxMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib) )
|
if (tmxMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib))
|
||||||
{
|
{
|
||||||
unsigned char *deflated = nullptr;
|
unsigned char *deflated = nullptr;
|
||||||
Size s = layer->_layerSize;
|
Size s = layer->_layerSize;
|
||||||
|
@ -650,7 +652,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
buffer = nullptr;
|
buffer = nullptr;
|
||||||
|
|
||||||
if( ! deflated )
|
if (!deflated)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: TiledMap: inflate data error");
|
CCLOG("cocos2d: TiledMap: inflate data error");
|
||||||
return;
|
return;
|
||||||
|
@ -669,7 +671,6 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
{
|
{
|
||||||
_xmlTileIndex = 0;
|
_xmlTileIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (elementName == "map")
|
else if (elementName == "map")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue