#pragma once #include "compat/defs.hpp" #include "tile-atlas.hpp" #include "global-coords.hpp" #include "tile.hpp" #include #include #include #include #include #include #include #include namespace floormat { enum class editor_mode : unsigned char { none, floor, walls, }; enum class editor_wall_rotation : std::uint8_t { N, W, }; struct world; struct tile_editor final { private: enum selection_mode : std::uint8_t { sel_none, sel_tile, sel_perm, }; std::string _name; std::map> _atlases; tile_image_proto _selected_tile; std::tuple, std::vector> _permutation; selection_mode _selection_mode = sel_none; editor_mode _mode; editor_wall_rotation _rotation = editor_wall_rotation::N; void load_atlases(); tile_image_proto get_selected_perm(); public: enum class snap_mode : std::uint8_t { none = 0, horizontal = 1 << 0, vertical = 1 << 1, }; tile_editor(editor_mode mode, StringView name); std::shared_ptr maybe_atlas(StringView str); std::shared_ptr atlas(StringView str); auto cbegin() const noexcept { return _atlases.cbegin(); } auto cend() const noexcept { return _atlases.cend(); } auto begin() const noexcept { return _atlases.cbegin(); } auto end() const noexcept { return _atlases.cend(); } StringView name() const noexcept { return _name; } editor_mode mode() const noexcept { return _mode; } editor_wall_rotation rotation() const noexcept { return _rotation; } void clear_selection(); void select_tile(const std::shared_ptr& atlas, std::size_t variant); void select_tile_permutation(const std::shared_ptr& atlas); bool is_tile_selected(const std::shared_ptr& atlas, std::size_t variant) const; bool is_permutation_selected(const std::shared_ptr& atlas) const; bool is_atlas_selected(const std::shared_ptr& atlas) const; tile_image_proto get_selected(); void place_tile(world& world, global_coords pos, const tile_image_proto& img); void toggle_rotation(); void set_rotation(editor_wall_rotation r); snap_mode check_snap(int mods) const; bool can_rotate() const; }; struct editor final { [[nodiscard]] bool dirty() const noexcept { return _dirty; } void set_dirty(bool value) noexcept { _dirty = value; } [[nodiscard]] editor_mode mode() const noexcept { return _mode; } void set_mode(editor_mode mode); tile_editor* current() noexcept; const tile_editor* current() const noexcept; enum class button : std::uint8_t { none, place, remove, }; void on_click(world& world, global_coords pos, int mods, button b); void on_click_(world& world, global_coords pos, button b); void on_mouse_move(world& world, global_coords& pos, int modifiers); void on_release(); editor(); editor(editor&&) noexcept = default; editor& operator=(editor&&) noexcept = default; fm_DECLARE_DELETED_COPY_ASSIGNMENT(editor); static constexpr inline auto rotation_N = editor_wall_rotation::N; static constexpr inline auto rotation_W = editor_wall_rotation::W; using snap_mode = tile_editor::snap_mode; private: snap_mode get_snap_value(snap_mode snap, int mods) const; static global_coords apply_snap(global_coords pos, global_coords last, snap_mode snap) noexcept; tile_editor _floor{ editor_mode::floor, "floor" }; tile_editor _wall { editor_mode::walls, "wall" }; struct drag_pos final { global_coords coord, draw_coord; snap_mode snap = snap_mode::none; button btn; }; std::optional _last_pos; editor_mode _mode = editor_mode::floor; bool _dirty = false; }; } // namespace floormat