summaryrefslogtreecommitdiffhomepage
path: root/editor/scenery-editor.cpp
blob: 612bfb7817eebec6f4ab971fb8bc72db15b18a8d (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
#include "scenery-editor.hpp"
#include "src/anim-atlas.hpp"
#include "loader/loader.hpp"
#include "compat/assert.hpp"

namespace floormat {

using rotation_ = rotation;
using rotation_t = std::underlying_type_t<rotation_>;

scenery_editor::scenery_editor() noexcept
{
    load_atlases();
}

void scenery_editor::set_rotation(rotation_ r)
{
    if (_selected.proto.atlas)
    {
        (void)_selected.proto.atlas->group(r);
        _selected.proto.frame.r = r;
    }
}

rotation_ scenery_editor::rotation() const
{
    return _selected.proto.frame.r;
}

void scenery_editor::next_rotation()
{
    if (auto& proto = _selected.proto; proto.atlas)
        proto.frame.r = proto.atlas->next_rotation_from(proto.frame.r);
}

void scenery_editor::prev_rotation()
{
    if (auto& proto = _selected.proto; proto.atlas)
        proto.frame.r = proto.atlas->prev_rotation_from(proto.frame.r);
}

void scenery_editor::select_tile(const scenery_& s)
{
    _selected = s;
}

void scenery_editor::clear_selection()
{
    _selected = {};
}

auto scenery_editor::get_selected() -> const scenery_&
{
    return _selected;
}

bool scenery_editor::is_atlas_selected(const std::shared_ptr<anim_atlas>& atlas) const
{
    return atlas == _selected.proto.atlas;
}

bool scenery_editor::is_item_selected(const scenery_& s) const
{
    return s.name == _selected.name && s.proto.atlas == _selected.proto.atlas;
}

} // namespace floormat