35#ifndef LIBTCOD_TILESET_HPP_
36#define LIBTCOD_TILESET_HPP_
54static constexpr std::array<int, 256> CHARMAP_CP437 = TCOD_CHARMAP_CP437_;
61static constexpr std::array<int, 256> CHARMAP_TCOD = TCOD_CHARMAP_TCOD_;
73typedef std::unique_ptr<TCOD_Tileset, TilesetDeleter>
TilesetPtr;
101 explicit Tileset(
const std::array<int, 2>& tile_shape) :
Tileset{tile_shape.at(0), tile_shape.at(1)} {}
108 if (!tileset_)
throw std::invalid_argument(
"Pointer must not be nullptr.");
116 if (!tileset_)
throw std::invalid_argument(
"Pointer must not be nullptr.");
123 [[nodiscard]]
auto get_tile_width() const noexcept ->
int {
return tileset_->tile_width; }
129 [[nodiscard]]
auto get_tile_height() const noexcept ->
int {
return tileset_->tile_height; }
136 return {tileset_->tile_width, tileset_->tile_height};
163 [[nodiscard]]
operator const TCOD_Tileset&()
const {
return *tileset_; }
189template <
typename ArrayType>
191 const std::filesystem::path& path,
const std::array<int, 2>& columns_rows,
const ArrayType& charmap) ->
Tileset {
194 path.string().c_str(), columns_rows.at(0), columns_rows.at(1),
static_cast<int>(charmap.size()), charmap.data())};
196 return Tileset{std::move(tileset)};
A C++ Tileset container.
Definition tileset.hpp:81
Tileset(TCOD_Tileset *ptr)
Takes ownership of a raw TCOD_Tileset pointer.
Definition tileset.hpp:115
auto get_tile_shape() const noexcept -> std::array< int, 2 >
Get the {width, height} shape of tiles in this Tileset.
Definition tileset.hpp:135
Tileset(const std::array< int, 2 > &tile_shape)
Construct a new Tileset object with tiles of the given size.
Definition tileset.hpp:101
auto release() noexcept -> TCOD_Tileset *
Release ownership of this Tileset's TCOD_Tileset* and return the pointer.
Definition tileset.hpp:155
auto get() noexcept -> TCOD_Tileset *
Return a non-owning pointer to this objects TCOD_Tileset.
Definition tileset.hpp:143
Tileset(TilesetPtr ptr)
Pass ownership of a TilesetPtr to a new Tileset.
Definition tileset.hpp:107
auto get_tile_width() const noexcept -> int
Get the width of tiles in this Tileset.
Definition tileset.hpp:123
Tileset(int tile_width, int tile_height)
Construct a new Tileset object with tiles of the given size.
Definition tileset.hpp:93
Tileset()=default
Construct a new Tileset object.
auto get() const noexcept -> TCOD_Tileset *
Return a non-owning pointer to this objects TCOD_Tileset.
Definition tileset.hpp:149
auto get_tile_height() const noexcept -> int
Get the height of tiles in this Tileset.
Definition tileset.hpp:129
const char * TCOD_get_error(void)
Return the last error message.
std::unique_ptr< TCOD_Tileset, TilesetDeleter > TilesetPtr
A unique pointer to a TCOD_Tileset.
Definition tileset.hpp:73
auto load_tilesheet(const std::filesystem::path &path, const std::array< int, 2 > &columns_rows, const ArrayType &charmap) -> Tileset
Load a tilesheet from a PNG file.
Definition tileset.hpp:190
void TCOD_tileset_delete(TCOD_Tileset *tileset)
Delete a tile-set.
TCOD_Tileset * TCOD_tileset_new(int tile_width, int tile_height)
Create a new tile-set with the given tile size.
TCOD_Tileset * TCOD_tileset_load(const char *filename, int columns, int rows, int n, const int *charmap)
Load a PNG font as a tilesheet and return a TCOD_Tileset.
The libtcod namespace.
Definition bresenham.hpp:157
void check_path(const std::filesystem::path &path)
Throw an exception if the given path does not exist.
Definition error.hpp:78
A container for libtcod tileset graphics.
Definition tileset.h:62
Definition tileset.hpp:63