35#ifndef LIBTCOD_TILESET_HPP_
36#define LIBTCOD_TILESET_HPP_
52static constexpr std::array<int, 256> CHARMAP_CP437 = TCOD_CHARMAP_CP437_;
57static constexpr std::array<int, 256> CHARMAP_TCOD = TCOD_CHARMAP_TCOD_;
59struct TilesetDeleter {
67typedef std::unique_ptr<TCOD_Tileset, TilesetDeleter> TilesetPtr;
85 explicit Tileset(
int tile_width,
int tile_height) : tileset_{
TCOD_tileset_new(tile_width, tile_height)} {
93 explicit Tileset(
const std::array<int, 2>& tile_shape) : Tileset{tile_shape.at(0), tile_shape.at(1)} {}
99 explicit Tileset(TilesetPtr ptr) : tileset_{std::move(ptr)} {
100 if (!tileset_)
throw std::invalid_argument(
"Pointer must not be nullptr.");
107 explicit Tileset(TCOD_Tileset* ptr) : tileset_{ptr} {
108 if (!tileset_)
throw std::invalid_argument(
"Pointer must not be nullptr.");
115 [[nodiscard]]
auto get_tile_width() const noexcept ->
int {
return tileset_->tile_width; }
121 [[nodiscard]]
auto get_tile_height() const noexcept ->
int {
return tileset_->tile_height; }
127 [[nodiscard]]
auto get_tile_shape() const noexcept -> std::array<
int, 2> {
128 return {tileset_->tile_width, tileset_->tile_height};
135 [[nodiscard]]
auto get() noexcept -> TCOD_Tileset* {
return tileset_.get(); }
141 [[nodiscard]]
auto get() const noexcept -> TCOD_Tileset* {
return tileset_.get(); }
147 auto release() noexcept -> TCOD_Tileset* {
return tileset_.release(); }
151 [[nodiscard]]
operator TCOD_Tileset&() {
return *tileset_; }
155 [[nodiscard]]
operator const TCOD_Tileset&()
const {
return *tileset_; }
158 TilesetPtr tileset_ =
nullptr;
179template <
typename ArrayType>
180TCOD_NODISCARD
inline auto load_tilesheet(
181 const std::filesystem::path& path,
const std::array<int, 2>& columns_rows,
const ArrayType& charmap) -> Tileset {
184 path.string().c_str(), columns_rows.at(0), columns_rows.at(1),
static_cast<int>(charmap.size()), charmap.data())};
186 return Tileset{std::move(tileset)};
const char * TCOD_get_error(void)
Return the last error message.
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 color.hpp:45
void check_path(const std::filesystem::path &path)
Throw an exception if the given path does not exist.
Definition error.hpp:78