|
14 | 14 | template<> |
15 | 15 | struct matjson::Serialize<Settings> { |
16 | 16 | static Result<Settings> fromJson(const matjson::Value& value) { |
17 | | - Settings defaults; |
18 | | - |
19 | | - return Ok(Settings { |
20 | | - .GDInWindow = value["game_in_window"].asBool().unwrapOr(std::move(defaults.GDInWindow)), |
21 | | - .attributesInTree = value["attributes_in_tree"].asBool().unwrapOr(std::move(defaults.attributesInTree)), |
22 | | - .alwaysHighlight = value["always_highlight"].asBool().unwrapOr(std::move(defaults.alwaysHighlight)), |
23 | | - .highlightLayouts = value["highlight_layouts"].asBool().unwrapOr(std::move(defaults.highlightLayouts)), |
24 | | - .arrowExpand = value["arrow_expand"].asBool().unwrapOr(std::move(defaults.arrowExpand)), |
25 | | - .orderChildren = value["order_children"].asBool().unwrapOr(std::move(defaults.orderChildren)), |
26 | | - .advancedSettings = value["advanced_settings"].asBool().unwrapOr(std::move(defaults.advancedSettings)), |
27 | | - .showMemoryViewer = value["show_memory_viewer"].asBool().unwrapOr(std::move(defaults.showMemoryViewer)), |
28 | | - .showModGraph = value["show_mod_graph"].asBool().unwrapOr(std::move(defaults.showModGraph)), |
29 | | - .theme = value["theme"].asString().unwrapOr(std::move(defaults.theme)), |
30 | | - .themeColor = value["theme_color"].as<ccColor4B>().isOk() ? value["theme_color"].as<ccColor4B>().unwrap() : std::move(defaults.themeColor), |
31 | | - .buttonPos = CCPoint{ |
32 | | - value["button_x"].as<float>().isOk() ? value["button_x"].as<float>().unwrap() : std::move(defaults.buttonPos.x), |
33 | | - value["button_y"].as<float>().isOk() ? value["button_y"].as<float>().unwrap() : std::move(defaults.buttonPos.y) |
34 | | - }, |
35 | | - .buttonInEditor = value["button_editor"].asBool().isOk() ? value["button_editor"].asBool().unwrap() : std::move(defaults.buttonInEditor), |
36 | | - .buttonInGame = value["button_game"].asBool().isOk() ? value["button_game"].asBool().unwrap() : std::move(defaults.buttonInGame) |
37 | | - }); |
| 17 | + Settings s; |
| 18 | + |
| 19 | + const auto assign = [](const matjson::Value& json, auto& prop) { |
| 20 | + if (auto res = json.as<std::decay_t<decltype(prop)>>()) prop = res.unwrap(); |
| 21 | + }; |
| 22 | + |
| 23 | + assign(value["game_in_window"], s.GDInWindow); |
| 24 | + assign(value["attributes_in_tree"], s.attributesInTree); |
| 25 | + assign(value["always_highlight"], s.alwaysHighlight); |
| 26 | + assign(value["highlight_layouts"], s.highlightLayouts); |
| 27 | + assign(value["arrow_expand"], s.arrowExpand); |
| 28 | + assign(value["order_children"], s.orderChildren); |
| 29 | + assign(value["advanced_settings"], s.advancedSettings); |
| 30 | + assign(value["show_memory_viewer"], s.showMemoryViewer); |
| 31 | + assign(value["show_mod_graph"], s.showModGraph); |
| 32 | + assign(value["theme"], s.theme); |
| 33 | + assign(value["theme_color"], s.themeColor); |
| 34 | + assign(value["button_x"], s.buttonPos.x); |
| 35 | + assign(value["button_y"], s.buttonPos.y); |
| 36 | + assign(value["button_editor"], s.buttonInEditor); |
| 37 | + assign(value["button_game"], s.buttonInGame); |
| 38 | + |
| 39 | + return Ok(s); |
38 | 40 | } |
39 | 41 |
|
40 | 42 | static matjson::Value toJson(const Settings& settings) { |
@@ -181,7 +183,7 @@ void DevTools::drawPages() { |
181 | 183 |
|
182 | 184 | if (m_settings.showMemoryViewer) { |
183 | 185 | this->drawPage( |
184 | | - U8STR(FEATHER_TERMINAL " Memory viewer"), |
| 186 | + U8STR(FEATHER_TERMINAL " Memory viewer"), |
185 | 187 | &DevTools::drawMemory |
186 | 188 | ); |
187 | 189 | } |
|
0 commit comments