Hello. I'm working on the input system for my game. And I've run into a problem. I'm storing the keybindings for each "player" in separate ini files. The whole system is actually working out pretty well. Except that telling the program what sf::Keyboard:: thing to look for is a huge pain. I get my data from the INI file in the form of strings. Right now, I have a function that looks up that string and returns the proper sf::Keyboard::Key.
It looks something like this (except it has an entry for every keyboard key x.x)
if ( stringholder.at(i) == "A" ) {
results.push_back(sf::Keyboard::A);
} else if ( stringholder.at(i) == "B" ) {
results.push_back(sf::Keyboard::B);
} else if ( stringholder.at(i) == "C" ) {
results.push_back(sf::Keyboard::C);
} else if ( stringholder.at(i) == "D" ) {
results.push_back(sf::Keyboard::D);
} else if ( stringholder.at(i) == "E" ) {
results.push_back(sf::Keyboard::E);
} else if ( stringholder.at(i) == "F" ) {
results.push_back(sf::Keyboard::F);
} else if ( stringholder.at(i) == "G" ) {
results.push_back(sf::Keyboard::G);
(A switch statement would be a little less messy, but C++ doesn't allow those with strings. x.x Also, I'm using vectors so that I can have multiple keys bound to the same action.)
Is there a better way to do this? I can change what strings are in the INI file. I can even try to find a way to simplify them to a single letter so I can use a switch statement. But the problem is that that still requires massive amounts of conditions. And it's easy to create tiny errors.
Is there a better way to do this? Is there a way to lookup a keyboard key by something and return it, rather than explicitly stating which keyboard key is to be used for a specific string?
Thanks for reading this post. Any advice you can offer would be great.