summaryrefslogtreecommitdiffhomepage
path: root/editor/scenery-editor.cpp
blob: a3560d2f1082a36fff44a0afd2de3ab7155d89bd (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
76
77
78
79
80
#include "scenery-editor.hpp"
#include "src/anim-atlas.hpp"
#include "src/loader.hpp"
#include "compat/assert.hpp"

namespace floormat {

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

scenery_editor::pair::operator bool() const { return atlas != nullptr; }

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

void scenery_editor::set_rotation(rotation_ r)
{
    _selected.r = r;
}

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

void scenery_editor::next_rotation()
{
    auto r_1 = (rotation_t)_selected.r + 1;
    auto rot = (rotation_)r_1;
    if (rot >= rotation_::COUNT)
        rot = (rotation_)0;
    _selected.r = rot;
}

void scenery_editor::prev_rotation()
{
    if (_selected.r == (rotation_)0)
        _selected.r = (rotation_)((rotation_t)rotation_::COUNT - 1);
    else
        _selected.r = (rotation_)((rotation_t)_selected.r - 1);
}

//return atlas == _selected.atlas && r == _selected.s.r && frame == _selected.s.frame;

void scenery_editor::select_tile(const std::shared_ptr<anim_atlas>& atlas, rotation_ r, frame_t frame)
{
    fm_assert(frame < atlas->group(r).frames.size());
    _selected = { atlas, r, frame };
}

void scenery_editor::clear_selection()
{
    _selected = { nullptr, rotation_::COUNT, scenery::NO_FRAME };
}

auto scenery_editor::get_selected() -> pair
{
    return _selected;
}

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

bool scenery_editor::is_item_selected(const std::shared_ptr<anim_atlas>& atlas, rotation_ r, frame_t frame) const
{
    return is_atlas_selected(atlas) && _selected.r == r && _selected.frame == frame;
}

void scenery_editor::load_atlases()
{
    _atlases.clear();
    for (StringView str : loader.anim_atlas_list())
        _atlases[str] = loader.anim_atlas(str);
}

} // namespace floormat