| 1215 | } |
| 1216 | |
| 1217 | bool CTouchControls::ParseConfiguration(const void *pFileData, unsigned FileLength) |
| 1218 | { |
| 1219 | json_settings JsonSettings{}; |
| 1220 | char aError[256]; |
| 1221 | json_value *pConfiguration = json_parse_ex(&JsonSettings, static_cast<const json_char *>(pFileData), FileLength, aError); |
| 1222 | |
| 1223 | if(pConfiguration == nullptr) |
| 1224 | { |
| 1225 | log_error("touch_controls", "Failed to parse configuration (invalid json): '%s'", aError); |
| 1226 | return false; |
| 1227 | } |
| 1228 | if(pConfiguration->type != json_object) |
| 1229 | { |
| 1230 | log_error("touch_controls", "Failed to parse configuration: root must be an object"); |
| 1231 | json_value_free(pConfiguration); |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
| 1235 | std::optional<EDirectTouchIngameMode> ParsedDirectTouchIngame = ParseDirectTouchIngameMode(&(*pConfiguration)["direct-touch-ingame"]); |
| 1236 | if(!ParsedDirectTouchIngame.has_value()) |
| 1237 | { |
| 1238 | json_value_free(pConfiguration); |
| 1239 | return false; |
| 1240 | } |
| 1241 | |
| 1242 | std::optional<EDirectTouchSpectateMode> ParsedDirectTouchSpectate = ParseDirectTouchSpectateMode(&(*pConfiguration)["direct-touch-spectate"]); |
| 1243 | if(!ParsedDirectTouchSpectate.has_value()) |
| 1244 | { |
| 1245 | json_value_free(pConfiguration); |
| 1246 | return false; |
| 1247 | } |
| 1248 | |
| 1249 | std::optional<ColorRGBA> ParsedBackgroundColorInactive = |
| 1250 | ParseColor(&(*pConfiguration)["background-color-inactive"], "background-color-inactive", ColorRGBA(0.0f, 0.0f, 0.0f, 0.25f)); |
| 1251 | if(!ParsedBackgroundColorInactive.has_value()) |
| 1252 | { |
| 1253 | json_value_free(pConfiguration); |
| 1254 | return false; |
| 1255 | } |
| 1256 | |
| 1257 | std::optional<ColorRGBA> ParsedBackgroundColorActive = |
| 1258 | ParseColor(&(*pConfiguration)["background-color-active"], "background-color-active", ColorRGBA(0.2f, 0.2f, 0.2f, 0.25f)); |
| 1259 | if(!ParsedBackgroundColorActive.has_value()) |
| 1260 | { |
| 1261 | json_value_free(pConfiguration); |
| 1262 | return false; |
| 1263 | } |
| 1264 | |
| 1265 | const json_value &TouchButtons = (*pConfiguration)["touch-buttons"]; |
| 1266 | if(TouchButtons.type != json_array) |
| 1267 | { |
| 1268 | log_error("touch_controls", "Failed to parse configuration: attribute 'touch-buttons' must specify an array"); |
| 1269 | json_value_free(pConfiguration); |
| 1270 | return false; |
| 1271 | } |
| 1272 | |
| 1273 | std::vector<CTouchButton> vParsedTouchButtons; |
| 1274 | vParsedTouchButtons.reserve(TouchButtons.u.array.length); |
nothing calls this directly
no test coverage detected