summaryrefslogtreecommitdiffhomepage
path: root/editor/vobj-editor.hpp
blob: d847701128586844923c587c4efab3192fe05d2b (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
71
72
73
74
75
#pragma once
#include "src/object-type.hpp"
#include "src/object-id.hpp"
#include <memory>
#include <map>
#include <Corrade/Containers/StringView.h>

namespace Corrade::Containers {
template<typename T> class BasicStringView;
using StringView = BasicStringView<const char>;
} // namespace Corrade::Containers

namespace floormat {

struct world;
struct global_coords;
struct object;
struct 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