MCPcopy Create free account
hub / github.com/Aloshi/EmulationStation / loadConfig

Method loadConfig

src/InputManager.cpp:328–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

326}
327
328void 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";

Callers

nothing calls this directly

Calls 8

load_fileMethod · 0.80
descriptionMethod · 0.80
setPlayerNumMethod · 0.80
childMethod · 0.80
next_siblingMethod · 0.80
as_stringMethod · 0.80
attributeMethod · 0.80
loadFromXMLMethod · 0.80

Tested by

no test coverage detected