Skip to content

Commit ce739ed

Browse files
committed
fix: JSON::Impl::SettingLoad<>
1 parent 2081335 commit ce739ed

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

include/REX/REX/JSON.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,9 @@ namespace REX::JSON
3030
{
3131
public:
3232
Setting(path_t a_path, T a_default) :
33-
TSetting<T, Store>(a_default)
34-
{
35-
if (a_path[0] != '/') {
36-
m_path = std::format("/{}"sv, a_path);
37-
} else {
38-
m_path = std::move(a_path);
39-
}
40-
}
33+
TSetting<T, Store>(a_default),
34+
m_path(a_path)
35+
{}
4136

4237
public:
4338
virtual void Load(void* a_data, bool a_isBase) override

src/REX/REX/JSON.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,26 @@ namespace REX::JSON
1717
T& a_valueDefault)
1818
{
1919
const auto& json = *static_cast<glz::json_t*>(a_data);
20-
a_value = glz::get<T>(json, a_path).value_or(a_valueDefault);
20+
if (a_path[0] != '/') {
21+
const auto path = std::format("/{}sv", a_path);
22+
REX::DEBUG("path: {}", path);
23+
auto value = glz::get<T>(json, path);
24+
if (value.has_value()) {
25+
REX::DEBUG("no value");
26+
a_value = value->get();
27+
} else {
28+
a_value = a_valueDefault;
29+
}
30+
} else {
31+
auto value = glz::get<T>(json, a_path);
32+
REX::DEBUG("a_path: {}", a_path);
33+
if (value.has_value()) {
34+
REX::DEBUG("no value");
35+
a_value = value->get();
36+
} else {
37+
a_value = a_valueDefault;
38+
}
39+
}
2140
}
2241

2342
template void SettingLoad<bool>(void*, path_t, bool&, bool&);
@@ -38,7 +57,12 @@ namespace REX::JSON
3857
T& a_value)
3958
{
4059
auto& json = *static_cast<glz::json_t*>(a_data);
41-
glz::set(json, a_path, a_value);
60+
if (a_path[0] != '/') {
61+
const auto path = std::format("/{}"sv, a_path);
62+
glz::set(json, path, a_value);
63+
} else {
64+
glz::set(json, a_path, a_value);
65+
}
4266
}
4367

4468
template void SettingSave<bool>(void*, path_t, bool&);

0 commit comments

Comments
 (0)