From 30e261ce0220110db201e522e751b1c82c0b5683 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 1 Feb 2025 21:34:22 +0500 Subject: feat: tileset --- src/tileset.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/tileset.cpp (limited to 'src/tileset.cpp') diff --git a/src/tileset.cpp b/src/tileset.cpp new file mode 100644 index 0000000..8651a8f --- /dev/null +++ b/src/tileset.cpp @@ -0,0 +1,28 @@ +#include "tileset.hpp" + +namespace silly::editor { + void Tileset::add_tile(const std::string &path, TilesetTileType type) { + TilesetTile tile; + tile.type = type; + tile.id = this->tiles.size(); + + if (!tile.texture.loadFromFile(path)) { + // TODO: add logging here + return; + } + + this->tiles.push_back(tile); + } + + void Tileset::remove_tile(const TilesetTile &tile) { + this->tiles.resize(std::distance( + this->tiles.begin(), + std::remove_if( + this->tiles.begin(), this->tiles.end(), + [&tile](const TilesetTile &t) { return t.id == tile.id; }))); + } + + const std::vector &Tileset::get_tiles() const { + return this->tiles; + } +} \ No newline at end of file -- cgit v1.2.3