Skip to content

Release 1.2.0

Compare
Choose a tag to compare
@SSBMTonberry SSBMTonberry released this 13 Dec 12:44
· 270 commits to master since this release

Features

  • There is now an option to use a tileson_min.hpp file which only contains the Tileson related code (~5000 lines of code). This requires the user to include their own version of nlohmann/json before including tileson_min.hpp, but is less bloated and gives the user freedom to use whatever improved version of nlohmann/json they want (for reference: Tileson is implemented with version 3.7.0 of this library). tileson.hpp with the full functionality is, of course, still available.

  • All tiles in a Tile layer can now get retrieved as tson::TileObject. A tson::TileObject contains all the information needed to be able to draw a Tile at a specific location, and it also knows which Tileset it is related to (#1 , #11 ):

for (const auto& [pos, tileObject] : layer.getTileObjects()) 
{
    tson::Tileset *tileset = tileObject.getTile()->getTileset();
    tson::Rect drawingRect = tileObject.getDrawingRect();
    tson::Vector2f position = tileObject.getPosition();

    //If using SFML to draw (sprite is a sf::Sprite (if used with SFML))
    sprite->setTextureRect({drawingRect.x, drawingRect.y, drawingRect.width, drawingRect.height});
    sprite->setPosition({position.x, position.y});
    m_window.draw(*sprite); //sf::RenderWindow
}
  • Base64-encoded data inside Tiled maps are now supported! (#5 )

  • Tileson now supports Tiled worlds. These contains a collection of several maps that can be tied together, but the files themselves must be parsed separately using Tileson. NB! This functionality requires std::filesystem to be enabled (DISABLE_CPP17_FILESYSTEM not defined (default)). (See examples to get a full idea how worlds works)(#12 ).

tson::Tileson t;
tson::World world; 
world.parse(fs::path("path/to/you/file.world"));

//world.get("w1.json") can be used to get a specific map

for(const auto &data : world.getMapData())
{
    std::unique_ptr<tson::Map> map = t.parse(fs::path(world.getFolder() / data.fileName));
    //...
}
  • Tileson now supports Tiled projects. These contains all map and world data, but the files themselves must be parsed separately using Tileson. NB! This functionality requires std::filesystem to be enabled (DISABLE_CPP17_FILESYSTEM not defined (default)). (See examples to get a full idea how projects works)
    (#8 ).
tson::Tileson t;
tson::Project project; 
bool ok = project.parse(fs::path("path/to/you/file.tiled-project"));

for(const auto &folder : m_project.getFolders())
{
    // You can check if a project folder contains a world with -> folder.hasWorldFile()
    // If it does, you can get the world data with -> folder.getWorld()
    for(const auto &file : folder.getFiles())
    {
        std::unique_ptr<tson::Map> map = t.parse(fs::path(folder.getPath() / file.filename()));
        //...
    }
}
  • Added support for flipped tiles. Flip flags can be retrieved from tson::Tile, tson::TileObject and tson::Object(specifically used when using tile graphics):
tson::Object *obj = map->getLayer("Object Layer")->firstObj("mario_ver_flip");
tson::Tile *tile = map->getLayer("Main Layer")->getTileData(28, 15);
tson::TileObject *tileObj = map->getLayer("Main Layer")->getTileObject(28, 14);

bool hasFlags1 = obj->hasFlipFlags(tson::TileFlipFlags::Vertically);
bool hasFlags2 = tile->hasFlipFlags(tson::TileFlipFlags::Horizontally);
bool hasFlags3 = tileObj->getTile()->hasFlipFlags(tson::TileFlipFlags::Vertically | tson::TileFlipFlags::Diagonally);
  • The SFML demo in examples has been greatly improved to showcase the most important features of Tileson v1.2.0. Check it out!

Improvements

  • New helper functions for tson::Tile (#3 , #1 ):

    • inline tson::Tileset * getTileset() const
    • inline tson::Map * getMap() const
    • inline const tson::Rect &getDrawingRect() const
    • inline const tson::Vector2f getPosition(const std::tuple<int, int> &tileDataPos)
    • inline const tson::Vector2i getPositionInTileUnits(const std::tuple<int, int> &tileDataPos)
    • inline const tson::Vector2i getTileSize() const
  • tson::Layer and tson::Tileset now has a pointer to the map they are owned by, which can be retrieved with tson::Map *getMap()

  • Unresolvable tiles no longer crashes during parsing (example: By accidentally using external tilesets, which is not supported by Tileson), but as a result the internal tile map and tile data will be empty. (#17 )

  • Added all new properties introduced after Tiled 1.2.4. Up to version 1.4.1. editorsettings not included. (#9 )

  • Added the missing color property of tson::Text (#21 ).

  • Greatly improved the CMakeLists.txt build script for the examples, making it more flexible. This removes the 32-bit-restriction of Windows systems.

  • tson::Tile now has an own property of gid, which will always be the actual graphics ID. When
    flip flags are not in use, the id and gid will be equal, but in cases where flip flags are used, the id will represent the ID + flip flag bits, where gid still will be the same ID.

  • tson::Map now has a function to get tson::Tileset by providing a gid from a tile or object: getTilesetByGid(uint32_t gid)

Breaking changes

  • The parser now returns a std::unique_ptr<tson::Map> instead of a tson::Map. This should have been done from the start, but now there are some parts where it really is required that the physical space in memory is unchanged. At the same time a unnecessary copy will no longer happen during the parsing, so a minor performance increase should be expected.
  • Due to the implementation of the missing flip flags for tiles, which uses the upper bits of a 32-bit unsigned int, all IDs related to tson::Tile (or related to tiles in general) had to be changed from int to uint32_t, which cannot be negative.

Deprecated

  • The DISABLE_CPP17_FILESYSTEM preprocessor has been deprecated, and will be removed in the next version of Tileson. This is because all mayor compilers now should support std::filesystem, and certain features requires this to work.