diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-20 23:08:45 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-20 23:11:32 +0200 |
commit | d22abc50862f7243228c93fd2fd3878b37821487 (patch) | |
tree | 26d388a2d86132cd6d5df4295d5affa216e02cb4 | |
parent | 3e1199836bf8eb752afe9d4d20b121c8a23e87d5 (diff) |
some editor stuff
-rw-r--r-- | main/editor.cpp | 24 | ||||
-rw-r--r-- | main/editor.hpp | 7 | ||||
-rw-r--r-- | main/update.cpp | 2 |
3 files changed, 28 insertions, 5 deletions
diff --git a/main/editor.cpp b/main/editor.cpp index 21a72aa0..38697a30 100644 --- a/main/editor.cpp +++ b/main/editor.cpp @@ -6,6 +6,7 @@ #include "compat/assert.hpp" #include "compat/unreachable.hpp" #include "src/tile-defs.hpp" +#include "src/world.hpp" #include <Corrade/Containers/StringStlView.h> #include <filesystem> #include <vector> @@ -128,15 +129,34 @@ std::optional<std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>> tile_type:: } } +void tile_type::place_tile(world& world, global_coords pos) +{ + const auto& [c, t] = world[pos]; + switch (_mode) + { + case editor_mode::select: + WARN("wrong tile mode 'select'"); break; + case editor_mode::floor: + + case editor_mode::walls: + break; // todo + } +} + editor::editor() { } -void editor::maybe_place_tile(const global_coords pos, int mouse_button) +void editor::maybe_place_tile(world& world, const global_coords pos, int mouse_button) { if (mouse_button == 0) { - // TODO + switch (_mode) + { + case editor_mode::select: break; + case editor_mode::floor: _floor.place_tile(world, pos); break; + case editor_mode::walls: break; // TODO + } } } diff --git a/main/editor.hpp b/main/editor.hpp index c66ccff1..88740b35 100644 --- a/main/editor.hpp +++ b/main/editor.hpp @@ -16,6 +16,8 @@ enum class editor_mode : unsigned char { select, floor, walls, }; +struct world; + struct tile_type final { tile_type(editor_mode mode, Containers::StringView name); @@ -36,6 +38,7 @@ struct tile_type final bool is_tile_selected(const std::shared_ptr<tile_atlas>& atlas, std::uint8_t variant); bool is_permutation_selected(const std::shared_ptr<tile_atlas>& atlas); std::optional<std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>> get_selected(); + void place_tile(world& world, global_coords pos); private: enum selection_mode : std::uint8_t { @@ -67,7 +70,7 @@ struct editor final tile_type& floor() { return _floor; } const tile_type& floor() const { return _floor; } - void maybe_place_tile(global_coords pos, int mouse_button); + void maybe_place_tile(world& world, global_coords pos, int mouse_button); editor(); editor(editor&&) noexcept = default; @@ -76,7 +79,7 @@ struct editor final private: tile_type _floor{editor_mode::floor, "floor"}; - editor_mode _mode = {}; + editor_mode _mode = editor_mode::select; bool _dirty = false; }; diff --git a/main/update.cpp b/main/update.cpp index c726f542..0d93b0c2 100644 --- a/main/update.cpp +++ b/main/update.cpp @@ -18,7 +18,7 @@ void app::make_test_chunk(chunk& c) void app::do_mouse_click(const global_coords pos, int button) { - _editor.maybe_place_tile(pos, button); + _editor.maybe_place_tile(_world, pos, button); } void app::update(double dt) |