MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / parse_mapping

Method parse_mapping

core/input/input.cpp:1657–1756  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1655}
1656
1657void Input::parse_mapping(const String &p_mapping) {
1658 _THREAD_SAFE_METHOD_;
1659 JoyDeviceMapping mapping;
1660
1661 Vector<String> entry = p_mapping.split(",");
1662 if (entry.size() < 2) {
1663 return;
1664 }
1665
1666 mapping.uid = entry[0];
1667 mapping.name = entry[1];
1668
1669 int idx = 1;
1670 while (++idx < entry.size()) {
1671 if (entry[idx].is_empty()) {
1672 continue;
1673 }
1674
1675 String output = entry[idx].get_slicec(':', 0).remove_char(' ');
1676 String input = entry[idx].get_slicec(':', 1).remove_char(' ');
1677 if (output.length() < 1 || input.length() < 2) {
1678 continue;
1679 }
1680
1681 if (output == "platform" || output == "hint") {
1682 continue;
1683 }
1684
1685 JoyAxisRange output_range = FULL_AXIS;
1686 if (output[0] == '+' || output[0] == '-') {
1687 ERR_CONTINUE_MSG(output.length() < 2,
1688 vformat("Invalid output entry \"%s\" in mapping:\n%s", entry[idx], p_mapping));
1689 if (output[0] == '+') {
1690 output_range = POSITIVE_HALF_AXIS;
1691 } else if (output[0] == '-') {
1692 output_range = NEGATIVE_HALF_AXIS;
1693 }
1694 output = output.substr(1);
1695 }
1696
1697 JoyAxisRange input_range = FULL_AXIS;
1698 if (input[0] == '+') {
1699 input_range = POSITIVE_HALF_AXIS;
1700 input = input.substr(1);
1701 } else if (input[0] == '-') {
1702 input_range = NEGATIVE_HALF_AXIS;
1703 input = input.substr(1);
1704 }
1705 bool invert_axis = false;
1706 if (input[input.length() - 1] == '~') {
1707 invert_axis = true;
1708 input = input.left(input.length() - 1);
1709 }
1710
1711 JoyButton output_button = _get_output_button(output);
1712 JoyAxis output_axis = _get_output_axis(output);
1713 if (output_button == JoyButton::INVALID && output_axis == JoyAxis::INVALID) {
1714 print_verbose(vformat("Unrecognized output string \"%s\" in mapping:\n%s", output, p_mapping));

Callers

nothing calls this directly

Calls 11

vformatFunction · 0.85
splitMethod · 0.80
remove_charMethod · 0.80
get_slicecMethod · 0.80
substrMethod · 0.80
leftMethod · 0.80
to_intMethod · 0.80
sizeMethod · 0.65
is_emptyMethod · 0.45
lengthMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected