added MnGuyens further improved menu handling and extra options.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "../include/DeckMetaData.h"
|
||||
#include "../include/DeckStats.h"
|
||||
#include "../include/MTGDeck.h"
|
||||
#include "../include/config.h"
|
||||
#include "../include/utils.h"
|
||||
|
||||
//Possible improvements:
|
||||
//Merge this with DeckStats
|
||||
//Have this class handle all the Meta Data rather than relying on MTGDeck. Then MTGDeck would have a MetaData object...
|
||||
@@ -12,25 +15,75 @@ DeckMetaData::DeckMetaData(){
|
||||
|
||||
}
|
||||
|
||||
DeckMetaData::DeckMetaData(string filename){
|
||||
DeckMetaData::DeckMetaData(string filename, Player * statsPlayer){
|
||||
load(filename);
|
||||
}
|
||||
|
||||
|
||||
void DeckMetaData::loadStatsForPlayer( Player * statsPlayer, string deckStatsFileName )
|
||||
{
|
||||
DeckStats * stats = DeckStats::GetInstance();
|
||||
if ( statsPlayer )
|
||||
{
|
||||
stats->load(statsPlayer);
|
||||
DeckStat * opponentDeckStats = stats->getDeckStat(deckStatsFileName);
|
||||
if ( opponentDeckStats )
|
||||
{
|
||||
percentVictories = stats->percentVictories(deckStatsFileName);
|
||||
victories = opponentDeckStats->victories;
|
||||
nbGamesPlayed = opponentDeckStats->nbgames;
|
||||
if (percentVictories < 34){
|
||||
difficulty = HARD;
|
||||
}else if (percentVictories < 67){
|
||||
difficulty = NORMAL;
|
||||
}else{
|
||||
difficulty = EASY;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fileExists(deckStatsFileName.c_str())){
|
||||
stats->load(deckStatsFileName.c_str());
|
||||
nbGamesPlayed = stats->nbGames();
|
||||
percentVictories = stats->percentVictories();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string DeckMetaData::getDescription()
|
||||
{
|
||||
char deckDesc[512];
|
||||
string difficultyString = "";
|
||||
switch( difficulty )
|
||||
{
|
||||
case HARD:
|
||||
difficultyString = "Hard";
|
||||
break;
|
||||
case EASY:
|
||||
difficultyString = "Easy";
|
||||
break;
|
||||
}
|
||||
if ( nbGamesPlayed > 0 && difficultyString != "")
|
||||
sprintf(deckDesc, "Difficulty: %s\nVictory %%: %i\nGames Played: %i\n\n%s", difficultyString.c_str(), percentVictories, nbGamesPlayed, desc.c_str() );
|
||||
else if ( nbGamesPlayed > 0 )
|
||||
sprintf(deckDesc, "Victory %%: %i\nGames Played: %i\n\n%s", percentVictories, nbGamesPlayed, desc.c_str() );
|
||||
else
|
||||
return desc.c_str();
|
||||
return deckDesc;
|
||||
}
|
||||
|
||||
void DeckMetaData::load(string filename){
|
||||
MTGDeck * mtgd = NEW MTGDeck(filename.c_str(),NULL,1);
|
||||
name = DeckMetaData::trim( mtgd->meta_name );
|
||||
desc = DeckMetaData::trim( mtgd->meta_desc );
|
||||
name = trim( mtgd->meta_name );
|
||||
desc = trim( mtgd->meta_desc );
|
||||
deckid = atoi( (filename.substr( filename.find("deck") + 4, filename.find(".txt") )).c_str() );
|
||||
|
||||
delete(mtgd);
|
||||
}
|
||||
|
||||
|
||||
// Must define less than relative to DeckMetaData objects.
|
||||
bool DeckMetaData::operator<(DeckMetaData b)
|
||||
{
|
||||
return strcmp(name.c_str(), b.name.c_str()) < 0;
|
||||
}
|
||||
|
||||
DeckMetaDataList::~DeckMetaDataList(){
|
||||
for(map<string,DeckMetaData *>::iterator it = values.begin(); it != values.end(); ++it){
|
||||
SAFE_DELETE(it->second);
|
||||
@@ -46,11 +99,12 @@ void DeckMetaDataList::invalidate(string filename){
|
||||
}
|
||||
}
|
||||
|
||||
DeckMetaData * DeckMetaDataList::get(string filename){
|
||||
|
||||
DeckMetaData * DeckMetaDataList::get(string filename, Player * statsPlayer){
|
||||
map<string,DeckMetaData *>::iterator it = values.find(filename);
|
||||
if (it ==values.end()){
|
||||
if (fileExists(filename.c_str())) {
|
||||
values[filename] = NEW DeckMetaData(filename);
|
||||
values[filename] = NEW DeckMetaData(filename, statsPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,44 +112,3 @@ DeckMetaData * DeckMetaDataList::get(string filename){
|
||||
}
|
||||
|
||||
|
||||
|
||||
string& DeckMetaData::trim(string &str)
|
||||
{
|
||||
int i,j,start,end;
|
||||
|
||||
//ltrim
|
||||
for (i=0; (str[i]!=0 && str[i]<=32); )
|
||||
i++;
|
||||
start=i;
|
||||
|
||||
//rtrim
|
||||
for(i=0,j=0; str[i]!=0; i++)
|
||||
j = ((str[i]<=32)? j+1 : 0);
|
||||
end=i-j;
|
||||
str = str.substr(start,end-start);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
string& DeckMetaData::ltrim(string &str)
|
||||
{
|
||||
int i,start;
|
||||
|
||||
for (i=0; (str[i]!=0 && str[i]<=32); )
|
||||
i++;
|
||||
start=i;
|
||||
|
||||
str = str.substr(start,str.length()-start);
|
||||
return str;
|
||||
}
|
||||
string& DeckMetaData::rtrim(string &str)
|
||||
{
|
||||
int i,j,end;
|
||||
|
||||
for(i=0,j=0; str[i]!=0; i++)
|
||||
j = ((str[i]<=32)? j+1 : 0);
|
||||
end=i-j;
|
||||
|
||||
str = str.substr(0,end);
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user