Skip to content

Commit

Permalink
Removed "version" from tson::Map to support Tiled v1.6 #37
Browse files Browse the repository at this point in the history
TiledVersion is still an own thing, which is still contained inside the map. Reason why version (json format version) was removed is that Tiled v1.6 changed the type from float to string, and it seems to give no real benefit to include in a map, so the easiest and most stable solution is to remove.
  • Loading branch information
SSBMTonberry committed May 2, 2021
1 parent ae701f3 commit 29edea2
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 25 deletions.
28 changes: 28 additions & 0 deletions content/test-maps/tiled_version_1.6.json
@@ -0,0 +1,28 @@
{ "compressionlevel":-1,
"height":16,
"infinite":false,
"layers":[
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":16,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":16,
"x":0,
"y":0
}],
"nextlayerid":2,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"left-down",
"tiledversion":"1.6.0",
"tileheight":16,
"tilesets":[],
"tilewidth":16,
"type":"map",
"version":"1.6",
"width":16
}
17 changes: 10 additions & 7 deletions include/tiled/Map.hpp
Expand Up @@ -42,7 +42,7 @@ namespace tson
[[nodiscard]] inline const std::string &getTiledVersion() const;
[[nodiscard]] inline const Vector2i &getTileSize() const;
[[nodiscard]] inline const std::string &getType() const;
[[nodiscard]] inline int getVersion() const;
//[[nodiscard]] inline int getVersion() const; //Removed - Tileson v1.3.0

[[nodiscard]] inline std::vector<tson::Layer> &getLayers();
[[nodiscard]] inline PropertyCollection &getProperties();
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace tson
Vector2i m_tileSize; /*! 'tilewidth': and 'tileheight' of a map */
std::vector<tson::Tileset> m_tilesets; /*! 'tilesets': Array of Tilesets */
std::string m_type; /*! 'type': map (since 1.0) */
int m_version{}; /*! 'version': The JSON format version*/
//int m_version{}; /*! 'version': The JSON format version - Removed in Tileson v1.3.0*/

ParseStatus m_status {ParseStatus::OK};
std::string m_statusMessage {"OK"};
Expand Down Expand Up @@ -161,7 +161,10 @@ bool tson::Map::parse(IJson &json, tson::DecompressorContainer *decompressors)
if(json.count("tilewidth") > 0 && json.count("tileheight") > 0 )
m_tileSize = {json["tilewidth"].get<int>(), json["tileheight"].get<int>()}; else allFound = false;
if(json.count("type") > 0) m_type = json["type"].get<std::string>(); //Optional
if(json.count("version") > 0) m_version = json["version"].get<int>(); else allFound = false;

//Removed - Changed from a float to string in Tiled v1.6, and old spec said int.
//Reason for removal is that it seems to have no real use, as TiledVersion is stored in another variable.
//if(json.count("version") > 0) m_version = json["version"].get<int>(); else allFound = false;

//More advanced data
if(json.count("layers") > 0 && json["layers"].isArray())
Expand Down Expand Up @@ -370,10 +373,10 @@ const std::string &tson::Map::getType() const
* 'version': The JSON format version
* @return
*/
int tson::Map::getVersion() const
{
return m_version;
}
//int tson::Map::getVersion() const
//{
// return m_version;
//}

/*!
* 'layers': Array of layers. group on
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_tiled_gason.cpp
Expand Up @@ -66,7 +66,7 @@ TEST_CASE( "Gason - Parse a Map from Tiled's documentation", "[tiled][map]" )
REQUIRE(map.getOrientation() == "orthogonal");
REQUIRE(map.getRenderOrder() == "right-down");
REQUIRE(map.getTileSize() == tson::Vector2i(32, 32));
REQUIRE(map.getVersion() == 1);
//REQUIRE(map.getVersion() == 1);
REQUIRE(map.getTiledVersion() == "1.0.3");
REQUIRE(map.getProperties().getSize() == 2);
REQUIRE(map.getProperties().get()[0]->getName() == "mapProperty1");
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_tiled_json11.cpp
Expand Up @@ -64,7 +64,7 @@ TEST_CASE( "Json11 - Parse a Map from Tiled's documentation", "[tiled][map]" )
REQUIRE(map.getOrientation() == "orthogonal");
REQUIRE(map.getRenderOrder() == "right-down");
REQUIRE(map.getTileSize() == tson::Vector2i(32, 32));
REQUIRE(map.getVersion() == 1);
//REQUIRE(map.getVersion() == 1);
REQUIRE(map.getTiledVersion() == "1.0.3");
REQUIRE(map.getProperties().getSize() == 2);
REQUIRE(map.getProperties().get()[0]->getName() == "mapProperty1");
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_tiled_nlohmann.cpp
Expand Up @@ -69,7 +69,7 @@ TEST_CASE( "Parse a Map from Tiled's documentation", "[tiled][map]" )
map.getOrientation() == "orthogonal" &&
map.getRenderOrder() == "right-down" &&
map.getTileSize() == tson::Vector2i(32, 32) &&
map.getVersion() == 1 &&
//map.getVersion() == 1 &&
map.getTiledVersion() == "1.0.3" &&
map.getProperties().getSize() == 2 &&
map.getProperties().get()[0]->getName() == "mapProperty1" &&
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_tiled_picojson.cpp
Expand Up @@ -58,7 +58,7 @@ TEST_CASE( "PicoJson - Parse a Map from Tiled's documentation", "[tiled][map]" )
REQUIRE(map.getOrientation() == "orthogonal");
REQUIRE(map.getRenderOrder() == "right-down");
REQUIRE(map.getTileSize() == tson::Vector2i(32, 32));
REQUIRE(map.getVersion() == 1);
//REQUIRE(map.getVersion() == 1);
REQUIRE(map.getTiledVersion() == "1.0.3");
REQUIRE(map.getProperties().getSize() == 2);
REQUIRE(map.getProperties().get()[0]->getName() == "mapProperty1");
Expand Down
17 changes: 10 additions & 7 deletions tileson.hpp
Expand Up @@ -6528,7 +6528,7 @@ namespace tson
[[nodiscard]] inline const std::string &getTiledVersion() const;
[[nodiscard]] inline const Vector2i &getTileSize() const;
[[nodiscard]] inline const std::string &getType() const;
[[nodiscard]] inline int getVersion() const;
//[[nodiscard]] inline int getVersion() const; //Removed - Tileson v1.3.0

[[nodiscard]] inline std::vector<tson::Layer> &getLayers();
[[nodiscard]] inline PropertyCollection &getProperties();
Expand Down Expand Up @@ -6570,7 +6570,7 @@ namespace tson
Vector2i m_tileSize; /*! 'tilewidth': and 'tileheight' of a map */
std::vector<tson::Tileset> m_tilesets; /*! 'tilesets': Array of Tilesets */
std::string m_type; /*! 'type': map (since 1.0) */
int m_version{}; /*! 'version': The JSON format version*/
//int m_version{}; /*! 'version': The JSON format version - Removed in Tileson v1.3.0*/

ParseStatus m_status {ParseStatus::OK};
std::string m_statusMessage {"OK"};
Expand Down Expand Up @@ -6646,7 +6646,10 @@ bool tson::Map::parse(IJson &json, tson::DecompressorContainer *decompressors)
if(json.count("tilewidth") > 0 && json.count("tileheight") > 0 )
m_tileSize = {json["tilewidth"].get<int>(), json["tileheight"].get<int>()}; else allFound = false;
if(json.count("type") > 0) m_type = json["type"].get<std::string>(); //Optional
if(json.count("version") > 0) m_version = json["version"].get<int>(); else allFound = false;

//Removed - Changed from a float to string in Tiled v1.6, and old spec said int.
//Reason for removal is that it seems to have no real use, as TiledVersion is stored in another variable.
//if(json.count("version") > 0) m_version = json["version"].get<int>(); else allFound = false;

//More advanced data
if(json.count("layers") > 0 && json["layers"].isArray())
Expand Down Expand Up @@ -6855,10 +6858,10 @@ const std::string &tson::Map::getType() const
* 'version': The JSON format version
* @return
*/
int tson::Map::getVersion() const
{
return m_version;
}
//int tson::Map::getVersion() const
//{
// return m_version;
//}

/*!
* 'layers': Array of layers. group on
Expand Down
17 changes: 10 additions & 7 deletions tileson_min.hpp
Expand Up @@ -5544,7 +5544,7 @@ namespace tson
[[nodiscard]] inline const std::string &getTiledVersion() const;
[[nodiscard]] inline const Vector2i &getTileSize() const;
[[nodiscard]] inline const std::string &getType() const;
[[nodiscard]] inline int getVersion() const;
//[[nodiscard]] inline int getVersion() const; //Removed - Tileson v1.3.0

[[nodiscard]] inline std::vector<tson::Layer> &getLayers();
[[nodiscard]] inline PropertyCollection &getProperties();
Expand Down Expand Up @@ -5586,7 +5586,7 @@ namespace tson
Vector2i m_tileSize; /*! 'tilewidth': and 'tileheight' of a map */
std::vector<tson::Tileset> m_tilesets; /*! 'tilesets': Array of Tilesets */
std::string m_type; /*! 'type': map (since 1.0) */
int m_version{}; /*! 'version': The JSON format version*/
//int m_version{}; /*! 'version': The JSON format version - Removed in Tileson v1.3.0*/

ParseStatus m_status {ParseStatus::OK};
std::string m_statusMessage {"OK"};
Expand Down Expand Up @@ -5662,7 +5662,10 @@ bool tson::Map::parse(IJson &json, tson::DecompressorContainer *decompressors)
if(json.count("tilewidth") > 0 && json.count("tileheight") > 0 )
m_tileSize = {json["tilewidth"].get<int>(), json["tileheight"].get<int>()}; else allFound = false;
if(json.count("type") > 0) m_type = json["type"].get<std::string>(); //Optional
if(json.count("version") > 0) m_version = json["version"].get<int>(); else allFound = false;

//Removed - Changed from a float to string in Tiled v1.6, and old spec said int.
//Reason for removal is that it seems to have no real use, as TiledVersion is stored in another variable.
//if(json.count("version") > 0) m_version = json["version"].get<int>(); else allFound = false;

//More advanced data
if(json.count("layers") > 0 && json["layers"].isArray())
Expand Down Expand Up @@ -5871,10 +5874,10 @@ const std::string &tson::Map::getType() const
* 'version': The JSON format version
* @return
*/
int tson::Map::getVersion() const
{
return m_version;
}
//int tson::Map::getVersion() const
//{
// return m_version;
//}

/*!
* 'layers': Array of layers. group on
Expand Down

0 comments on commit 29edea2

Please sign in to comment.