-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathProfile.cpp
More file actions
46 lines (38 loc) · 1.33 KB
/
Profile.cpp
File metadata and controls
46 lines (38 loc) · 1.33 KB
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
#include "Profile.h"
#include "Abyss/Common/JSON.h"
#include "Abyss/Singletons.h"
#include <format>
#include <nlohmann/json.hpp>
#include <stdexcept>
namespace OD2::Layouts {
namespace {
nlohmann::json readMergedProfile(std::string_view name) {
nlohmann::json me =
Abyss::Common::parseJson(Abyss::Singletons::getFileProvider().loadString(std::format("/data/global/ui/layouts/_profile{}.json", name)));
if (me.contains("basedOn")) {
nlohmann::json base = readMergedProfile(me["basedOn"].get<std::string_view>());
base.merge_patch(me);
return base;
}
return me;
}
bool resolveDataReferences(nlohmann::json &object, const nlohmann::json &profile) {
bool again = false;
for (auto &[k, v] : object.items()) {
if (v.is_structured()) {
again = resolveDataReferences(v, profile) || again;
} else if (v.is_string() && v.get<std::string_view>().starts_with('$')) {
v = profile.at(v.get<std::string_view>().substr(1));
again = true;
}
}
return again;
}
} // namespace
Profile::Profile(std::string_view name) {
_data = readMergedProfile(name);
while (resolveDataReferences(_data, _data)) {
}
}
void Profile::resolveReferences(nlohmann::json &object) const { resolveDataReferences(object, _data); }
} // namespace OD2::Layouts