summaryrefslogtreecommitdiffhomepage
path: root/editor/vobj-editor.hpp
blob: 3ebf7bd865726267293fc305f2e5036e55aa2bcc (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
#pragma once
#include "src/entity-type.hpp"
#include <memory>
//#include <Corrade/Containers/ArrayView.h>

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

namespace floormat {

struct world;
struct global_coords;
struct entity;
struct anim_atlas;
struct vobj_info;

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wweak-vtables"
#endif

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

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

#ifdef __clang__
#pragma clang diagnostic pop
#endif

struct vobj_editor final
{
    vobj_editor();

    void select_type(entity_type type);
    void clear_selection();

    [[nodiscard]] static const vobj_factory* get_factory(entity_type type);
    bool is_type_selected(entity_type type) const;
    bool is_anything_selected() const;

    static void place_tile(world& w, global_coords pos, const vobj_factory& factory);

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

private:
    static const ArrayView<const vobj_factory* const> _types;
    const vobj_factory* _selected = nullptr;
};

} // namespace floormat