add wild encounters to config

This commit is contained in:
garak 2019-07-03 16:21:48 -04:00
parent c52b6fe4cd
commit d794dee8c0
4 changed files with 29 additions and 0 deletions

View file

@ -96,9 +96,12 @@ class ProjectConfig: public KeyValueConfigBase
public:
ProjectConfig() {
this->baseGameVersion = BaseGameVersion::pokeemerald;
this->useEncounterJson = true;
}
void setBaseGameVersion(BaseGameVersion baseGameVersion);
BaseGameVersion getBaseGameVersion();
void setEncounterJsonActive(bool active);
bool getEncounterJsonActive();
void setProjectDir(QString projectDir);
protected:
QString getConfigFilepath();
@ -108,6 +111,7 @@ protected:
private:
BaseGameVersion baseGameVersion;
QString projectDir;
bool useEncounterJson;
};
extern ProjectConfig projectConfig;

View file

@ -337,6 +337,12 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
this->baseGameVersion = BaseGameVersion::pokeemerald;
logWarn(QString("Invalid config value for base_game_version: '%1'. Must be 'pokeruby' or 'pokeemerald'.").arg(value));
}
} else if (key == "use_encounter_json") {
bool ok;
this->useEncounterJson = value.toInt(&ok);
if (!ok) {
logWarn(QString("Invalid config value for use_encounter_json: '%1'. Must be 0 or 1.").arg(value));
}
} else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
}
@ -345,6 +351,7 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
QMap<QString, QString> ProjectConfig::getKeyValueMap() {
QMap<QString, QString> map;
map.insert("base_game_version", baseGameVersionMap.value(this->baseGameVersion));
map.insert("use_encounter_json", QString::number(this->useEncounterJson));
return map;
}
@ -373,6 +380,7 @@ void ProjectConfig::onNewConfigFileCreated() {
this->baseGameVersion = static_cast<BaseGameVersion>(baseGameVersionComboBox->currentData().toInt());
}
}
this->useEncounterJson = true;
}
void ProjectConfig::setProjectDir(QString projectDir) {
@ -387,3 +395,12 @@ void ProjectConfig::setBaseGameVersion(BaseGameVersion baseGameVersion) {
BaseGameVersion ProjectConfig::getBaseGameVersion() {
return this->baseGameVersion;
}
void ProjectConfig::setEncounterJsonActive(bool active) {
this->useEncounterJson = active;
this->save();
}
bool ProjectConfig::getEncounterJsonActive() {
return this->useEncounterJson;
}

View file

@ -149,6 +149,9 @@ void MainWindow::initMapSortOrder() {
void MainWindow::setProjectSpecificUIVisibility()
{
if (!projectConfig.getEncounterJsonActive())
ui->tabWidget->removeTab(4);
switch (projectConfig.getBaseGameVersion())
{
case BaseGameVersion::pokeruby:
@ -2216,6 +2219,7 @@ void MainWindow::closeEvent(QCloseEvent *event) {
this->ui->splitter_main->saveState()
);
porymapConfig.save();
projectConfig.save();
QMainWindow::closeEvent(event);
}

View file

@ -521,6 +521,8 @@ void Project::saveMapGroups() {
}
void Project::saveWildMonData() {
if (!projectConfig.getEncounterJsonActive()) return;
QString wildEncountersJsonFilepath = QString("%1/src/data/wild_encounters.json").arg(root);
QFile wildEncountersFile(wildEncountersJsonFilepath);
if (!wildEncountersFile.open(QIODevice::WriteOnly)) {
@ -1378,6 +1380,8 @@ void Project::deleteFile(QString path) {
}
void Project::readWildMonData() {
if (!projectConfig.getEncounterJsonActive()) return;
QString wildMonJsonFilepath = QString("%1/src/data/wild_encounters.json").arg(root);
QJsonDocument wildMonsJsonDoc;
if (!parser.tryParseJsonFile(&wildMonsJsonDoc, wildMonJsonFilepath)) {