dungeon/src/TileSet.cpp

66 lines
1.5 KiB
C++
Raw Normal View History

2018-01-09 21:59:05 +01:00
#include "TileSet.h"
2018-01-10 10:10:43 +01:00
#include <kaguya/kaguya.hpp>
#include <SDL2/SDL_log.h>
2018-01-09 21:59:05 +01:00
Tile null = Tile();
TileSet::TileSet() {}
TileSet::~TileSet() {}
2018-03-26 22:16:10 +02:00
int TileSet::count() const {
return tiles.size();
2018-01-09 21:59:05 +01:00
}
void TileSet::add_tile(std::string name, Tile tile) {
2018-01-10 10:10:43 +01:00
tiles[name] = tile;
2018-01-09 21:59:05 +01:00
}
Tile const& TileSet::get_tile(std::string name) {
auto it = tiles.find(name);
if (it == tiles.end()) {
return null;
}
else {
return it->second;
}
}
std::vector<std::string> TileSet::find_tiles(bool passable, bool opaque, bool wall, std::vector<std::string> include_tags, std::vector<std::string> exclude_tags) {
std::vector<std::string> found_tiles;
// TODO: optimize this stuff, could use less for loops
for (auto pair : tiles) {
if (pair.second.passable == passable
&& pair.second.opaque == opaque
&& pair.second.wall == wall) {
bool match = true;
for (std::string& inc : include_tags) {
if (!match) break;
match = false;
for (std::string& tag : pair.second.tags) {
if (tag == inc) {
match = true;
break;
}
}
}
for (std::string& tag : pair.second.tags) {
if (!match) break;
for (std::string& excl : exclude_tags) {
if (tag == excl) {
match = false;
break;
}
}
}
if (match) {
found_tiles.emplace_back(pair.first);
}
}
}
return found_tiles;
}