summaryrefslogtreecommitdiffhomepage
path: root/editor/vobj-editor.hpp
blob: 0057504ca8ee8c134f63e73ad828a7e45f6b7e77 (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
#pragma once
#include "src/object-type.hpp"
#include "src/object-id.hpp"
#include <memory>
#include <map>
#include <cr/String.h>

namespace floormat {

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

struct vobj_factory
{
    vobj_factory();
    virtual ~vobj_factory() noexcept;
    virtual const vobj_cell& 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;
};

class vobj_editor final
{
public:
    struct vobj_ final {
        String 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<String, vobj_> make_vobj_type_map();

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

} // namespace floormat