/*
* TMXCopy
* Copyright (C) 2007 Philipp Sehmisch
* Copyright (C) 2009 Steve Cotton
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include "xmlutils.h"
#include "zlibutils.h"
#include "base64.h"
#include "tostring.h"
#include "map.hpp"
Map::Map(std::string filename):
mMaxGid(0)
{
std::cout<<"Loading map "<name, BAD_CAST "map")) {
std::cerr<name, BAD_CAST "tileset"))
{
//add tilesets to vector of used tilesets
Tileset* tileset = new Tileset;
tileset->name = XML::getProperty(node, "name", "Unnamed");
tileset->tilewidth = XML::getProperty(node, "tilewidth", 0);
tileset->tileheight = XML::getProperty(node, "tileheight", 0);
tileset->firstgid = XML::getProperty(node, "firstgid", 0);
for_each_xml_child_node(imageNode, node)
{
if (xmlStrEqual(imageNode->name, BAD_CAST "image"))
tileset->imagefile = XML::getProperty(imageNode, "source", "");
}
//add tileset to tileset list
Map::mTilesets.push_back(tileset);
}
}
for_each_xml_child_node(node, rootNode)
{
if (xmlStrEqual(node->name, BAD_CAST "layer"))
{
//build layer information
std::string name = XML::getProperty(node, "name", "");
Layer* layer = new Layer(name, mWidth * mHeight);
if (
(mWidth != XML::getProperty(node, "width" , 0)) ||
(mHeight != XML::getProperty(node, "height", 0)) ||
(0 != XML::getProperty(node, "x" , 0)) ||
(0 != XML::getProperty(node, "y" , 0)))
{
std::cerr<<"Error: layer size does not match map size for layer \""<name, BAD_CAST "data")) continue;
std::string encoding = XML::getProperty(dataNode, "encoding", "");
std::string compression = XML::getProperty(dataNode, "compression", "");
if (encoding != "base64")
{
std::cerr<<"Layers in "<xmlChildrenNode;
if (!dataChild)
continue;
int len = strlen((const char*)dataChild->content) + 1;
unsigned char *charData = new unsigned char[len + 1];
const char *charStart = (const char*)dataChild->content;
unsigned char *charIndex = charData;
while (*charStart) {
if (*charStart != ' ' && *charStart != '\t' &&
*charStart != '\n')
{
*charIndex = *charStart;
charIndex++;
}
charStart++;
}
*charIndex = '\0';
int binLen;
unsigned char *binData =
php3_base64_decode(charData, strlen((char*)charData), &binLen);
delete[] charData;
if (binData) {
if (compression == "gzip")
{
unsigned char *inflated;
unsigned int inflatedSize =
inflateMemory(binData, binLen, inflated);
free(binData);
binData = inflated;
binLen = inflatedSize;
if (inflated == NULL)
{
std::cerr<<"Error: while decompressing layer "<at(c).tileset = -1;
layer->at(c).index = 0;
}
else
{
for (int s = mTilesets.size()-1; s >= 0; s--)
{
if (mTilesets.at(s)->firstgid <= gid)
{
layer->at(c).tileset = s;
layer->at(c).index = gid - mTilesets.at(s)->firstgid;
if (mMaxGid < gid) mMaxGid = gid;
break;
}
}
}
c++;
}
free(binData);
} else {
std::cerr<<"error processing layer data in "< Map::addAndTranslateTilesets(const Map* srcMap)
{
std::map translation;
translation[-1] = -1;
std::vector* srcTilesets = const_cast