MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / SDLStringToController

Function SDLStringToController

Source/UserInput/keyTranslator.cpp:1048–1104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1046}
1047
1048ControllerInput::Input SDLStringToController(const char* string) {
1049 SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(string);
1050 if (button != SDL_CONTROLLER_BUTTON_INVALID) {
1051 return SDLControllerButtonToController(button);
1052 }
1053 char buffer[128];
1054 strcpy(buffer, string);
1055 int last = strlen(buffer) - 1;
1056 if (last > 0) {
1057 if (buffer[last] == '+' || buffer[last] == '-') {
1058 buffer[last] = '\0';
1059 }
1060 SDL_GameControllerAxis axis = SDL_GameControllerGetAxisFromString(buffer);
1061 if (axis != SDL_CONTROLLER_AXIS_INVALID) {
1062 ControllerInput::Input input = SDLControllerAxisToController(axis);
1063 switch (input) {
1064 case ControllerInput::L_STICK_X:
1065 if (string[last] == '+') {
1066 return ControllerInput::L_STICK_XP;
1067 } else if (string[last] == '-') {
1068 return ControllerInput::L_STICK_XN;
1069 } else {
1070 return input;
1071 }
1072 case ControllerInput::L_STICK_Y:
1073 if (string[last] == '+') {
1074 return ControllerInput::L_STICK_YP;
1075 } else if (string[last] == '-') {
1076 return ControllerInput::L_STICK_YN;
1077 } else {
1078 return input;
1079 }
1080 case ControllerInput::R_STICK_X:
1081 if (string[last] == '+') {
1082 return ControllerInput::R_STICK_XP;
1083 } else if (string[last] == '-') {
1084 return ControllerInput::R_STICK_XN;
1085 } else {
1086 return input;
1087 }
1088 case ControllerInput::R_STICK_Y:
1089 if (string[last] == '+') {
1090 return ControllerInput::R_STICK_YP;
1091 } else if (string[last] == '-') {
1092 return ControllerInput::R_STICK_YN;
1093 } else {
1094 return input;
1095 }
1096 default:
1097 return input;
1098 }
1099 }
1100 }
1101
1102 LOGW << "Tried converting an invalid string \"" << string << "\" to a controller input" << std::endl;
1103 return ControllerInput::NONE;
1104}

Callers 1

ProcessBindingsMethod · 0.85

Tested by

no test coverage detected