diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-06 20:23:23 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-06 20:23:23 +0100 |
| commit | e611d6c12085d32c2e024bf1b544d4c32bae1738 (patch) | |
| tree | 0dbdc8bce4d4d0ccc26a51f6f7d4f2546437aafe /editor | |
| parent | b82ebb0339a15cc05e26f9cdca646022e6b71ef4 (diff) | |
a
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/scenery-editor.cpp | 57 | ||||
| -rw-r--r-- | editor/scenery-editor.hpp | 13 | ||||
| -rw-r--r-- | editor/tile-editor.hpp | 2 |
3 files changed, 57 insertions, 15 deletions
diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index c3b29c9d..ac84abc8 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -1,40 +1,77 @@ #include "scenery-editor.hpp" #include "src/anim-atlas.hpp" +#include "src/loader.hpp" +#include "compat/assert.hpp" namespace floormat { using rotation_ = enum rotation; using rotation_t = std::underlying_type_t<rotation_>; -scenery_editor::scenery_editor() noexcept -{ -} +scenery_editor::pair::operator bool() const { return atlas != nullptr; } + +scenery_editor::scenery_editor() noexcept = default; void scenery_editor::set_rotation(enum rotation r) { - _selected.s.r = r; + _selected.r = r; } rotation scenery_editor::rotation() const { - return _selected.s.r; + return _selected.r; } void scenery_editor::next_rotation() { - auto r_1 = (rotation_t)_selected.s.r + 1; + auto r_1 = (rotation_t)_selected.r + 1; auto rot = (rotation_)r_1; if (rot >= rotation_::COUNT) rot = (rotation_)0; - _selected.s.r = rot; + _selected.r = rot; } void scenery_editor::prev_rotation() { - if (_selected.s.r == (rotation_)0) - _selected.s.r = (rotation_)((rotation_t)rotation_::COUNT - 1); + if (_selected.r == (rotation_)0) + _selected.r = (rotation_)((rotation_t)rotation_::COUNT - 1); else - _selected.s.r = (rotation_)((rotation_t)_selected.s.r - 1); + _selected.r = (rotation_)((rotation_t)_selected.r - 1); +} + +//return atlas == _selected.atlas && r == _selected.s.r && frame == _selected.s.frame; + +void scenery_editor::select_tile(const std::shared_ptr<anim_atlas>& atlas, rotation_ r, frame_t frame) +{ + fm_assert(frame < atlas->group(r).frames.size()); + _selected = { atlas, r, frame }; +} + +void scenery_editor::clear_selection() +{ + _selected = { nullptr, rotation::COUNT, scenery::NO_FRAME }; +} + +auto scenery_editor::get_selected() -> pair +{ + return _selected; +} + +bool scenery_editor::is_atlas_selected(const std::shared_ptr<anim_atlas>& atlas) const +{ + return _selected.atlas == atlas; +} + +bool scenery_editor::is_item_selected(const std::shared_ptr<anim_atlas>& atlas, enum rotation r, frame_t frame) const +{ + return is_atlas_selected(atlas) && _selected.r == r && _selected.frame == frame; +} + +void scenery_editor::load_atlases() +{ + _atlases.clear(); + for (StringView str : loader.anim_atlas_list()) + _atlases[str] = loader.anim_atlas(str); } } // namespace floormat diff --git a/editor/scenery-editor.hpp b/editor/scenery-editor.hpp index f4b40c66..9b89d2da 100644 --- a/editor/scenery-editor.hpp +++ b/editor/scenery-editor.hpp @@ -10,9 +10,13 @@ struct anim_atlas; struct scenery_editor final { + using frame_t = scenery::frame_t; + struct pair final { std::shared_ptr<anim_atlas> atlas; - scenery s; + enum rotation r = rotation::COUNT; + frame_t frame = scenery::NO_FRAME; + operator bool() const; }; scenery_editor() noexcept; @@ -22,10 +26,11 @@ struct scenery_editor final void next_rotation(); void prev_rotation(); - void select_tile(const std::shared_ptr<anim_atlas>& atlas, enum rotation r, std::uint16_t frame); + void select_tile(const std::shared_ptr<anim_atlas>& atlas, enum rotation r, frame_t frame); void clear_selection(); - bool is_atlas_selected() const; - bool is_item_selected(const std::shared_ptr<anim_atlas>& atlas, enum rotation r, std::uint16_t frame) const; + pair get_selected(); + bool is_atlas_selected(const std::shared_ptr<anim_atlas>& atlas) const; + bool is_item_selected(const std::shared_ptr<anim_atlas>& atlas, enum rotation r, frame_t frame) const; private: void load_atlases(); diff --git a/editor/tile-editor.hpp b/editor/tile-editor.hpp index 4089ca62..0458ee79 100644 --- a/editor/tile-editor.hpp +++ b/editor/tile-editor.hpp @@ -1,7 +1,7 @@ #pragma once #include "editor-enums.hpp" -#include "tile-image.hpp" +#include "src/tile-image.hpp" #include "global-coords.hpp" #include <tuple> #include <memory> |
