reverted ability/color parser for AATokenCreator.

fixed color parsing error for Transformer classes
This commit is contained in:
techdragon.nguyen@gmail.com
2010-11-22 09:51:36 +00:00
parent 4c7b4f4df9
commit 064dad3085
4 changed files with 50 additions and 13 deletions

View File

@@ -1018,10 +1018,43 @@ public:
who = who;
tokenId = 0;
if (!multiplier) this->multiplier = NEW WParsedInt(1);
//TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class;
PopulateAbilityIndexVector(abilities, sabilities);
PopulateColorIndexVector(colors, sabilities);
PopulateSubtypesIndexVector(types, stypes);
for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++)
{
size_t found = sabilities.find(Constants::MTGBasicAbilities[j]);
if (found != string::npos)
{
abilities.push_back(j);
}
}
for (int j = 0; j < Constants::MTG_NB_COLORS; j++)
{
size_t found = sabilities.find(Constants::MTGColorStrings[j]);
if (found != string::npos)
{
colors.push_back(j);
}
}
string s = stypes;
while (s.size())
{
size_t found = s.find(" ");
if (found != string::npos)
{
int id = Subtypes::subtypesList->find(s.substr(0, found));
types.push_back(id);
s = s.substr(found + 1);
}
else
{
int id = Subtypes::subtypesList->find(s);
types.push_back(id);
s = "";
}
}
}
int resolve()

View File

@@ -43,7 +43,7 @@ std::vector<std::string> &split(const std::string &s, char delim, std::vector<st
std::vector<std::string> split(const std::string &s, char delim); //splits a string with "delim" and returns a vector of strings.
std::string wordWrap(std::string s, int width);
void PopulateColorIndexVector( list<int>& colors, const string& colorsString, char delimiter = ' ');
void PopulateColorIndexVector( list<int>& colors, const string& colorsString, char delimiter = ',');
void PopulateAbilityIndexVector( list<int>& abilities, const string& abilitiesString, char delimiter = ',');
void PopulateSubtypesIndexVector( list<int>& subtypes, const string& subtypesString, char delimiter = ' ');

View File

@@ -631,9 +631,11 @@ AACloner::AACloner(int _id, MTGCardInstance * _source, MTGCardInstance * _target
{
target = _target;
source = _source;
PopulateAbilityIndexVector(awith, abilitiesStringList);
PopulateColorIndexVector(colors, abilitiesStringList);
if ( abilitiesStringList.size() > 0 )
{
PopulateAbilityIndexVector(awith, abilitiesStringList);
PopulateColorIndexVector(colors, abilitiesStringList);
}
}

View File

@@ -262,8 +262,7 @@ std::string wordWrap(std::string sentence, int width)
return sentence;
}
// Given a delimited string of abilities, add the ones to the list that are "Basic" MTG abilities
void PopulateAbilityIndexVector( list<int>& abilities, const string& abilityStringList, char delimiter )
{
vector<string> abilitiesList = split( abilityStringList, delimiter);
@@ -276,15 +275,18 @@ void PopulateAbilityIndexVector( list<int>& abilities, const string& abilityStri
}
}
void PopulateColorIndexVector( list<int>& colors, const string& colorStringList, char delimiter )
{
vector<string> abilitiesList = split( colorStringList, delimiter);
for ( vector<string>::iterator iter = abilitiesList.begin(); iter != abilitiesList.end(); ++iter)
{
int colorIndex = Constants::GetColorStringIndex(*iter);
if (colorIndex != -1)
colors.push_back(colorIndex);
for (int colorIndex = Constants::MTG_COLOR_ARTIFACT; colorIndex < Constants::MTG_NB_COLORS; ++colorIndex)
{
// if the text is not a basic ability but contains a valid color add it to the color vector
if ( (Constants::GetBasicAbilityIndex( *iter ) != -1) && ((*iter).find( Constants::MTGColorStrings[ colorIndex ] ) != string::npos) )
colors.push_back(colorIndex);
}
}
}