mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 10:09:43 +01:00
De-duplicate and use a macro for loading things into plain arrays
Since it's basically the same code each time, I might as well just have a macro instead.
This commit is contained in:
parent
3f448ce439
commit
56f06bd853
1 changed files with 17 additions and 36 deletions
|
@ -4589,6 +4589,20 @@ void Game::unlocknum( int t )
|
||||||
savestats();
|
savestats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LOAD_ARRAY(ARRAY_NAME) \
|
||||||
|
if (pKey == #ARRAY_NAME) \
|
||||||
|
{ \
|
||||||
|
std::string TextString = pText; \
|
||||||
|
if (TextString.length()) \
|
||||||
|
{ \
|
||||||
|
std::vector<std::string> values = split(TextString, ','); \
|
||||||
|
for (size_t i = 0; i < SDL_min(SDL_arraysize(ARRAY_NAME), values.size()); i++) \
|
||||||
|
{ \
|
||||||
|
ARRAY_NAME[i] = atoi(values[i].c_str()); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
void Game::loadstats()
|
void Game::loadstats()
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
|
@ -4625,31 +4639,9 @@ void Game::loadstats()
|
||||||
std::string pKey(pElem->Value());
|
std::string pKey(pElem->Value());
|
||||||
const char* pText = pElem->GetText() ;
|
const char* pText = pElem->GetText() ;
|
||||||
|
|
||||||
if (pKey == "unlock")
|
LOAD_ARRAY(unlock)
|
||||||
{
|
|
||||||
std::string TextString = (pText);
|
|
||||||
if(TextString.length())
|
|
||||||
{
|
|
||||||
std::vector<std::string> values = split(TextString,',');
|
|
||||||
for(size_t i = 0; i < SDL_min(SDL_arraysize(unlock), values.size()); i++)
|
|
||||||
{
|
|
||||||
unlock[i] = atoi(values[i].c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pKey == "unlocknotify")
|
LOAD_ARRAY(unlocknotify)
|
||||||
{
|
|
||||||
std::string TextString = (pText);
|
|
||||||
if(TextString.length())
|
|
||||||
{
|
|
||||||
std::vector<std::string> values = split(TextString,',');
|
|
||||||
for(size_t i = 0; i < SDL_min(SDL_arraysize(unlocknotify), values.size()); i++)
|
|
||||||
{
|
|
||||||
unlocknotify[i] = atoi(values[i].c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pKey == "besttimes")
|
if (pKey == "besttimes")
|
||||||
{
|
{
|
||||||
|
@ -4665,18 +4657,7 @@ void Game::loadstats()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pKey == "bestframes")
|
LOAD_ARRAY(bestframes)
|
||||||
{
|
|
||||||
std::string TextString = pText;
|
|
||||||
if (TextString.length())
|
|
||||||
{
|
|
||||||
std::vector<std::string> values = split(TextString, ',');
|
|
||||||
for (size_t i = 0; i < std::min(sizeof(bestframes) / sizeof(int), values.size()); i++)
|
|
||||||
{
|
|
||||||
bestframes[i] = atoi(values[i].c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pKey == "besttrinkets")
|
if (pKey == "besttrinkets")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue