1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59: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:
Misa 2020-07-02 16:58:58 -07:00 committed by Ethan Lee
parent 3f448ce439
commit 56f06bd853

View file

@ -4589,6 +4589,20 @@ void Game::unlocknum( int t )
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()
{
tinyxml2::XMLDocument doc;
@ -4625,31 +4639,9 @@ void Game::loadstats()
std::string pKey(pElem->Value());
const char* pText = pElem->GetText() ;
if (pKey == "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());
}
}
}
LOAD_ARRAY(unlock)
if (pKey == "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());
}
}
}
LOAD_ARRAY(unlocknotify)
if (pKey == "besttimes")
{
@ -4665,18 +4657,7 @@ void Game::loadstats()
}
}
if (pKey == "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());
}
}
}
LOAD_ARRAY(bestframes)
if (pKey == "besttrinkets")
{