Set project-specific config defaults

This commit is contained in:
GriffinR 2020-05-26 17:01:18 -04:00 committed by huderlem
parent 125a287b9c
commit 90aa26197d
2 changed files with 21 additions and 1 deletions

View file

@ -24,6 +24,7 @@ protected:
virtual void parseConfigKeyValue(QString key, QString value) = 0;
virtual QMap<QString, QString> getKeyValueMap() = 0;
virtual void onNewConfigFileCreated() = 0;
virtual void setUnreadKeys() = 0;
};
class PorymapConfig: public KeyValueConfigBase
@ -73,7 +74,8 @@ protected:
virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override;
virtual QMap<QString, QString> getKeyValueMap() override;
virtual void onNewConfigFileCreated() override {}
virtual void onNewConfigFileCreated() override {};
virtual void setUnreadKeys() override {};
private:
QString recentProject;
QString recentMap;
@ -121,6 +123,7 @@ public:
this->enableObjectEventInConnection = false;
this->enableFloorNumber = false;
this->customScripts.clear();
this->readKeys.clear();
}
void setBaseGameVersion(BaseGameVersion baseGameVersion);
BaseGameVersion getBaseGameVersion();
@ -153,6 +156,7 @@ protected:
virtual void parseConfigKeyValue(QString key, QString value) override;
virtual QMap<QString, QString> getKeyValueMap() override;
virtual void onNewConfigFileCreated() override;
virtual void setUnreadKeys() override;
private:
BaseGameVersion baseGameVersion;
QString projectDir;
@ -167,6 +171,7 @@ private:
bool enableObjectEventInConnection;
bool enableFloorNumber;
QList<QString> customScripts;
QStringList readKeys;
};
extern ProjectConfig projectConfig;

View file

@ -56,6 +56,7 @@ void KeyValueConfigBase::load() {
this->parseConfigKeyValue(match.captured("key").toLower(), match.captured("value"));
}
this->setUnreadKeys();
file.close();
}
@ -434,6 +435,20 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
} else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
}
readKeys.append(key);
}
void ProjectConfig::setUnreadKeys() {
// Set game-version specific defaults for any config field that wasn't read
bool isPokefirered = this->baseGameVersion == BaseGameVersion::pokefirered;
if (!readKeys.contains("use_custom_border_size")) this->useCustomBorderSize = isPokefirered;
if (!readKeys.contains("enable_event_weather_trigger")) this->enableEventWeatherTrigger = !isPokefirered;
if (!readKeys.contains("enable_event_secret_base")) this->enableEventSecretBase = !isPokefirered;
if (!readKeys.contains("enable_hidden_item_quantity")) this->enableHiddenItemQuantity = isPokefirered;
if (!readKeys.contains("enable_hidden_item_requires_itemfinder")) this->enableHiddenItemRequiresItemfinder = isPokefirered;
if (!readKeys.contains("enable_heal_location_respawn_data")) this->enableHealLocationRespawnData = isPokefirered;
if (!readKeys.contains("enable_object_event_in_connection")) this->enableObjectEventInConnection = isPokefirered;
if (!readKeys.contains("enable_floor_number")) this->enableFloorNumber = isPokefirered;
}
QMap<QString, QString> ProjectConfig::getKeyValueMap() {