diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-17 00:10:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-17 00:10:25 +0300 |
commit | d6da03bf0c4bd2e89429448f2d33c2bdc5083733 (patch) | |
tree | 771e9ccecc5d5fd739f9be5df9af443c9ab8b6e5 /src/resources/mapreader.cpp | |
parent | e3ce2827f14efc6630a4c2932b60e23d9b0321b0 (diff) | |
download | mv-d6da03bf0c4bd2e89429448f2d33c2bdc5083733.tar.gz mv-d6da03bf0c4bd2e89429448f2d33c2bdc5083733.tar.bz2 mv-d6da03bf0c4bd2e89429448f2d33c2bdc5083733.tar.xz mv-d6da03bf0c4bd2e89429448f2d33c2bdc5083733.zip |
add code for loading map heights.
Diffstat (limited to 'src/resources/mapreader.cpp')
-rw-r--r-- | src/resources/mapreader.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 3ab6c49fe..2b2edb3de 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -419,6 +419,7 @@ void MapReader::readProperties(const XmlNodePtr node, Properties *const props) inline static void setTile(Map *const map, MapLayer *const layer, const MapLayer::Type &layerType, + MapHeights *const heights, const int x, const int y, const int gid) { const Tileset * const set = map->getTilesetWithGid(gid); @@ -469,7 +470,21 @@ inline static void setTile(Map *const map, MapLayer *const layer, } case MapLayer::HEIGHTS: + { + if (!set) + break; + if (map->getVersion() >= 2) + { + heights->setHeight(x, y, gid - set->getFirstGid() + 1); + } + else + { + Image *const img = set ? set->get(gid - set->getFirstGid()) + : nullptr; + layer->setTile(x, y, img); + } break; + } default: break; @@ -477,7 +492,7 @@ inline static void setTile(Map *const map, MapLayer *const layer, } #define addTile() \ - setTile(map, layer, layerType, x, y, gid); \ + setTile(map, layer, layerType, heights, x, y, gid); \ if (hasAnimations) \ { \ TileAnimationMapCIter it = tileAnimations.find(gid); \ @@ -492,6 +507,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, + MapHeights *const heights, const std::string &compression, int &x, int &y, const int w, const int h) { @@ -592,6 +608,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, + MapHeights *const heights, int &x, int &y, const int w, const int h) { XmlNodePtr dataChild = childNode->xmlChildrenNode; @@ -658,6 +675,7 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map) map->indexTilesets(); MapLayer *layer = nullptr; + MapHeights *heights = nullptr; logger->log("- Loading layer \"%s\"", name.c_str()); int x = 0; @@ -692,6 +710,11 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map) layer = new MapLayer(offsetX, offsetY, w, h, isFringeLayer); map->addLayer(layer); } + else if (layerType == MapLayer::HEIGHTS) + { + heights = new MapHeights(w, h); + map->addHeights(heights); + } const std::string encoding = XML::getProperty(childNode, "encoding", ""); @@ -701,7 +724,7 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map) if (encoding == "base64") { if (readBase64Layer(childNode, map, layer, layerType, - compression, x, y, w, h)) + heights, compression, x, y, w, h)) { continue; } @@ -712,10 +735,15 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map) } else if (encoding == "csv") { - if (readCsvLayer(childNode, map, layer, layerType, x, y, w, h)) + if (readCsvLayer(childNode, map, layer, layerType, + heights, x, y, w, h)) + { continue; + } else + { return; + } } else { |