summaryrefslogtreecommitdiff
path: root/src/tileset.cpp
blob: 8651a8f24197df93e228564f256a0db93931d09d (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
#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<TilesetTile> &Tileset::get_tiles() const {
    return this->tiles;
  }
}