diff --git a/include/project.h b/include/project.h index 9873c60f..51bec9a0 100644 --- a/include/project.h +++ b/include/project.h @@ -89,13 +89,13 @@ public: QString readMapLayoutId(QString map_name); QString readMapLocation(QString map_name); - void readWildMonData(); + bool readWildMonData(); QMap> wildMonData; QVector wildMonFields; QVector encounterGroupLabels; QMap extraEncounterGroups; - void readSpeciesIconPaths(); + bool readSpeciesIconPaths(); QMap speciesToIconPath; QMap getTopLevelMapFields(); @@ -129,22 +129,22 @@ public: QStringList getSongNames(); QStringList getVisibilities(); QMap getTilesetLabels(); - void readTilesetProperties(); + bool readTilesetProperties(); bool readRegionMapSections(); - void readItemNames(); - void readFlagNames(); - void readVarNames(); - void readMovementTypes(); - void readInitialFacingDirections(); - void readMapTypes(); - void readMapBattleScenes(); - void readWeatherNames(); - void readCoordEventWeatherNames(); - void readSecretBaseIds(); - void readBgEventFacingDirections(); - void readMetatileBehaviors(); - void readHealLocations(); - void readMiscellaneousConstants(); + bool readItemNames(); + bool readFlagNames(); + bool readVarNames(); + bool readMovementTypes(); + bool readInitialFacingDirections(); + bool readMapTypes(); + bool readMapBattleScenes(); + bool readWeatherNames(); + bool readCoordEventWeatherNames(); + bool readSecretBaseIds(); + bool readBgEventFacingDirections(); + bool readMetatileBehaviors(); + bool readHealLocations(); + bool readMiscellaneousConstants(); void loadEventPixmaps(QList objects); QMap getEventObjGfxConstants(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 20cd5b90..62d9362b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -598,37 +598,48 @@ void MainWindow::on_checkBox_AllowEscapeRope_clicked(bool checked) bool MainWindow::loadDataStructures() { Project *project = editor->project; bool success = project->readMapLayouts() - && project->readRegionMapSections(); + && project->readRegionMapSections() + && project->readItemNames() + && project->readFlagNames() + && project->readVarNames() + && project->readMovementTypes() + && project->readInitialFacingDirections() + && project->readMapTypes() + && project->readMapBattleScenes() + && project->readWeatherNames() + && project->readCoordEventWeatherNames() + && project->readSecretBaseIds() + && project->readBgEventFacingDirections() + && project->readMetatileBehaviors() + && project->readTilesetProperties() + && project->readHealLocations() + && project->readMiscellaneousConstants() + && project->readSpeciesIconPaths() + && project->readWildMonData(); if (!success) { return false; } - project->readItemNames(); - project->readFlagNames(); - project->readVarNames(); - project->readMovementTypes(); - project->readInitialFacingDirections(); - project->readMapTypes(); - project->readMapBattleScenes(); - project->readWeatherNames(); - project->readCoordEventWeatherNames(); - project->readSecretBaseIds(); - project->readBgEventFacingDirections(); - project->readMetatileBehaviors(); - project->readTilesetProperties(); - project->readHealLocations(); - project->readMiscellaneousConstants(); - project->readSpeciesIconPaths(); - project->readWildMonData(); // set up project ui comboboxes QStringList songs = project->getSongNames(); + ui->comboBox_Song->clear(); ui->comboBox_Song->addItems(songs); + ui->comboBox_Location->clear(); ui->comboBox_Location->addItems(project->mapSectionValueToName.values()); + QMap tilesets = project->getTilesetLabels(); + if (tilesets.isEmpty()) { + return false; + } + ui->comboBox_PrimaryTileset->clear(); ui->comboBox_PrimaryTileset->addItems(tilesets.value("primary")); + ui->comboBox_SecondaryTileset->clear(); ui->comboBox_SecondaryTileset->addItems(tilesets.value("secondary")); + ui->comboBox_Weather->clear(); ui->comboBox_Weather->addItems(*project->weatherNames); + ui->comboBox_BattleScene->clear(); ui->comboBox_BattleScene->addItems(*project->mapBattleScenes); + ui->comboBox_Type->clear(); ui->comboBox_Type->addItems(*project->mapTypes); return true; } diff --git a/src/project.cpp b/src/project.cpp index c5bee579..fc7154d7 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1452,14 +1452,20 @@ void Project::deleteFile(QString path) { } } -void Project::readWildMonData() { - if (!projectConfig.getEncounterJsonActive()) return; +bool Project::readWildMonData() { + extraEncounterGroups.clear(); + wildMonFields.clear(); + wildMonData.clear(); + encounterGroupLabels.clear(); + if (!projectConfig.getEncounterJsonActive()) { + return true; + } QString wildMonJsonFilepath = QString("%1/src/data/wild_encounters.json").arg(root); QJsonDocument wildMonsJsonDoc; if (!parser.tryParseJsonFile(&wildMonsJsonDoc, wildMonJsonFilepath)) { logError(QString("Failed to read wild encounters from %1").arg(wildMonJsonFilepath)); - return; + return false; } QJsonObject wildMonObj = wildMonsJsonDoc.object(); @@ -1509,6 +1515,7 @@ void Project::readWildMonData() { encounterGroupLabels.append(encounter.toObject().value("base_label").toString()); } } + return true; } void Project::readMapGroups() { @@ -1646,7 +1653,12 @@ QMap Project::getTilesetLabels() { allTilesets.insert("primary", primaryTilesets); allTilesets.insert("secondary", secondaryTilesets); - QString headers_text = parser.readTextFile(root + "/data/tilesets/headers.inc"); + QString filename = "data/tilesets/headers.inc"; + QString headers_text = parser.readTextFile(root + "/" + filename); + if (headers_text.isEmpty()) { + logError(QString("Failed to read tileset labels from %1.").arg(filename)); + return QMap(); + } QRegularExpression re("(?