Release 1.2.0
Features
-
There is now an option to use a
tileson_min.hpp
file which only contains theTileson
related code (~5000 lines of code). This requires the user to include their own version ofnlohmann/json
before includingtileson_min.hpp
, but is less bloated and gives the user freedom to use whatever improved version ofnlohmann/json
they want (for reference: Tileson is implemented with version3.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 astson::TileObject
. Atson::TileObject
contains all the information needed to be able to draw aTile
at a specific location, and it also knows whichTileset
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 usingTileson
. NB! This functionality requiresstd::filesystem
to be enabled (DISABLE_CPP17_FILESYSTEM not defined (default)). (Seeexamples
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 allmap
andworld
data, but the files themselves must be parsed separately usingTileson
. NB! This functionality requiresstd::filesystem
to be enabled (DISABLE_CPP17_FILESYSTEM not defined (default)). (Seeexamples
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 fromtson::Tile
,tson::TileObject
andtson::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 inexamples
has been greatly improved to showcase the most important features ofTileson 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
andtson::Tileset
now has a pointer to the map they are owned by, which can be retrieved withtson::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 internaltile map
andtile data
will be empty. (#17 ) -
Added all new properties introduced after Tiled
1.2.4
. Up to version1.4.1
.editorsettings
not included. (#9 ) -
Added the missing
color
property oftson::Text
(#21 ). -
Greatly improved the
CMakeLists.txt
build script for theexamples
, making it more flexible. This removes the32-bit
-restriction ofWindows
systems. -
tson::Tile
now has an own property ofgid
, which will always be the actual graphics ID. When
flip flags are not in use, theid
andgid
will be equal, but in cases where flip flags are used, theid
will represent the ID + flip flag bits, wheregid
still will be the same ID. -
tson::Map
now has a function to gettson::Tileset
by providing agid
from a tile or object:getTilesetByGid(uint32_t gid)
Breaking changes
- The parser now returns a
std::unique_ptr<tson::Map>
instead of atson::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 totson::Tile
(or related to tiles in general) had to be changed fromint
touint32_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 supportstd::filesystem
, and certain features requires this to work.