diff options
| author | ilotterytea <iltsu@alright.party> | 2025-02-01 23:19:16 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-02-01 23:19:16 +0500 |
| commit | 91ffa8637cddddae07c42115788e5104a5faca7f (patch) | |
| tree | 69b392ec7ecdc82402b79a5bac3e11db50ddf81d /src/editor.cpp | |
| parent | 79c7edc335fc162e9d2ef9acc5cdf41fbd1bac76 (diff) | |
feat: tile rotation
Diffstat (limited to 'src/editor.cpp')
| -rw-r--r-- | src/editor.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/editor.cpp b/src/editor.cpp index 198620c..97979fb 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -2,6 +2,8 @@ #include <SFML/Graphics/RenderWindow.hpp> #include <SFML/System/Vector2.hpp> +#include <SFML/Window/Event.hpp> +#include <SFML/Window/Keyboard.hpp> #include <memory> #include <optional> #include <string> @@ -13,6 +15,17 @@ #include "tileset.hpp" namespace silly::editor { + void Editor::update(const sf::Event &event) { + if (const auto *e = event.getIf<sf::Event::KeyPressed>()) { + if (e->code == sf::Keyboard::Key::R) { + this->rotation += 90.0f; + if (this->rotation >= 360.0f) { + this->rotation = 0.0f; + } + } + } + } + void Editor::update(const sf::RenderWindow &window) { if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) || sf::Mouse::isButtonPressed(sf::Mouse::Button::Right)) { @@ -28,7 +41,8 @@ namespace silly::editor { if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && this->selectedTile.has_value()) { - this->floor.place_tile(this->selectedTile.value(), pos); + this->floor.place_tile(this->selectedTile.value(), pos, + this->rotation); } else if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Right)) { this->floor.remove_tile(pos); } @@ -54,6 +68,7 @@ namespace silly::editor { ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar); // --- SELECTED TILE --- + ImGui::BeginChild("SelectedTileRegion", ImVec2(200, 100)); if (this->selectedTile.has_value()) { TilesetTile *t = this->selectedTile->get(); @@ -70,6 +85,14 @@ namespace silly::editor { ImGui::Text("NO TILE SELECTED!"); ImGui::Dummy(ImVec2(64, 64)); } + ImGui::EndChild(); + + ImGui::SameLine(); + + // --- EDITOR SETTINGS --- + ImGui::BeginChild("EditorSettingsRegion", ImVec2(170, 100)); + ImGui::Text("Rotation is %.0f degrees", this->rotation); + ImGui::EndChild(); // --- TILE SELECTION --- ImGui::BeginChild("TileSelectionRegion", ImVec2(0, 400), |
