#pragma once #include #include #include "../utils/string.hpp" #include "entryset.hpp" #define TILE_WIDTH 16 #define TILE_HEIGHT 16 namespace silly::editor { enum TilesetTileType { TILE_FLOOR = 0, TILE_WALL }; struct TilesetTile { int id; sf::Texture texture; std::string path, name, extension; TilesetTileType type; }; class TileSet : public EntrySet { public: void add_entry(const std::string &path, TilesetTileType type) override { TilesetTile tile; tile.type = type; tile.path = path; tile.id = this->entries.size(); if (!tile.texture.loadFromFile(path)) { // TODO: add logging here return; } // parsing name and extension #ifdef WIN32 char delim = '\\'; #else char delim = '/'; #endif auto path_parts = utils::split_text(path, delim); std::string name_with_extension = path_parts[path_parts.size() - 1]; auto nwe_parts = utils::split_text(name_with_extension, '.'); tile.extension = nwe_parts[nwe_parts.size() - 1]; tile.name = name_with_extension.substr( 0, name_with_extension.length() - tile.extension.length() - 1); this->entries.push_back(std::make_shared(tile)); } void remove_entry(const TilesetTile &entry) override { this->entries.resize(std::distance( this->entries.begin(), std::remove_if(this->entries.begin(), this->entries.end(), [&entry](const std::shared_ptr &t) { return t.get()->id == entry.id; }))); } }; }