reformatting code according to guidelines defined at
http://wololo.net/forum/viewtopic.php?f=35&t=2235&start=10
This commit is contained in:
@@ -5,79 +5,87 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
PlayerData::PlayerData(){
|
||||
init();
|
||||
}
|
||||
PlayerData::PlayerData(MTGAllCards * allcards){
|
||||
init();
|
||||
|
||||
//COLLECTION
|
||||
if (allcards) collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards);
|
||||
PlayerData::PlayerData()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void PlayerData::init() {
|
||||
collection = NULL;
|
||||
PlayerData::PlayerData(MTGAllCards * allcards)
|
||||
{
|
||||
init();
|
||||
|
||||
//CREDITS
|
||||
credits = 3000; //Default value
|
||||
//COLLECTION
|
||||
if (allcards) collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards);
|
||||
}
|
||||
|
||||
std::ifstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
|
||||
std::string s;
|
||||
if(file){
|
||||
if(std::getline(file,s)){
|
||||
credits = atoi(s.c_str());
|
||||
}else{
|
||||
//TODO error management
|
||||
void PlayerData::init()
|
||||
{
|
||||
collection = NULL;
|
||||
|
||||
//CREDITS
|
||||
credits = 3000; //Default value
|
||||
|
||||
std::ifstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
|
||||
std::string s;
|
||||
if (file)
|
||||
{
|
||||
if (std::getline(file, s))
|
||||
{
|
||||
credits = atoi(s.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO error management
|
||||
}
|
||||
|
||||
//Story Saves
|
||||
while (std::getline(file, s))
|
||||
{
|
||||
if (!s.size()) continue;
|
||||
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); //Handle DOS files
|
||||
if (s.size() && s[0] == '#') continue;
|
||||
size_t i = s.find_first_of("=");
|
||||
if (i == string::npos) continue;
|
||||
|
||||
string key = s.substr(0, i);
|
||||
string value = s.substr(i + 1);
|
||||
if (key.size() < 3) continue;
|
||||
|
||||
if (key[0] != 's') continue;
|
||||
key = key.substr(2);
|
||||
storySaves[key] = value;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
//Story Saves
|
||||
while(std::getline(file,s)){
|
||||
if (!s.size())
|
||||
continue;
|
||||
if (s[s.size()-1] == '\r') s.erase(s.size()-1); //Handle DOS files
|
||||
if (s.size() && s[0] == '#')
|
||||
continue;
|
||||
size_t i = s.find_first_of("=");
|
||||
if (i == string::npos)
|
||||
continue;
|
||||
taskList = NEW TaskList(options.profileFile(PLAYER_TASKS).c_str());
|
||||
}
|
||||
|
||||
string key = s.substr(0,i);
|
||||
string value = s.substr(i+1);
|
||||
if (key.size() < 3)
|
||||
continue;
|
||||
int PlayerData::save()
|
||||
{
|
||||
std::ofstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
|
||||
char writer[512];
|
||||
if (file)
|
||||
{
|
||||
sprintf(writer, "%i\n", credits);
|
||||
file << writer;
|
||||
|
||||
if(key[0] != 's')
|
||||
continue;
|
||||
key = key.substr(2);
|
||||
storySaves[key]=value;
|
||||
//Story Saves
|
||||
for (map<string, string>::iterator it = storySaves.begin(); it != storySaves.end(); ++it)
|
||||
{
|
||||
sprintf(writer, "s %s=%s\n", it->first.c_str(), it->second.c_str());
|
||||
file << writer;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
taskList = NEW TaskList(options.profileFile(PLAYER_TASKS).c_str());
|
||||
if (collection) collection->save();
|
||||
taskList->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PlayerData::save(){
|
||||
std::ofstream file(options.profileFile(PLAYER_SAVEFILE).c_str());
|
||||
char writer[512];
|
||||
if (file){
|
||||
sprintf(writer,"%i\n", credits);
|
||||
file<<writer;
|
||||
|
||||
//Story Saves
|
||||
for (map<string,string>::iterator it =storySaves.begin(); it !=storySaves.end(); ++it){
|
||||
sprintf(writer,"s %s=%s\n", it->first.c_str(),it->second.c_str());
|
||||
file << writer;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
if (collection) collection->save();
|
||||
taskList->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
PlayerData::~PlayerData(){
|
||||
SAFE_DELETE(collection);
|
||||
SAFE_DELETE(taskList);
|
||||
PlayerData::~PlayerData()
|
||||
{
|
||||
SAFE_DELETE(collection);
|
||||
SAFE_DELETE(taskList);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user