summaryrefslogtreecommitdiffhomepage
path: root/editor/vobj-editor.hpp
blob: e92c6abeb3da33a42b8658a744c7e100638359eb (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include "src/object-type.hpp"
#include "src/object-id.hpp"
#include <memory>
#include <map>
#include <Corrade/Containers/StringView.h>

namespace floormat {

struct world;
struct global_coords;
struct object;
class anim_atlas;
struct vobj_info;
struct app;

#if defined __clang__ || defined __CLION_IDE__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wweak-vtables"
#endif

struct vobj_factory
{
    vobj_factory();
    virtual ~vobj_factory() noexcept;
    virtual const vobj_info& info() const = 0;
    virtual object_type type() const = 0;
    virtual std::shared_ptr<object> make(world& w, object_id id, global_coords pos) const = 0;

    StringView name() const;
    StringView descr() const;
    std::shared_ptr<anim_atlas> atlas() const;
};

#if defined __clang__ || defined __CLION_IDE__
#pragma clang diagnostic pop
#endif

struct vobj_editor final
{
    struct vobj_ final {
        StringView name, descr;
        std::unique_ptr<vobj_factory> factory;
    };

    vobj_editor();

    void select_tile(const vobj_& type);
    void clear_selection();
    const vobj_* get_selected() const;

    const vobj_* get_type(StringView name);
    bool is_item_selected(const vobj_& x) const;
    bool is_anything_selected() const;

    static void place_tile(world& w, global_coords pos, const vobj_* x, app& a);

    auto cbegin() const noexcept { return _types.cbegin(); }
    auto cend() const noexcept { return _types.cend(); }
    auto begin() const noexcept { return _types.cbegin(); }
    auto end() const noexcept { return _types.cend(); }

private:
    static std::map<StringView, vobj_> make_vobj_type_map();

    std::map<StringView, vobj_> _types = make_vobj_type_map();
    const vobj_* _selected = nullptr;
};

} // namespace floormat