diff options
| author | ilotterytea <iltsu@alright.party> | 2025-02-01 22:51:37 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-02-01 22:51:37 +0500 |
| commit | 79c7edc335fc162e9d2ef9acc5cdf41fbd1bac76 (patch) | |
| tree | 65decb4938ffd096ccdf7da5f26c2eee27818ac5 /src/floor.cpp | |
| parent | 2f54da5844b959c29788b2a0883ee5dae5bdbbd2 (diff) | |
feat: layers
Diffstat (limited to 'src/floor.cpp')
| -rw-r--r-- | src/floor.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/floor.cpp b/src/floor.cpp index 4365c73..8482b48 100644 --- a/src/floor.cpp +++ b/src/floor.cpp @@ -11,29 +11,34 @@ namespace silly::editor { void TileFloor::render(sf::RenderWindow &window) const { - std::for_each(this->tiles.begin(), this->tiles.end(), - [&window](const Tile &t) { - sf::Sprite s(t.tile->texture); - s.setPosition({t.position.x * (float)TILE_WIDTH, - t.position.y * (float)TILE_HEIGHT}); - - window.draw(s); - }); + for (auto l = this->layers.begin(); l != this->layers.end(); ++l) { + for (auto t = l->tiles.begin(); t != l->tiles.end(); ++t) { + sf::Sprite s(t->tile->texture); + s.setPosition({t->position.x * (float)TILE_WIDTH, + t->position.y * (float)TILE_HEIGHT}); + + window.draw(s); + } + } } void TileFloor::place_tile(std::shared_ptr<TilesetTile> &tile, const sf::Vector2i &position) { + TileLayer &layer = this->layers.at(tile->type); + if (!std::any_of( - this->tiles.begin(), this->tiles.end(), + layer.tiles.begin(), layer.tiles.end(), [&position](const Tile &t) { return t.position == position; })) { - this->tiles.push_back({position, tile}); + layer.tiles.push_back({position, tile}); } } void TileFloor::remove_tile(const sf::Vector2i &position) { - this->tiles.resize(std::distance( - this->tiles.begin(), + TileLayer &layer = this->layers.at(this->activeLayerIndex); + + layer.tiles.resize(std::distance( + layer.tiles.begin(), std::remove_if( - this->tiles.begin(), this->tiles.end(), + layer.tiles.begin(), layer.tiles.end(), [&position](const Tile &t) { return t.position == position; }))); } |
