summaryrefslogtreecommitdiff
path: root/src/tileset.cpp
blob: 5e5b47af5624ebf82a62c64c94940c7c96363ef7 (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
#include "tileset.hpp"

#include <memory>

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(std::make_shared<TilesetTile>(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 std::shared_ptr<TilesetTile> &t) {
                         return t.get()->id == tile.id;
                       })));
  }

  const std::vector<std::shared_ptr<TilesetTile>> &Tileset::get_tiles() const {
    return this->tiles;
  }
}