@@ -14,34 +14,39 @@ using Controls = std::variant<input::KeyboardSettings, input::JoystickSettings,
1414namespace nlohmann {
1515 template <>
1616 struct adl_serializer <Controls> {
17- static Controls from_json (const json& j ) {
18- const auto & type = j .at (" type" );
17+ static Controls from_json (const json& obj ) {
18+ const auto & type = obj .at (" type" );
1919
2020 if (type == " keyboard" ) {
21- return Controls{ nlohmann::adl_serializer<input::KeyboardSettings>::from_json (j) };
22- } else if (type == " joystick" ) {
23- return Controls{ nlohmann::adl_serializer<input::JoystickSettings>::from_json (j) };
24- } else if (type == " touch" ) {
25- return Controls{ nlohmann::adl_serializer<input::TouchSettings>::from_json (j) };
26- } else {
27- throw std::runtime_error{ fmt::format (" unsupported control type '{}'" , to_string (type)) };
21+ return Controls{ nlohmann::adl_serializer<input::KeyboardSettings>::from_json (obj) };
2822 }
23+
24+ if (type == " joystick" ) {
25+ return Controls{ nlohmann::adl_serializer<input::JoystickSettings>::from_json (obj) };
26+ }
27+
28+ if (type == " touch" ) {
29+ return Controls{ nlohmann::adl_serializer<input::TouchSettings>::from_json (obj) };
30+ }
31+
32+ throw std::runtime_error{ fmt::format (" unsupported control type '{}'" , to_string (type)) };
2933 }
3034
31- static void to_json (json& j , Controls controls) {
35+ static void to_json (json& obj , Controls controls) { // NOLINT(misc-no-recursion)
3236 std::visit (
33- helper::overloaded{ [&](const input::KeyboardSettings& keyboard_settings) {
34- to_json (j, keyboard_settings);
35- j[" type" ] = " keyboard" ;
36- },
37- [&](const input::JoystickSettings& joystick_settings) {
38- to_json (j, joystick_settings);
39- j[" type" ] = " joystick" ;
40- },
41- [&](const input::TouchSettings& touch_settings) {
42- to_json (j, touch_settings);
43- j[" type" ] = " touch" ;
44- } },
37+ helper::overloaded{
38+ [&](const input::KeyboardSettings& keyboard_settings) { // NOLINT(misc-no-recursion)
39+ to_json (obj, keyboard_settings);
40+ obj[" type" ] = " keyboard" ;
41+ },
42+ [&](const input::JoystickSettings& joystick_settings) { // NOLINT(misc-no-recursion)
43+ to_json (obj, joystick_settings);
44+ obj[" type" ] = " joystick" ;
45+ },
46+ [&](const input::TouchSettings& touch_settings) { // NOLINT(misc-no-recursion)
47+ to_json (obj, touch_settings);
48+ obj[" type" ] = " touch" ;
49+ } },
4550 controls
4651 );
4752 }
0 commit comments