summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-12-11 18:26:38 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-12-11 18:26:38 +0100
commit6944f24118eee8135f2465bed4f728fe1445f723 (patch)
tree920578957aaeb9370050d7dad53627dabd56b7f1
parent34f63343a30b3fdcd1808e23b899f738adbebd84 (diff)
a
-rw-r--r--editor/editor.cpp2
-rw-r--r--editor/wall-editor.cpp66
-rw-r--r--editor/wall-editor.hpp4
-rw-r--r--src/wall-atlas.cpp3
4 files changed, 70 insertions, 5 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 816f73e3..984fa0a1 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -137,7 +137,7 @@ void editor::on_click_(world& world, global_coords pos, button b)
{
default: break;
case button::place:
- if (const auto& sel = mode->get_selected())
+ if (const auto* sel = mode->get_selected())
mode->place_tile(world, pos, sel, *_app);
break;
case button::remove:
diff --git a/editor/wall-editor.cpp b/editor/wall-editor.cpp
index e1fc96cb..faa7a260 100644
--- a/editor/wall-editor.cpp
+++ b/editor/wall-editor.cpp
@@ -1,6 +1,72 @@
#include "wall-editor.hpp"
+#include "src/wall-defs.hpp"
+#include "src/wall-atlas.hpp"
+#include "loader/loader.hpp"
+#include "loader/wall-info.hpp"
+#include <Corrade/Containers/ArrayView.h>
namespace floormat {
+using namespace floormat::Wall;
+
+namespace {
+
+struct rot_pair { rotation r; Direction_ d; };
+
+constexpr inline rot_pair rot_map[] = {
+ { rotation::N, Direction_::N },
+ { rotation::W, Direction_::W },
+};
+static_assert(std::size(rot_map) == Direction_COUNT);
+
+constexpr rotation dir_to_rot(Direction_ D)
+{
+ for (auto [r, d] : rot_map)
+ if (D == d)
+ return r;
+ fm_abort("invalid rotation '%d'!", (int)D);
+}
+
+constexpr Direction_ rot_to_dir(rotation R)
+{
+ for (auto [r, d] : rot_map)
+ if (r == R)
+ return d;
+ fm_abort("invalid rotation '%d'!", (int)R);
+}
+
+constexpr rotation next_rot(rotation r)
+{
+ auto dir_0 = (unsigned)rot_to_dir(r);
+ auto dir_1 = (dir_0 + 1) % Direction_COUNT;
+ return dir_to_rot((Direction_)dir_1);
+}
+static_assert(next_rot(rotation::N) == rotation::W);
+static_assert(next_rot(rotation::W) == rotation::N);
+
+} // namespace
+
+void wall_editor::load_atlases()
+{
+ fm_assert(_atlases.empty());
+ for (const auto& [name, _, atlas] : loader.wall_atlas_list())
+ _atlases[name] = atlas;
+ fm_assert(!_atlases.empty());
+}
+
+wall_editor::wall_editor()
+{
+ load_atlases();
+}
+
+StringView wall_editor::name() const { return "wall"_s; }
+enum rotation wall_editor::rotation() const { return _r; }
+void wall_editor::set_rotation(enum rotation r) { _r = r; }
+void wall_editor::toggle_rotation() { _r = next_rot(_r); }
+const wall_atlas* wall_editor::get_selected() const { return _selected_atlas.get(); }
+void wall_editor::select_atlas(const std::shared_ptr<wall_atlas>& atlas) { _selected_atlas = atlas; }
+void wall_editor::clear_selection() { _selected_atlas = nullptr; }
+bool wall_editor::is_atlas_selected(const std::shared_ptr<wall_atlas>& atlas) const { return _selected_atlas == atlas; }
+bool wall_editor::is_anything_selected() const { return _selected_atlas != nullptr; }
} // namespace floormat
diff --git a/editor/wall-editor.hpp b/editor/wall-editor.hpp
index 815b91c6..b23cab60 100644
--- a/editor/wall-editor.hpp
+++ b/editor/wall-editor.hpp
@@ -22,11 +22,11 @@ public:
wall_editor();
StringView name() const;
- enum rotation rotation() const { return _r; }
+ enum rotation rotation() const;
void set_rotation(enum rotation r);
void toggle_rotation();
- std::shared_ptr<wall_atlas> get_selected() const { return _selected_atlas; }
+ const wall_atlas* get_selected() const;
void select_atlas(const std::shared_ptr<wall_atlas>& atlas);
void clear_selection();
bool is_atlas_selected(const std::shared_ptr<wall_atlas>& atlas) const;
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index 71f20b40..568aee83 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -61,10 +61,9 @@ wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img)
_image_size{get_image_size(img)},
_direction_map{def.direction_map}
{
- fm_soft_assert(!_frame_array.empty());
-
{
const auto frame_count = _frame_array.size();
+ fm_soft_assert(frame_count > 0);
bool found = false;
for (auto [dir_name, dir] : wall_atlas::directions)
{