Hi.
I'm writing a class that enables me to let the user decide what buttons he wants to press to access a certain function (basically something that enables the user to configure his keymapping for my games himself).
For obvious reasons, I need to save the configuration to and read it from a file (in my case i'm using xml files + tinyxml).
anyways, the keymapping in my class is saved like this:
std::vector<std::pair<std::string,sf::Key::Code>> m_actionlist;
a vector that is full of all the "action" configurations that are read from the config file. for example: one element of that vector could have the name "move player up" as the first member of that pair and sf::Key::Up as the second member (or whatever i write in that config file).
the problem now is, that there is no such thing as pure "numbers" in c++; when I read the corresponding for some action from the config file (for example, sf::Key::Up is something like 297 i think), I can only read ints or doubles from the file.
now, I don't know how to dynamically assign these "numbers" to my vectors pair second member. something like this will obviously not compile
m_actionlist[current_iteration].second = myxmlfile.GetValue("Up")
because the returned value will be double, or int if I static_cast<int> it and the compiler can't convert int or double to sf::Key::Code.
Now, what am I supposed to do now, to avoid having to do something like this for any Code that is in sf::Key::Code and sf::Joy
if(myxmlfile.GetValue() == 297)
m_actionlist[whatever].second = sf::Key::Up
else if(myxmlfile.GetValue() == 298)
m_actionlist[whatever].second = sf::Key::Right
//And so on
I'm kinda lost here.
By the way to make it easier for anyone that seriously wants to help me (laurent maybe?) i'm posting the current state of the class on pastebin.net: [i'm adding descriptions of my XMLFile and XMLElement classes to the bottom of the paste, to make it easier for you]
http://pastebin.com/m6d494ef3i'd really appreciate your help.
greetings,
travis
edit: A typical config file would look like this:
<action ID=297>Up</action>
This will assign the sf::Key::Up key to the name "Up".