| 326 | } |
| 327 | |
| 328 | void InputManager::loadConfig() |
| 329 | { |
| 330 | if(!mJoysticks) |
| 331 | { |
| 332 | LOG(LogError) << "ERROR - cannot load InputManager config without being initialized!"; |
| 333 | } |
| 334 | |
| 335 | std::string path = getConfigPath(); |
| 336 | if(!fs::exists(path)) |
| 337 | return; |
| 338 | |
| 339 | pugi::xml_document doc; |
| 340 | pugi::xml_parse_result res = doc.load_file(path.c_str()); |
| 341 | |
| 342 | if(!res) |
| 343 | { |
| 344 | LOG(LogError) << "Error loading input config: " << res.description(); |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | mNumPlayers = 0; |
| 349 | |
| 350 | bool* configuredDevice = new bool[mNumJoysticks]; |
| 351 | for(int i = 0; i < mNumJoysticks; i++) |
| 352 | { |
| 353 | mInputConfigs[i]->setPlayerNum(-1); |
| 354 | configuredDevice[i] = false; |
| 355 | } |
| 356 | |
| 357 | pugi::xml_node root = doc.child("inputList"); |
| 358 | |
| 359 | for(pugi::xml_node node = root.child("inputConfig"); node; node = node.next_sibling("inputConfig")) |
| 360 | { |
| 361 | std::string type = node.attribute("type").as_string(); |
| 362 | |
| 363 | if(type == "keyboard") |
| 364 | { |
| 365 | getInputConfigByDevice(DEVICE_KEYBOARD)->loadFromXML(node, mNumPlayers); |
| 366 | mNumPlayers++; |
| 367 | }else if(type == "joystick") |
| 368 | { |
| 369 | bool found = false; |
| 370 | std::string devName = node.attribute("deviceName").as_string(); |
| 371 | for(int i = 0; i < mNumJoysticks; i++) |
| 372 | { |
| 373 | if(!configuredDevice[i] && SDL_JoystickName(i) == devName) |
| 374 | { |
| 375 | mInputConfigs[i]->loadFromXML(node, mNumPlayers); |
| 376 | mNumPlayers++; |
| 377 | found = true; |
| 378 | configuredDevice[i] = true; |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | if(!found) |
| 384 | { |
| 385 | LOG(LogWarning) << "Could not find unconfigured joystick named \"" << devName << "\"! Skipping it.\n"; |
nothing calls this directly
no test coverage detected