17#ifndef _FGE_C_TILELAYER_HPP_INCLUDED
18#define _FGE_C_TILELAYER_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_matrix.hpp"
22#include "FastEngine/C_tileset.hpp"
23#include "FastEngine/graphic/C_color.hpp"
24#include "FastEngine/graphic/C_drawable.hpp"
25#include "FastEngine/graphic/C_transformable.hpp"
26#include "FastEngine/vulkan/C_vertexBuffer.hpp"
30#define FGE_LAYER_BAD_ID 0
35using GlobalTileId = int32_t;
36using LocalTileId = int32_t;
39class FGE_API
BaseLayer :
public fge::Transformable
51 BaseLayer() =
default;
52 ~BaseLayer()
override =
default;
54 [[nodiscard]]
virtual Types getType()
const = 0;
69 [[nodiscard]] GlobalTileId
getId()
const;
82 [[nodiscard]] std::string
const&
getName()
const;
84 virtual void save(nlohmann::json& jsonObject);
85 virtual void load(nlohmann::json
const& jsonObject, std::filesystem::path
const& filePath);
87 [[nodiscard]]
static std::shared_ptr<BaseLayer> loadLayer(nlohmann::json
const& jsonObject,
88 std::filesystem::path
const& filePath);
91 constexpr T
const* as()
const
93 static_assert(std::is_base_of_v<BaseLayer, T>,
"T must inherit from BaseLayer");
94 return static_cast<T*
>(
this);
99 static_assert(std::is_base_of_v<BaseLayer, T>,
"T must inherit from BaseLayer");
100 return static_cast<T*
>(
this);
105 GlobalTileId g_id{FGE_LAYER_BAD_ID};
115class FGE_API TileLayer :
public BaseLayer
141 [[nodiscard]] GlobalTileId
getGid()
const;
184 [[nodiscard]]
TileData const* getTileData()
const;
187 void updatePositions();
188 void updateTexCoords();
190 GlobalTileId g_gid{0};
191 std::weak_ptr<TileSet> g_tileSet;
200#ifndef FGE_DEF_SERVER
204 [[nodiscard]] Types getType()
const override;
206 void clear()
override;
221 void setGid(fge::Vector2size position, std::span<std::shared_ptr<TileSet>> tileSets, GlobalTileId gid);
222 [[nodiscard]] GlobalTileId getGid(fge::Vector2size position)
const;
223 [[nodiscard]] std::optional<fge::Vector2size> getGridPosition(fge::Vector2f position)
const;
230 void setGid(fge::Vector2size position, GlobalTileId gid);
244 [[nodiscard]]
static std::shared_ptr<TileSet>
245 retrieveAssociatedTileSet(std::span<std::shared_ptr<TileSet>> tileSets, GlobalTileId gid);
247 [[nodiscard]] fge::RectFloat getGlobalBounds()
const;
248 [[nodiscard]] fge::RectFloat getLocalBounds()
const;
250 void save(nlohmann::json& jsonObject)
override;
251 void load(nlohmann::json
const& jsonObject, std::filesystem::path
const& filePath)
override;
264class FGE_API ObjectGroupLayer :
public BaseLayer
267 ObjectGroupLayer() =
default;
271 fge::Vector2f _position;
279#ifndef FGE_DEF_SERVER
283 [[nodiscard]] Types getType()
const override;
285 void clear()
override;
287 [[nodiscard]] std::vector<Object>
const& getObjects()
const;
288 [[nodiscard]] std::vector<Object>& getObjects();
290 [[nodiscard]]
Object* findObjectName(std::string_view name);
291 [[nodiscard]]
Object const* findObjectName(std::string_view name)
const;
293 void save(nlohmann::json& jsonObject)
override;
294 void load(nlohmann::json
const& jsonObject, std::filesystem::path
const& filePath)
override;
297 std::vector<Object> g_objects;
Definition C_tilelayer.hpp:43
GlobalTileId getId() const
Get the id of the layer.
void setId(GlobalTileId id)
Set the id of the layer (mostly for "Tiled" map editor compatibility)
std::string const & getName() const
Get the name of the layer.
void setName(std::string_view name)
Set the name of the layer.
Definition C_color.hpp:35
Definition C_drawable.hpp:36
A container to store a 2D matrix of any type.
Definition C_matrix.hpp:40
The RenderStates class contains all the information needed to render something.
Definition C_renderStates.hpp:412
Definition C_renderTarget.hpp:56
Color getColor() const
Get the color of the tile.
GlobalTileId getGid() const
Get the global id of the tile.
std::shared_ptr< TileSet > getTileSet() const
Get the associated tileset pointer.
Vector2f const & getPosition() const
Get the local position of the tile.
void setTileSet(std::shared_ptr< TileSet > const &tileSet)
Set the associated tileset pointer.
void setGid(GlobalTileId gid)
Set the global id of the tile.
void setPosition(Vector2f const &position)
Set the local position of the tile.
void setColor(Color const &color)
Set the color of the tile.
A tile layer contain a matrix of global tile id and a list of TileSet.
Definition C_tilelayer.hpp:116
void refreshTextures(std::span< std::shared_ptr< TileSet > > tileSets)
Refresh all tiles with a list of tilesets.
void setGid(fge::Vector2size position, GlobalTileId gid)
Shortcut to set a global tile id.
fge::Matrix< Tile > const & getTiles() const
Get the matrix of tiles.
void setGid(fge::Vector2size position, std::span< std::shared_ptr< TileSet > > tileSets, GlobalTileId gid)
Shortcut to set a global tile id and a new tileset.
void setGridSize(fge::Vector2size size)
Set the tiles matrix size.
Definition C_vertexBuffer.hpp:45
Definition C_tilelayer.hpp:270
A tile structure that contain mostly the texture rectangle and data.
Definition C_tileset.hpp:42