summaryrefslogtreecommitdiff
path: root/include/mbgl/style/conversion/transition_options.hpp
blob: de8834d578fad674f25fdf579a443457a56c9882 (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
#pragma once

#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/conversion.hpp>

namespace mbgl {
namespace style {
namespace conversion {

template <>
struct Converter<TransitionOptions> {
public:
    template <class V>
    optional<TransitionOptions> operator()(const V& value, Error& error) const {
        if (!isObject(value)) {
            error = { "transition must be an object" };
            return {};
        }

        TransitionOptions result;

        auto duration = objectMember(value, "duration");
        if (duration) {
            auto number = toNumber(*duration);
            if (!number) {
                error = { "duration must be a number" };
                return {};
            }
            result.duration = { std::chrono::milliseconds(int64_t(*number)) };
        }

        auto delay = objectMember(value, "delay");
        if (delay) {
            auto number = toNumber(*delay);
            if (!number) {
                error = { "delay must be a number" };
                return {};
            }
            result.delay = { std::chrono::milliseconds(int64_t(*number)) };
        }

        return result;
    }
};

} // namespace conversion
} // namespace style
} // namespace mbgl