summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-16 22:06:21 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-16 22:18:16 +0300
commite3ce2827f14efc6630a4c2932b60e23d9b0321b0 (patch)
tree3919c09ad3461b934d92daf95051e22eb8c6f20d
parentf5eba43704cfda82cff4229aecf6ebce99029bda (diff)
downloadmanaverse-e3ce2827f14efc6630a4c2932b60e23d9b0321b0.tar.gz
manaverse-e3ce2827f14efc6630a4c2932b60e23d9b0321b0.tar.bz2
manaverse-e3ce2827f14efc6630a4c2932b60e23d9b0321b0.tar.xz
manaverse-e3ce2827f14efc6630a4c2932b60e23d9b0321b0.zip
read map layers based on layer types.
-rw-r--r--src/maplayer.h7
-rw-r--r--src/resources/mapreader.cpp94
-rw-r--r--src/resources/mapreader.h4
3 files changed, 68 insertions, 37 deletions
diff --git a/src/maplayer.h b/src/maplayer.h
index a994ab4bc..410be05fa 100644
--- a/src/maplayer.h
+++ b/src/maplayer.h
@@ -87,6 +87,13 @@ class MapObjectList final
class MapLayer final: public ConfigListener
{
public:
+ enum Type
+ {
+ TILES,
+ COLLISION,
+ HEIGHTS
+ };
+
friend class Map;
/**
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 327f356ac..3ab6c49fe 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -27,7 +27,6 @@
#include "logger.h"
#include "main.h"
#include "map.h"
-#include "maplayer.h"
#include "tileset.h"
#include "resources/animation.h"
@@ -419,54 +418,66 @@ void MapReader::readProperties(const XmlNodePtr node, Properties *const props)
}
inline static void setTile(Map *const map, MapLayer *const layer,
+ const MapLayer::Type &layerType,
const int x, const int y, const int gid)
{
const Tileset * const set = map->getTilesetWithGid(gid);
- if (layer)
+ switch (layerType)
{
- // Set regular tile on a layer
- Image * const img = set ? set->get(gid - set->getFirstGid()) : nullptr;
- layer->setTile(x, y, img);
- }
- else
- {
- // Set collision tile
- if (set)
+ case MapLayer::TILES:
+ {
+ Image *const img = set ? set->get(gid - set->getFirstGid())
+ : nullptr;
+ layer->setTile(x, y, img);
+ break;
+ }
+
+ case MapLayer::COLLISION:
{
- if (map->getVersion() >= 1)
+ if (set)
{
- switch (gid - set->getFirstGid())
+ if (map->getVersion() >= 1)
{
- case Map::COLLISION_EMPTY:
- map->blockTile(x, y, Map::BLOCKTYPE_GROUND);
- break;
- case Map::COLLISION_WALL:
+ switch (gid - set->getFirstGid())
+ {
+ case Map::COLLISION_EMPTY:
+ map->blockTile(x, y, Map::BLOCKTYPE_GROUND);
+ break;
+ case Map::COLLISION_WALL:
+ map->blockTile(x, y, Map::BLOCKTYPE_WALL);
+ break;
+ case Map::COLLISION_AIR:
+ map->blockTile(x, y, Map::BLOCKTYPE_AIR);
+ break;
+ case Map::COLLISION_WATER:
+ map->blockTile(x, y, Map::BLOCKTYPE_WATER);
+ break;
+ case Map::COLLISION_GROUNDTOP:
+ map->blockTile(x, y, Map::BLOCKTYPE_GROUNDTOP);
+ break;
+ default:
+ break;
+ }
+ }
+ else
+ {
+ if (gid - set->getFirstGid() != 0)
map->blockTile(x, y, Map::BLOCKTYPE_WALL);
- break;
- case Map::COLLISION_AIR:
- map->blockTile(x, y, Map::BLOCKTYPE_AIR);
- break;
- case Map::COLLISION_WATER:
- map->blockTile(x, y, Map::BLOCKTYPE_WATER);
- break;
- case Map::COLLISION_GROUNDTOP:
- map->blockTile(x, y, Map::BLOCKTYPE_GROUNDTOP);
- break;
- default:
- break;
}
}
- else
- {
- if (gid - set->getFirstGid() != 0)
- map->blockTile(x, y, Map::BLOCKTYPE_WALL);
- }
+ break;
}
+
+ case MapLayer::HEIGHTS:
+ break;
+
+ default:
+ break;
}
}
#define addTile() \
- setTile(map, layer, x, y, gid); \
+ setTile(map, layer, layerType, x, y, gid); \
if (hasAnimations) \
{ \
TileAnimationMapCIter it = tileAnimations.find(gid); \
@@ -480,6 +491,7 @@ inline static void setTile(Map *const map, MapLayer *const layer,
bool MapReader::readBase64Layer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
+ const MapLayer::Type &layerType,
const std::string &compression,
int &x, int &y, const int w, const int h)
{
@@ -579,6 +591,7 @@ bool MapReader::readBase64Layer(const XmlNodePtr childNode, Map *const map,
bool MapReader::readCsvLayer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
+ const MapLayer::Type &layerType,
int &x, int &y, const int w, const int h)
{
XmlNodePtr dataChild = childNode->xmlChildrenNode;
@@ -634,6 +647,13 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
const bool isFringeLayer = (name.substr(0, 6) == "fringe");
const bool isCollisionLayer = (name.substr(0, 9) == "collision");
+ const bool isHeightLayer = (name.substr(0, 7) == "heights");
+
+ MapLayer::Type layerType = MapLayer::TILES;
+ if (isCollisionLayer)
+ layerType = MapLayer::COLLISION;
+ else if (isHeightLayer)
+ layerType = MapLayer::HEIGHTS;
map->indexTilesets();
@@ -667,7 +687,7 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
if (!xmlNameEqual(childNode, "data"))
continue;
- if (!isCollisionLayer)
+ if (layerType == MapLayer::TILES)
{
layer = new MapLayer(offsetX, offsetY, w, h, isFringeLayer);
map->addLayer(layer);
@@ -680,7 +700,7 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
if (encoding == "base64")
{
- if (readBase64Layer(childNode, map, layer,
+ if (readBase64Layer(childNode, map, layer, layerType,
compression, x, y, w, h))
{
continue;
@@ -692,7 +712,7 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
}
else if (encoding == "csv")
{
- if (readCsvLayer(childNode, map, layer, x, y, w, h))
+ if (readCsvLayer(childNode, map, layer, layerType, x, y, w, h))
continue;
else
return;
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 7ac70a99f..d03021790 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -25,6 +25,8 @@
#include "utils/xml.h"
+#include "maplayer.h"
+
#include <string>
class Map;
@@ -73,11 +75,13 @@ class MapReader final
static bool readBase64Layer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
+ const MapLayer::Type &layerType,
const std::string &compression,
int &x, int &y, const int w, const int h);
static bool readCsvLayer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
+ const MapLayer::Type &layerType,
int &x, int &y, const int w, const int h);
/**