summaryrefslogtreecommitdiffhomepage
path: root/editor/ground-editor.hpp
blob: b27065f008c00afeb23bd48b366d377817d50aab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "compat/safe-ptr.hpp"
#include "editor-enums.hpp"
#include "src/tile-image.hpp"
#include "src/global-coords.hpp"
#include <map>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/String.h>

namespace floormat {

class world;
struct ground_cell;

class ground_editor final
{
    enum selection_mode : unsigned char { sel_none, sel_tile, sel_perm, };
    struct tuple;

    std::map<StringView, ground_cell> _atlases;
    tile_image_proto _selected_tile;
    safe_ptr<tuple> _permutation;
    selection_mode _selection_mode = sel_none;

    void load_atlases();
    tile_image_proto get_selected_perm();

public:
    ground_editor();
    ~ground_editor() noexcept;
    bptr<ground_atlas> maybe_atlas(StringView str);
    bptr<ground_atlas> atlas(StringView str);
    typename std::map<StringView, ground_cell>::const_iterator begin() const noexcept;
    typename std::map<StringView, ground_cell>::const_iterator end() const noexcept;
    StringView name() const noexcept;

    void clear_selection();
    void select_tile(const bptr<ground_atlas>& atlas, size_t variant);
    void select_tile_permutation(const bptr<ground_atlas>& atlas);
    bool is_tile_selected(const bptr<const ground_atlas>& atlas, size_t variant) const;
    bool is_permutation_selected(const bptr<const ground_atlas>& atlas) const;
    bool is_atlas_selected(const bptr<const ground_atlas>& atlas) const;
    bool is_anything_selected() const;
    tile_image_proto get_selected();
    void place_tile(world& world, global_coords pos, const tile_image_proto& img);
    editor_snap_mode check_snap(int mods) const;
};

} // namespace floormat