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

View file

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