MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / makeCombination

Method makeCombination

src/Core/Input/InputManager.cpp:350–409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 }

Callers 1

configureMethod · 0.95

Calls 14

stringToInputButtonStateFunction · 0.85
UnknownInputButtonClass · 0.85
splitFunction · 0.50
replaceInPlaceFunction · 0.50
containsFunction · 0.50
sizeMethod · 0.45
push_backMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected