removed redundant code for card loading. getCardByName already loads by Id and caches the result

duplicating that code in MTGDeck is redundant.
This commit is contained in:
techdragon.nguyen@gmail.com
2011-02-14 17:36:19 +00:00
parent 5b365e53f0
commit 73b2d5ded8
+7 -19
View File
@@ -676,7 +676,10 @@ MTGCard * MTGAllCards::getCardByName(string name)
if (!name.size()) return NULL; if (!name.size()) return NULL;
if (name[0] == '#') return NULL; if (name[0] == '#') return NULL;
map<string, MTGCard * >::iterator cached = mtgCardByNameCache.find(name); map<string, MTGCard * >::iterator cached = mtgCardByNameCache.end();
if (mtgCardByNameCache.size() > 0)
cached = mtgCardByNameCache.find(name);
if (cached!= mtgCardByNameCache.end()) if (cached!= mtgCardByNameCache.end())
{ {
return cached->second; return cached->second;
@@ -778,11 +781,11 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
continue; continue;
} }
if (meta_only) break; if (meta_only) break;
int nb = 1; int numberOfCopies = 1;
size_t found = s.find(" *"); size_t found = s.find(" *");
if (found != string::npos) if (found != string::npos)
{ {
nb = atoi(s.substr(found + 2).c_str()); numberOfCopies = atoi(s.substr(found + 2).c_str());
s = s.substr(0, found); s = s.substr(0, found);
} }
size_t diff = s.find("toggledifficulty:"); size_t diff = s.find("toggledifficulty:");
@@ -801,34 +804,19 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
s = cardeasy; s = cardeasy;
} }
} }
int cardnb = atoi(s.c_str());
if (cardnb)
{
add(cardnb);
}
else
{
size_t found = s.find(" *");
if (found != string::npos)
{
nb = atoi(s.substr(found + 2).c_str());
s = s.substr(0, found);
}
MTGCard * card = database->getCardByName(s); MTGCard * card = database->getCardByName(s);
if (card) if (card)
{ {
for (int i = 0; i < nb; i++) for (int i = 0; i < numberOfCopies; i++)
{ {
add(card); add(card);
} }
} }
else else
{ {
DebugTrace("could not find Card matching name: " << s); DebugTrace("could not find Card matching name: " << s);
} }
} }
}
file.close(); file.close();
} }
else else