| 348 | return false; |
| 349 | } |
| 350 | InputCombination InputManager::makeCombination(const std::string& code) |
| 351 | { |
| 352 | InputCombination combination; |
| 353 | std::vector<std::string> elements = Utils::String::split(code, "+"); |
| 354 | if (code != "NotAssociated") |
| 355 | { |
| 356 | for (std::string element : elements) |
| 357 | { |
| 358 | Utils::String::replaceInPlace(element, " ", ""); |
| 359 | std::vector<std::string> stateAndButton |
| 360 | = Utils::String::split(element, ":"); |
| 361 | if (stateAndButton.size() == 1 || stateAndButton.size() == 2) |
| 362 | { |
| 363 | if (stateAndButton.size() == 1) |
| 364 | { |
| 365 | stateAndButton.push_back(stateAndButton[0]); |
| 366 | stateAndButton[0] = "Pressed"; |
| 367 | } |
| 368 | |
| 369 | std::vector<std::string> stateList |
| 370 | = Utils::String::split(stateAndButton[0], ","); |
| 371 | Types::FlagSet<InputButtonState> buttonStates; |
| 372 | for (std::string& buttonState : stateList) |
| 373 | { |
| 374 | if (Utils::Vector::contains( |
| 375 | buttonState, { "Idle", "Hold", "Pressed", "Released" })) |
| 376 | { |
| 377 | buttonStates |= stringToInputButtonState(buttonState); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | throw Exceptions::InvalidInputButtonState( |
| 382 | buttonState, EXC_INFO); |
| 383 | } |
| 384 | } |
| 385 | const std::string keyId = stateAndButton[1]; |
| 386 | if (m_inputs.find(keyId) != m_inputs.end()) |
| 387 | { |
| 388 | InputButton& button = this->getInput(keyId); |
| 389 | |
| 390 | if (!isKeyAlreadyInCombination(combination, &button)) |
| 391 | { |
| 392 | combination.emplace_back(&button, buttonStates); |
| 393 | } |
| 394 | else |
| 395 | { |
| 396 | throw Exceptions::InputButtonAlreadyInCombination( |
| 397 | button.getName(), EXC_INFO); |
| 398 | } |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | throw Exceptions::UnknownInputButton( |
| 403 | keyId, this->getAllInputButtonNames(), EXC_INFO); |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | } |
no test coverage detected