summaryrefslogtreecommitdiff
path: root/src/sets/tileset.hpp
blob: 09799ce8ad11ee603922a88de5f3e0f28bc792b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
                           })));
      }
  };
}