-- zipFS has several limitations... --- in a general way, seekg doesn't work... so getting a file's size needs to be done through JFileSystem. --- getLine on files open with zipFS doesn't work so great. Not sure if it is a normal issue because files are open in binary or not... JFileSystem therefore offers a "readIntoString" function that needs to be used instead of the usual "getline" technique. However getLine can then be used on a stream connected to the string. -- tested on Windows and PSP, I also made sure android still works, but haven't tested zip support on Android. -- I tried to maintain backwards compatibility, but this might break on some platforms, if I broke some platforms and you can't find a way to fix them, please contact me and we'll figure something out -- This removes wagic::ifstream. I didn't reimplement the securities that were involved in this, apologies for that. Might be useful to reimplement such securities in JFileSystem -- I haven't tested options/profiles in a deep way, it is possible I broke that.
91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
#include "PrecompiledHeader.h"
|
|
|
|
#include "PlayerData.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
PlayerData::PlayerData()
|
|
{
|
|
init();
|
|
}
|
|
|
|
PlayerData::PlayerData(MTGAllCards * allcards)
|
|
{
|
|
init();
|
|
|
|
//COLLECTION
|
|
if (allcards) collection = NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), allcards);
|
|
}
|
|
|
|
void PlayerData::init()
|
|
{
|
|
collection = NULL;
|
|
|
|
//CREDITS
|
|
credits = 3000; //Default value
|
|
|
|
std::string contents;
|
|
if (JFileSystem::GetInstance()->readIntoString(options.profileFile(PLAYER_SAVEFILE), contents))
|
|
{
|
|
std::stringstream stream(contents);
|
|
std::string s;
|
|
if (std::getline(stream, s))
|
|
{
|
|
credits = atoi(s.c_str());
|
|
}
|
|
else
|
|
{
|
|
//TODO error management
|
|
}
|
|
|
|
//Story Saves
|
|
while (std::getline(stream, 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;
|
|
}
|
|
}
|
|
|
|
taskList = NEW TaskList(options.profileFile(PLAYER_TASKS).c_str());
|
|
}
|
|
|
|
int PlayerData::save()
|
|
{
|
|
std::ofstream file;
|
|
if (JFileSystem::GetInstance()->openForWrite(file, options.profileFile(PLAYER_SAVEFILE)))
|
|
{
|
|
char writer[512];
|
|
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);
|
|
}
|