2019-11-23 20:27:39 +08:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
Copyright (c) 2011 Максим Аксенов
|
|
|
|
|
Copyright (c) 2009-2010 Ricardo Quesada
|
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
|
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.
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "2d/CCTMXXMLParser.h"
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <sstream>
|
2020-08-28 15:42:40 +08:00
|
|
|
|
// #include "2d/CCTMXTiledMap.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
#include "base/ZipUtils.h"
|
|
|
|
|
#include "base/base64.h"
|
|
|
|
|
#include "base/CCDirector.h"
|
|
|
|
|
#include "platform/CCFileUtils.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
|
|
// implementation TMXLayerInfo
|
|
|
|
|
TMXLayerInfo::TMXLayerInfo()
|
|
|
|
|
: _name("")
|
|
|
|
|
, _tiles(nullptr)
|
|
|
|
|
, _ownTiles(true)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMXLayerInfo::~TMXLayerInfo()
|
|
|
|
|
{
|
|
|
|
|
CCLOGINFO("deallocing TMXLayerInfo: %p", this);
|
|
|
|
|
if (_ownTiles && _tiles)
|
|
|
|
|
{
|
|
|
|
|
free(_tiles);
|
|
|
|
|
_tiles = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValueMap& TMXLayerInfo::getProperties()
|
|
|
|
|
{
|
|
|
|
|
return _properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMXLayerInfo::setProperties(ValueMap var)
|
|
|
|
|
{
|
|
|
|
|
_properties = var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// implementation TMXTilesetInfo
|
|
|
|
|
TMXTilesetInfo::TMXTilesetInfo()
|
|
|
|
|
:_firstGid(0)
|
2021-10-23 23:27:14 +08:00
|
|
|
|
,_tileSize(Vec2::ZERO)
|
2019-11-23 20:27:39 +08:00
|
|
|
|
,_spacing(0)
|
|
|
|
|
,_margin(0)
|
2021-10-23 23:27:14 +08:00
|
|
|
|
,_imageSize(Vec2::ZERO)
|
2019-11-23 20:27:39 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMXTilesetInfo::~TMXTilesetInfo()
|
|
|
|
|
{
|
|
|
|
|
CCLOGINFO("deallocing TMXTilesetInfo: %p", this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rect TMXTilesetInfo::getRectForGID(uint32_t gid)
|
|
|
|
|
{
|
|
|
|
|
Rect rect;
|
|
|
|
|
rect.size = _tileSize;
|
|
|
|
|
gid &= kTMXFlippedMask;
|
|
|
|
|
gid = gid - _firstGid;
|
|
|
|
|
// max_x means the column count in tile map
|
|
|
|
|
// in the origin:
|
|
|
|
|
// max_x = (int)((_imageSize.width - _margin*2 + _spacing) / (_tileSize.width + _spacing));
|
|
|
|
|
// but in editor "Tiled", _margin variable only effect the left side
|
|
|
|
|
// for compatible with "Tiled", change the max_x calculation
|
|
|
|
|
int max_x = (int)((_imageSize.width - _margin + _spacing) / (_tileSize.width + _spacing));
|
|
|
|
|
|
|
|
|
|
rect.origin.x = (gid % max_x) * (_tileSize.width + _spacing) + _margin;
|
|
|
|
|
rect.origin.y = (gid / max_x) * (_tileSize.height + _spacing) + _margin;
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// implementation TMXMapInfo
|
|
|
|
|
|
|
|
|
|
TMXMapInfo * TMXMapInfo::create(const std::string& tmxFile)
|
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
|
TMXMapInfo *ret = new TMXMapInfo();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (ret->initWithTMXFile(tmxFile))
|
|
|
|
|
{
|
|
|
|
|
ret->autorelease();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMXMapInfo * TMXMapInfo::createWithXML(const std::string& tmxString, const std::string& resourcePath)
|
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
|
TMXMapInfo *ret = new TMXMapInfo();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (ret->initWithXML(tmxString, resourcePath))
|
|
|
|
|
{
|
|
|
|
|
ret->autorelease();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string& resourcePath)
|
|
|
|
|
{
|
|
|
|
|
if (!tmxFileName.empty())
|
|
|
|
|
{
|
|
|
|
|
_TMXFileName = FileUtils::getInstance()->fullPathForFilename(tmxFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!resourcePath.empty())
|
|
|
|
|
{
|
|
|
|
|
_resources = resourcePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_objectGroups.reserve(4);
|
|
|
|
|
|
|
|
|
|
// tmp vars
|
|
|
|
|
_currentString = "";
|
|
|
|
|
_storingCharacters = false;
|
|
|
|
|
_layerAttribs = TMXLayerAttribNone;
|
|
|
|
|
_parentElement = TMXPropertyNone;
|
|
|
|
|
_currentFirstGID = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMXMapInfo::initWithXML(const std::string& tmxString, const std::string& resourcePath)
|
|
|
|
|
{
|
|
|
|
|
internalInit("", resourcePath);
|
|
|
|
|
return parseXMLString(tmxString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMXMapInfo::initWithTMXFile(const std::string& tmxFile)
|
|
|
|
|
{
|
|
|
|
|
internalInit(tmxFile, "");
|
|
|
|
|
return parseXMLFile(_TMXFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMXMapInfo::TMXMapInfo()
|
|
|
|
|
: _orientation(TMXOrientationOrtho)
|
|
|
|
|
, _staggerAxis(TMXStaggerAxis_Y)
|
|
|
|
|
, _staggerIndex(TMXStaggerIndex_Even)
|
|
|
|
|
, _hexSideLength(0)
|
2021-10-23 23:27:14 +08:00
|
|
|
|
, _mapSize(Vec2::ZERO)
|
|
|
|
|
, _tileSize(Vec2::ZERO)
|
2019-11-23 20:27:39 +08:00
|
|
|
|
, _parentElement(0)
|
|
|
|
|
, _parentGID(0)
|
|
|
|
|
, _layerAttribs(0)
|
|
|
|
|
, _storingCharacters(false)
|
|
|
|
|
, _xmlTileIndex(0)
|
|
|
|
|
, _currentFirstGID(-1)
|
|
|
|
|
, _recordFirstGID(true)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMXMapInfo::~TMXMapInfo()
|
|
|
|
|
{
|
|
|
|
|
CCLOGINFO("deallocing TMXMapInfo: %p", this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMXMapInfo::parseXMLString(const std::string& xmlString)
|
|
|
|
|
{
|
|
|
|
|
size_t len = xmlString.size();
|
|
|
|
|
if (len <= 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
SAXParser parser;
|
|
|
|
|
|
|
|
|
|
if (false == parser.init("UTF-8") )
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parser.setDelegator(this);
|
|
|
|
|
|
|
|
|
|
return parser.parse(xmlString.c_str(), len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMXMapInfo::parseXMLFile(const std::string& xmlFilename)
|
|
|
|
|
{
|
|
|
|
|
SAXParser parser;
|
|
|
|
|
|
|
|
|
|
if (false == parser.init("UTF-8") )
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parser.setDelegator(this);
|
|
|
|
|
|
|
|
|
|
return parser.parse(FileUtils::getInstance()->fullPathForFilename(xmlFilename));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the XML parser calls here with all the elements
|
|
|
|
|
void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts)
|
|
|
|
|
{
|
|
|
|
|
TMXMapInfo *tmxMapInfo = this;
|
|
|
|
|
std::string elementName = name;
|
|
|
|
|
ValueMap attributeDict;
|
|
|
|
|
if (atts && atts[0])
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; atts[i]; i += 2)
|
|
|
|
|
{
|
|
|
|
|
std::string key = atts[i];
|
|
|
|
|
std::string value = atts[i+1];
|
|
|
|
|
attributeDict.emplace(key, Value(value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (elementName == "map")
|
|
|
|
|
{
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string version = attributeDict["version"].asString();
|
2020-09-01 15:16:01 +08:00
|
|
|
|
CCLOG("cocos2d: TMXFormat: TMX version: %s", version.c_str());
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string orientationStr = attributeDict["orientation"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (orientationStr == "orthogonal") {
|
|
|
|
|
tmxMapInfo->setOrientation(TMXOrientationOrtho);
|
|
|
|
|
}
|
|
|
|
|
else if (orientationStr == "isometric") {
|
|
|
|
|
tmxMapInfo->setOrientation(TMXOrientationIso);
|
|
|
|
|
}
|
|
|
|
|
else if (orientationStr == "hexagonal") {
|
|
|
|
|
tmxMapInfo->setOrientation(TMXOrientationHex);
|
|
|
|
|
}
|
|
|
|
|
else if (orientationStr == "staggered") {
|
|
|
|
|
tmxMapInfo->setOrientation(TMXOrientationStaggered);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", tmxMapInfo->getOrientation());
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string staggerAxisStr = attributeDict["staggeraxis"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (staggerAxisStr == "x") {
|
|
|
|
|
tmxMapInfo->setStaggerAxis(TMXStaggerAxis_X);
|
|
|
|
|
}
|
|
|
|
|
else if (staggerAxisStr == "y") {
|
|
|
|
|
tmxMapInfo->setStaggerAxis(TMXStaggerAxis_Y);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string staggerIndex = attributeDict["staggerindex"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (staggerIndex == "odd") {
|
|
|
|
|
tmxMapInfo->setStaggerIndex(TMXStaggerIndex_Odd);
|
|
|
|
|
}
|
|
|
|
|
else if (staggerIndex == "even") {
|
|
|
|
|
tmxMapInfo->setStaggerIndex(TMXStaggerIndex_Even);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
float hexSideLength = attributeDict["hexsidelength"].asFloat();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
tmxMapInfo->setHexSideLength(hexSideLength);
|
|
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
|
Vec2 s;
|
2020-08-18 11:33:18 +08:00
|
|
|
|
s.width = attributeDict["width"].asFloat();
|
|
|
|
|
s.height = attributeDict["height"].asFloat();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
tmxMapInfo->setMapSize(s);
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
s.width = attributeDict["tilewidth"].asFloat();
|
|
|
|
|
s.height = attributeDict["tileheight"].asFloat();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
tmxMapInfo->setTileSize(s);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The parent element is now "map"
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyMap);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "tileset")
|
|
|
|
|
{
|
|
|
|
|
// If this is an external tileset then start parsing that
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string externalTilesetFilename = attributeDict["source"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (externalTilesetFilename != "")
|
|
|
|
|
{
|
|
|
|
|
_externalTilesetFilename = externalTilesetFilename;
|
|
|
|
|
|
|
|
|
|
// Tileset file will be relative to the map file. So we need to convert it to an absolute path
|
|
|
|
|
if (_TMXFileName.find_last_of('/') != string::npos)
|
|
|
|
|
{
|
|
|
|
|
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of('/') + 1);
|
|
|
|
|
externalTilesetFilename = dir + externalTilesetFilename;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
externalTilesetFilename = _resources + "/" + externalTilesetFilename;
|
|
|
|
|
}
|
|
|
|
|
externalTilesetFilename = FileUtils::getInstance()->fullPathForFilename(externalTilesetFilename);
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
_currentFirstGID = attributeDict["firstgid"].asInt();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (_currentFirstGID < 0)
|
|
|
|
|
{
|
|
|
|
|
_currentFirstGID = 0;
|
|
|
|
|
}
|
|
|
|
|
_recordFirstGID = false;
|
|
|
|
|
|
|
|
|
|
tmxMapInfo->parseXMLFile(externalTilesetFilename);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
|
TMXTilesetInfo *tileset = new TMXTilesetInfo();
|
2020-08-18 11:33:18 +08:00
|
|
|
|
tileset->_name = attributeDict["name"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
|
if (_recordFirstGID)
|
|
|
|
|
{
|
|
|
|
|
// unset before, so this is tmx file.
|
2020-08-18 11:33:18 +08:00
|
|
|
|
tileset->_firstGid = attributeDict["firstgid"].asInt();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
|
if (tileset->_firstGid < 0)
|
|
|
|
|
{
|
|
|
|
|
tileset->_firstGid = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tileset->_firstGid = _currentFirstGID;
|
|
|
|
|
_currentFirstGID = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
tileset->_spacing = attributeDict["spacing"].asInt();
|
|
|
|
|
tileset->_margin = attributeDict["margin"].asInt();
|
2021-10-23 23:27:14 +08:00
|
|
|
|
Vec2 s;
|
2020-08-18 11:33:18 +08:00
|
|
|
|
s.width = attributeDict["tilewidth"].asFloat();
|
|
|
|
|
s.height = attributeDict["tileheight"].asFloat();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
tileset->_tileSize = s;
|
|
|
|
|
|
|
|
|
|
tmxMapInfo->getTilesets().pushBack(tileset);
|
|
|
|
|
tileset->release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "tile")
|
|
|
|
|
{
|
|
|
|
|
if (tmxMapInfo->getParentElement() == TMXPropertyLayer)
|
|
|
|
|
{
|
|
|
|
|
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
|
2021-10-23 23:27:14 +08:00
|
|
|
|
Vec2 layerSize = layer->_layerSize;
|
2020-08-18 11:33:18 +08:00
|
|
|
|
uint32_t gid = static_cast<uint32_t>(attributeDict["gid"].asUnsignedInt());
|
2019-11-23 20:27:39 +08:00
|
|
|
|
int tilesAmount = layerSize.width*layerSize.height;
|
|
|
|
|
|
|
|
|
|
if (_xmlTileIndex < tilesAmount)
|
|
|
|
|
{
|
|
|
|
|
layer->_tiles[_xmlTileIndex++] = gid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TMXTilesetInfo* info = tmxMapInfo->getTilesets().back();
|
2020-08-18 11:33:18 +08:00
|
|
|
|
tmxMapInfo->setParentGID(info->_firstGid + attributeDict["id"].asInt());
|
2019-11-23 20:27:39 +08:00
|
|
|
|
tmxMapInfo->getTileProperties()[tmxMapInfo->getParentGID()] = Value(ValueMap());
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyTile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "layer")
|
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
|
TMXLayerInfo *layer = new TMXLayerInfo();
|
2020-08-18 11:33:18 +08:00
|
|
|
|
layer->_name = attributeDict["name"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
|
Vec2 s;
|
2020-08-18 11:33:18 +08:00
|
|
|
|
s.width = attributeDict["width"].asFloat();
|
|
|
|
|
s.height = attributeDict["height"].asFloat();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
layer->_layerSize = s;
|
|
|
|
|
|
|
|
|
|
Value& visibleValue = attributeDict["visible"];
|
2020-08-18 11:33:18 +08:00
|
|
|
|
layer->_visible = visibleValue.isNull() ? true : visibleValue.asBool();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
|
Value& opacityValue = attributeDict["opacity"];
|
2020-08-18 11:33:18 +08:00
|
|
|
|
layer->_opacity = opacityValue.isNull() ? 255 : (unsigned char)(255.0f * opacityValue.asFloat());
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
float x = attributeDict["x"].asFloat();
|
|
|
|
|
float y = attributeDict["y"].asFloat();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
layer->_offset.set(x, y);
|
|
|
|
|
|
|
|
|
|
tmxMapInfo->getLayers().pushBack(layer);
|
|
|
|
|
layer->release();
|
|
|
|
|
|
|
|
|
|
// The parent element is now "layer"
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyLayer);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "objectgroup")
|
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
|
TMXObjectGroup *objectGroup = new TMXObjectGroup();
|
2020-08-18 11:33:18 +08:00
|
|
|
|
objectGroup->setGroupName(attributeDict["name"].asString());
|
2019-11-23 20:27:39 +08:00
|
|
|
|
Vec2 positionOffset;
|
2020-08-18 11:33:18 +08:00
|
|
|
|
positionOffset.x = attributeDict["x"].asFloat() * tmxMapInfo->getTileSize().width;
|
|
|
|
|
positionOffset.y = attributeDict["y"].asFloat() * tmxMapInfo->getTileSize().height;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
objectGroup->setPositionOffset(positionOffset);
|
|
|
|
|
|
|
|
|
|
tmxMapInfo->getObjectGroups().pushBack(objectGroup);
|
|
|
|
|
objectGroup->release();
|
|
|
|
|
|
|
|
|
|
// The parent element is now "objectgroup"
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyObjectGroup);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "tileoffset")
|
|
|
|
|
{
|
|
|
|
|
TMXTilesetInfo* tileset = tmxMapInfo->getTilesets().back();
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
float tileOffsetX = attributeDict["x"].asFloat();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
float tileOffsetY = attributeDict["y"].asFloat();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
|
tileset->_tileOffset = Vec2(tileOffsetX, tileOffsetY);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "image")
|
|
|
|
|
{
|
|
|
|
|
TMXTilesetInfo* tileset = tmxMapInfo->getTilesets().back();
|
|
|
|
|
|
|
|
|
|
// build full path
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string imagename = attributeDict["source"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
tileset->_originSourceImage = imagename;
|
|
|
|
|
|
|
|
|
|
if (_TMXFileName.find_last_of('/') != string::npos)
|
|
|
|
|
{
|
|
|
|
|
string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of('/') + 1);
|
|
|
|
|
tileset->_sourceImage = dir + imagename;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tileset->_sourceImage = _resources + (_resources.size() ? "/" : "") + imagename;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "data")
|
|
|
|
|
{
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string encoding = attributeDict["encoding"].asString();
|
|
|
|
|
std::string compression = attributeDict["compression"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
|
if (encoding == "")
|
|
|
|
|
{
|
|
|
|
|
tmxMapInfo->setLayerAttribs(tmxMapInfo->getLayerAttribs() | TMXLayerAttribNone);
|
|
|
|
|
|
|
|
|
|
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
|
2021-10-23 23:27:14 +08:00
|
|
|
|
Vec2 layerSize = layer->_layerSize;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
int tilesAmount = layerSize.width*layerSize.height;
|
|
|
|
|
|
|
|
|
|
uint32_t *tiles = (uint32_t*) malloc(tilesAmount*sizeof(uint32_t));
|
|
|
|
|
// set all value to 0
|
|
|
|
|
memset(tiles, 0, tilesAmount*sizeof(int));
|
|
|
|
|
|
|
|
|
|
layer->_tiles = tiles;
|
|
|
|
|
}
|
|
|
|
|
else if (encoding == "base64")
|
|
|
|
|
{
|
|
|
|
|
int layerAttribs = tmxMapInfo->getLayerAttribs();
|
|
|
|
|
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribBase64);
|
|
|
|
|
tmxMapInfo->setStoringCharacters(true);
|
|
|
|
|
|
|
|
|
|
if (compression == "gzip")
|
|
|
|
|
{
|
|
|
|
|
layerAttribs = tmxMapInfo->getLayerAttribs();
|
|
|
|
|
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip);
|
|
|
|
|
} else
|
|
|
|
|
if (compression == "zlib")
|
|
|
|
|
{
|
|
|
|
|
layerAttribs = tmxMapInfo->getLayerAttribs();
|
|
|
|
|
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib);
|
|
|
|
|
}
|
|
|
|
|
CCASSERT( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
|
|
|
|
|
}
|
|
|
|
|
else if (encoding == "csv")
|
|
|
|
|
{
|
|
|
|
|
int layerAttribs = tmxMapInfo->getLayerAttribs();
|
|
|
|
|
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribCSV);
|
|
|
|
|
tmxMapInfo->setStoringCharacters(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "object")
|
|
|
|
|
{
|
|
|
|
|
TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
|
|
|
|
|
|
|
|
|
|
// The value for "type" was blank or not a valid class name
|
|
|
|
|
// Create an instance of TMXObjectInfo to store the object and its properties
|
|
|
|
|
ValueMap dict;
|
|
|
|
|
// Parse everything automatically
|
|
|
|
|
const char* keys[] = {"name", "type", "width", "height", "gid", "id"};
|
|
|
|
|
|
|
|
|
|
for (const auto& key : keys)
|
|
|
|
|
{
|
|
|
|
|
Value value = attributeDict[key];
|
|
|
|
|
dict[key] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// But X and Y since they need special treatment
|
|
|
|
|
// X
|
2020-08-18 11:33:18 +08:00
|
|
|
|
int x = attributeDict["x"].asInt();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
// Y
|
2020-08-18 11:33:18 +08:00
|
|
|
|
int y = attributeDict["y"].asInt();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().y - attributeDict["height"].asInt());
|
2019-11-23 20:27:39 +08:00
|
|
|
|
p = CC_POINT_PIXELS_TO_POINTS(p);
|
|
|
|
|
dict["x"] = Value(p.x);
|
|
|
|
|
dict["y"] = Value(p.y);
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
int width = attributeDict["width"].asInt();
|
|
|
|
|
int height = attributeDict["height"].asInt();
|
2021-10-23 23:27:14 +08:00
|
|
|
|
Vec2 s(width, height);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
s = CC_SIZE_PIXELS_TO_POINTS(s);
|
|
|
|
|
dict["width"] = Value(s.width);
|
|
|
|
|
dict["height"] = Value(s.height);
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
dict["rotation"] = attributeDict["rotation"].asDouble();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
|
// Add the object to the objectGroup
|
|
|
|
|
objectGroup->getObjects().push_back(Value(dict));
|
|
|
|
|
|
|
|
|
|
// The parent element is now "object"
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyObject);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "property")
|
|
|
|
|
{
|
|
|
|
|
if ( tmxMapInfo->getParentElement() == TMXPropertyNone )
|
|
|
|
|
{
|
|
|
|
|
CCLOG( "TMX tile map: Parent element is unsupported. Cannot add property named '%s' with value '%s'",
|
2020-08-18 11:33:18 +08:00
|
|
|
|
attributeDict["name"].asString().c_str(), attributeDict["value"].asString().c_str() );
|
2019-11-23 20:27:39 +08:00
|
|
|
|
}
|
|
|
|
|
else if ( tmxMapInfo->getParentElement() == TMXPropertyMap )
|
|
|
|
|
{
|
|
|
|
|
// The parent element is the map
|
|
|
|
|
Value value = attributeDict["value"];
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string key = attributeDict["name"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
tmxMapInfo->getProperties().emplace(key, value);
|
|
|
|
|
}
|
|
|
|
|
else if ( tmxMapInfo->getParentElement() == TMXPropertyLayer )
|
|
|
|
|
{
|
|
|
|
|
// The parent element is the last layer
|
|
|
|
|
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
|
|
|
|
|
Value value = attributeDict["value"];
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string key = attributeDict["name"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
// Add the property to the layer
|
|
|
|
|
layer->getProperties().emplace(key, value);
|
|
|
|
|
}
|
|
|
|
|
else if ( tmxMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
|
|
|
|
{
|
|
|
|
|
// The parent element is the last object group
|
|
|
|
|
TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
|
|
|
|
|
Value value = attributeDict["value"];
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string key = attributeDict["name"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
objectGroup->getProperties().emplace(key, value);
|
|
|
|
|
}
|
|
|
|
|
else if ( tmxMapInfo->getParentElement() == TMXPropertyObject )
|
|
|
|
|
{
|
|
|
|
|
// The parent element is the last object
|
|
|
|
|
TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
|
|
|
|
|
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string propertyName = attributeDict["name"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
dict[propertyName] = attributeDict["value"];
|
|
|
|
|
}
|
|
|
|
|
else if ( tmxMapInfo->getParentElement() == TMXPropertyTile )
|
|
|
|
|
{
|
|
|
|
|
ValueMap& dict = tmxMapInfo->getTileProperties().at(tmxMapInfo->getParentGID()).asValueMap();
|
|
|
|
|
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string propertyName = attributeDict["name"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
dict[propertyName] = attributeDict["value"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "polygon")
|
|
|
|
|
{
|
|
|
|
|
// find parent object's dict and add polygon-points to it
|
|
|
|
|
TMXObjectGroup* objectGroup = _objectGroups.back();
|
|
|
|
|
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
|
|
|
|
|
|
|
|
|
// get points value string
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string value = attributeDict["points"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (!value.empty())
|
|
|
|
|
{
|
|
|
|
|
ValueVector pointsArray;
|
|
|
|
|
pointsArray.reserve(10);
|
|
|
|
|
|
|
|
|
|
// parse points string into a space-separated set of points
|
|
|
|
|
stringstream pointsStream(value);
|
|
|
|
|
string pointPair;
|
|
|
|
|
while (std::getline(pointsStream, pointPair, ' '))
|
|
|
|
|
{
|
|
|
|
|
// parse each point combo into a comma-separated x,y point
|
|
|
|
|
stringstream pointStream(pointPair);
|
|
|
|
|
string xStr, yStr;
|
|
|
|
|
|
|
|
|
|
ValueMap pointDict;
|
|
|
|
|
|
|
|
|
|
// set x
|
|
|
|
|
if (std::getline(pointStream, xStr, ','))
|
|
|
|
|
{
|
|
|
|
|
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
|
|
|
|
pointDict["x"] = Value(x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set y
|
|
|
|
|
if (std::getline(pointStream, yStr, ','))
|
|
|
|
|
{
|
|
|
|
|
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
|
|
|
|
pointDict["y"] = Value(y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add to points array
|
|
|
|
|
pointsArray.push_back(Value(pointDict));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dict["points"] = Value(pointsArray);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "polyline")
|
|
|
|
|
{
|
|
|
|
|
// find parent object's dict and add polyline-points to it
|
|
|
|
|
TMXObjectGroup* objectGroup = _objectGroups.back();
|
|
|
|
|
ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
|
|
|
|
|
|
|
|
|
|
// get points value string
|
2020-08-18 11:33:18 +08:00
|
|
|
|
std::string value = attributeDict["points"].asString();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
if (!value.empty())
|
|
|
|
|
{
|
|
|
|
|
ValueVector pointsArray;
|
|
|
|
|
pointsArray.reserve(10);
|
|
|
|
|
|
|
|
|
|
// parse points string into a space-separated set of points
|
|
|
|
|
stringstream pointsStream(value);
|
|
|
|
|
string pointPair;
|
|
|
|
|
while (std::getline(pointsStream, pointPair, ' '))
|
|
|
|
|
{
|
|
|
|
|
// parse each point combo into a comma-separated x,y point
|
|
|
|
|
stringstream pointStream(pointPair);
|
|
|
|
|
string xStr, yStr;
|
|
|
|
|
|
|
|
|
|
ValueMap pointDict;
|
|
|
|
|
|
|
|
|
|
// set x
|
|
|
|
|
if (std::getline(pointStream, xStr, ','))
|
|
|
|
|
{
|
|
|
|
|
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
|
|
|
|
pointDict["x"] = Value(x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set y
|
|
|
|
|
if (std::getline(pointStream, yStr, ','))
|
|
|
|
|
{
|
|
|
|
|
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
|
|
|
|
pointDict["y"] = Value(y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add to points array
|
|
|
|
|
pointsArray.push_back(Value(pointDict));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dict["polylinePoints"] = Value(pointsArray);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-28 16:33:52 +08:00
|
|
|
|
else if (elementName == "animation")
|
|
|
|
|
{
|
|
|
|
|
TMXTilesetInfo* info = tmxMapInfo->getTilesets().back();
|
|
|
|
|
info->_animationInfo.insert(tmxMapInfo->getParentGID(), TMXTileAnimInfo::create(tmxMapInfo->getParentGID()));
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyAnimation);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "frame")
|
|
|
|
|
{
|
|
|
|
|
TMXTilesetInfo* info = tmxMapInfo->getTilesets().back();
|
|
|
|
|
auto animInfo = info->_animationInfo.at(tmxMapInfo->getParentGID());
|
|
|
|
|
// calculate gid of frame
|
|
|
|
|
animInfo->_frames.emplace_back(TMXTileAnimFrame(info->_firstGid + attributeDict["tileid"].asInt(), attributeDict["duration"].asFloat()));
|
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMXMapInfo::endElement(void* /*ctx*/, const char *name)
|
|
|
|
|
{
|
|
|
|
|
TMXMapInfo *tmxMapInfo = this;
|
|
|
|
|
std::string elementName = name;
|
|
|
|
|
|
|
|
|
|
if (elementName == "data")
|
|
|
|
|
{
|
|
|
|
|
if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribBase64)
|
|
|
|
|
{
|
|
|
|
|
tmxMapInfo->setStoringCharacters(false);
|
|
|
|
|
|
|
|
|
|
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
|
|
|
|
|
|
|
|
|
|
std::string currentString = tmxMapInfo->getCurrentString();
|
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
auto len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
|
|
|
|
|
if (!buffer)
|
|
|
|
|
{
|
|
|
|
|
CCLOG("cocos2d: TiledMap: decode data error");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tmxMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib))
|
|
|
|
|
{
|
|
|
|
|
unsigned char *deflated = nullptr;
|
2021-10-23 23:27:14 +08:00
|
|
|
|
Vec2 s = layer->_layerSize;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
// int sizeHint = s.width * s.height * sizeof(uint32_t);
|
|
|
|
|
ssize_t sizeHint = s.width * s.height * sizeof(unsigned int);
|
|
|
|
|
|
|
|
|
|
ssize_t CC_UNUSED inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
|
|
|
|
|
CCASSERT(inflatedLen == sizeHint, "inflatedLen should be equal to sizeHint!");
|
|
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
buffer = nullptr;
|
|
|
|
|
|
|
|
|
|
if (!deflated)
|
|
|
|
|
{
|
|
|
|
|
CCLOG("cocos2d: TiledMap: inflate data error");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layer->_tiles = reinterpret_cast<uint32_t*>(deflated);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmxMapInfo->setCurrentString("");
|
|
|
|
|
}
|
|
|
|
|
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribCSV)
|
|
|
|
|
{
|
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
|
|
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
|
|
|
|
|
|
|
|
|
|
tmxMapInfo->setStoringCharacters(false);
|
|
|
|
|
std::string currentString = tmxMapInfo->getCurrentString();
|
|
|
|
|
|
|
|
|
|
vector<string> gidTokens;
|
|
|
|
|
istringstream filestr(currentString);
|
|
|
|
|
string sRow;
|
|
|
|
|
while(getline(filestr, sRow, '\n')) {
|
|
|
|
|
string sGID;
|
|
|
|
|
istringstream rowstr(sRow);
|
|
|
|
|
while (getline(rowstr, sGID, ',')) {
|
|
|
|
|
gidTokens.push_back(sGID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 32-bits per gid
|
|
|
|
|
buffer = (unsigned char*)malloc(gidTokens.size() * 4);
|
|
|
|
|
if (!buffer)
|
|
|
|
|
{
|
|
|
|
|
CCLOG("cocos2d: TiledMap: CSV buffer not allocated.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t* bufferPtr = reinterpret_cast<uint32_t*>(buffer);
|
|
|
|
|
for(const auto& gidToken : gidTokens) {
|
|
|
|
|
auto tileGid = (uint32_t)strtoul(gidToken.c_str(), nullptr, 10);
|
|
|
|
|
*bufferPtr = tileGid;
|
|
|
|
|
bufferPtr++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
|
|
|
|
|
|
|
|
|
|
tmxMapInfo->setCurrentString("");
|
|
|
|
|
}
|
|
|
|
|
else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribNone)
|
|
|
|
|
{
|
|
|
|
|
_xmlTileIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "map")
|
|
|
|
|
{
|
|
|
|
|
// The map element has ended
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyNone);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "layer")
|
|
|
|
|
{
|
|
|
|
|
// The layer element has ended
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyNone);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "objectgroup")
|
|
|
|
|
{
|
|
|
|
|
// The objectgroup element has ended
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyNone);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "object")
|
|
|
|
|
{
|
|
|
|
|
// The object element has ended
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyNone);
|
|
|
|
|
}
|
|
|
|
|
else if (elementName == "tileset")
|
|
|
|
|
{
|
|
|
|
|
_recordFirstGID = true;
|
|
|
|
|
}
|
2020-08-28 16:33:52 +08:00
|
|
|
|
else if (elementName == "animation")
|
|
|
|
|
{
|
|
|
|
|
tmxMapInfo->setParentElement(TMXPropertyNone);
|
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMXMapInfo::textHandler(void* /*ctx*/, const char *ch, size_t len)
|
|
|
|
|
{
|
|
|
|
|
TMXMapInfo *tmxMapInfo = this;
|
|
|
|
|
std::string text(ch, 0, len);
|
|
|
|
|
|
|
|
|
|
if (tmxMapInfo->isStoringCharacters())
|
|
|
|
|
{
|
|
|
|
|
std::string currentString = tmxMapInfo->getCurrentString();
|
|
|
|
|
currentString += text;
|
|
|
|
|
tmxMapInfo->setCurrentString(currentString);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 16:33:52 +08:00
|
|
|
|
TMXTileAnimFrame::TMXTileAnimFrame(uint32_t tileID, float duration)
|
|
|
|
|
: _tileID(tileID)
|
|
|
|
|
, _duration(duration)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMXTileAnimInfo::TMXTileAnimInfo(uint32_t tileID)
|
|
|
|
|
: _tileID(tileID)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMXTileAnimInfo* TMXTileAnimInfo::create(uint32_t tileID)
|
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
|
TMXTileAnimInfo* ret = new TMXTileAnimInfo(tileID);
|
|
|
|
|
ret->autorelease();
|
|
|
|
|
return ret;
|
2020-08-28 16:33:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
|
NS_CC_END
|