17#ifndef _FGE_C_TILESET_HPP_INCLUDED
18#define _FGE_C_TILESET_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
22#include "FastEngine/C_propertyList.hpp"
23#include "FastEngine/accessor/C_texture.hpp"
31using GlobalTileId = int32_t;
32using LocalTileId = int32_t;
45 mutable std::vector<fge::RectInt> _collisionRects{};
57inline bool operator<(fge::TileData
const& l, fge::TileData
const& r)
72 using TileListType = std::set<fge::TileData, std::less<>>;
76 TileSet(
fge::Texture texture, fge::Vector2i
const& tileSize);
77 TileSet(
fge::Texture texture, fge::Vector2i
const& tileSize, fge::Vector2i
const& offset);
95 [[nodiscard]] std::string
const&
getName()
const;
168 [[nodiscard]] LocalTileId
getLocalId(fge::Vector2i
const& position)
const;
178 [[nodiscard]] LocalTileId
getLocalId(GlobalTileId gid)
const;
179 [[nodiscard]] GlobalTileId getGlobalId(LocalTileId
id)
const;
187 [[nodiscard]]
bool containsLocal(LocalTileId
id)
const;
203 [[nodiscard]] TileListType::const_iterator begin()
const;
204 [[nodiscard]] TileListType::const_iterator end()
const;
252 fge::Vector2i g_tileSize;
253 fge::Vector2i g_offset{0, 0};
254 TileListType g_tiles;
255 GlobalTileId g_firstGid{1};
260FGE_API
void to_json(nlohmann::json& j, fge::TileSet
const& p);
261FGE_API
void from_json(nlohmann::json
const& j, fge::TileSet& p);
263FGE_API
void to_json(nlohmann::json& j, fge::TileData
const& p);
264FGE_API
void from_json(nlohmann::json
const& j, fge::TileData& p);
A class that map a string to a Property.
Definition C_propertyList.hpp:35
This class is a wrapper for the texture manager to allow easy manipulation.
Definition C_texture.hpp:36
A class that represent a set of tiles that can be used in a TileLayer.
Definition C_tileset.hpp:70
void setFirstGid(GlobalTileId gid)
Set the first global id of the tileset.
void setTileSize(fge::Vector2i const &tileSize)
Set the tile size of the TileSet.
void slice()
Slice the texture into tiles.
void clearTiles()
Clear the tiles.
fge::Vector2i const & getTileSize() const
Get the tile size of the TileSet.
fge::Vector2i const & getOffset() const
Get the offset in pixel of the TileSet.
std::optional< fge::RectInt > getTextureRect(LocalTileId id) const
Get the texture rectangle of a tile by its local id.
int getRows() const
Return the number of rows in the texture.
void setName(std::string name)
Set the name of the TileSet.
void setTexture(fge::Texture texture)
Set the texture of the TileSet.
int getColumns() const
Return the number of columns in the texture.
fge::RectInt computeTextureRect(LocalTileId id) const
Compute the supposed texture rectangle with a local id.
std::string const & getName() const
Get the name of the TileSet.
bool valid() const
Check if the TileSet have a valid Texture.
bool containsGlobal(GlobalTileId gid) const
Check if the global id is in the tileset.
std::size_t getTileCount() const
Get the total number of tiles in the TileSet.
fge::Texture const & getTexture() const
Get the texture of the TileSet.
LocalTileId getLocalId(fge::Vector2i const &position) const
Get the local id of a tile by its grid position.
fge::TileData const * getTile(LocalTileId id) const
Retrieve a tile by its local id.
void setOffset(fge::Vector2i const &offset)
Set the offset in pixel of the TileSet.
GlobalTileId getFirstGid() const
Get the first global id of the tileset.
LocalTileId getLocalId(GlobalTileId gid) const
Get the local id of a tile by its global id.
A tile structure that contain mostly the texture rectangle and data.
Definition C_tileset.hpp:42