summaryrefslogtreecommitdiff
path: root/src/sets/tileset.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sets/tileset.hpp')
-rw-r--r--src/sets/tileset.hpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/sets/tileset.hpp b/src/sets/tileset.hpp
new file mode 100644
index 0000000..09799ce
--- /dev/null
+++ b/src/sets/tileset.hpp
@@ -0,0 +1,41 @@
+#pragma once
+#include <SFML/Graphics/Texture.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;
+ TilesetTileType type;
+ };
+
+ class TileSet : public EntrySet<TilesetTile, TilesetTileType> {
+ public:
+ void add_entry(const std::string &path, TilesetTileType type) override {
+ TilesetTile tile;
+ tile.type = type;
+ tile.id = this->entries.size();
+
+ if (!tile.texture.loadFromFile(path)) {
+ // TODO: add logging here
+ return;
+ }
+
+ this->entries.push_back(std::make_shared<TilesetTile>(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<TilesetTile> &t) {
+ return t.get()->id == entry.id;
+ })));
+ }
+ };
+} \ No newline at end of file