clear config data between loads

This commit is contained in:
garakmon 2020-04-07 14:44:14 -04:00
parent c0bffa0107
commit 0e9deff4bc
2 changed files with 17 additions and 8 deletions

View file

@ -18,6 +18,7 @@ public:
void save();
void load();
virtual ~KeyValueConfigBase();
virtual void reset() = 0;
protected:
virtual QString getConfigFilepath() = 0;
virtual void parseConfigKeyValue(QString key, QString value) = 0;
@ -29,6 +30,9 @@ class PorymapConfig: public KeyValueConfigBase
{
public:
PorymapConfig() {
reset();
}
virtual void reset() override {
this->recentProject = "";
this->recentMap = "";
this->mapSortOrder = MapSortOrder::Group;
@ -63,10 +67,10 @@ public:
QSize getRegionMapDimensions();
QString getTheme();
protected:
QString getConfigFilepath();
void parseConfigKeyValue(QString key, QString value);
QMap<QString, QString> getKeyValueMap();
void onNewConfigFileCreated() {}
virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override;
virtual QMap<QString, QString> getKeyValueMap() override;
virtual void onNewConfigFileCreated() override {}
private:
QString recentProject;
QString recentMap;
@ -99,8 +103,12 @@ class ProjectConfig: public KeyValueConfigBase
{
public:
ProjectConfig() {
reset();
}
virtual void reset() override {
this->baseGameVersion = BaseGameVersion::pokeemerald;
this->useEncounterJson = true;
this->useCustomBorderSize = false;
}
void setBaseGameVersion(BaseGameVersion baseGameVersion);
BaseGameVersion getBaseGameVersion();
@ -112,10 +120,10 @@ public:
void setUseCustomBorderSize(bool enable);
bool getUseCustomBorderSize();
protected:
QString getConfigFilepath();
void parseConfigKeyValue(QString key, QString value);
QMap<QString, QString> getKeyValueMap();
void onNewConfigFileCreated();
virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override;
virtual QMap<QString, QString> getKeyValueMap() override;
virtual void onNewConfigFileCreated() override;
private:
BaseGameVersion baseGameVersion;
QString projectDir;

View file

@ -17,6 +17,7 @@ KeyValueConfigBase::~KeyValueConfigBase() {
}
void KeyValueConfigBase::load() {
reset();
QFile file(this->getConfigFilepath());
if (!file.exists()) {
if (!file.open(QIODevice::WriteOnly)) {