Fix confusing error logging during region map setup
This commit is contained in:
parent
236ad9b73c
commit
0954fe26ff
3 changed files with 24 additions and 26 deletions
|
@ -27,6 +27,7 @@ public:
|
|||
~RegionMapEditor();
|
||||
|
||||
bool load(bool silent = false);
|
||||
bool setupErrored() const { return setupError; }
|
||||
|
||||
void onRegionMapTileSelectorSelectedTileChanged(unsigned id);
|
||||
void onRegionMapTileSelectorHoveredTileChanged(unsigned id);
|
||||
|
@ -53,9 +54,13 @@ private:
|
|||
RegionMap *region_map = nullptr;
|
||||
tsl::ordered_map<QString, RegionMap *> region_maps;
|
||||
|
||||
QString configFilepath;
|
||||
QString mapSectionFilepath;
|
||||
|
||||
poryjson::Json rmConfigJson;
|
||||
|
||||
bool configSaved = false;
|
||||
bool setupError = false;
|
||||
|
||||
QUndoGroup history;
|
||||
|
||||
|
|
|
@ -2960,15 +2960,14 @@ bool MainWindow::initRegionMapEditor(bool silent) {
|
|||
this->regionMapEditor = new RegionMapEditor(this, this->editor->project);
|
||||
bool success = this->regionMapEditor->load(silent);
|
||||
if (!success) {
|
||||
delete this->regionMapEditor;
|
||||
this->regionMapEditor = nullptr;
|
||||
if (!silent) {
|
||||
if (!silent && this->regionMapEditor->setupErrored()) {
|
||||
QMessageBox msgBox(this);
|
||||
QString errorMsg = QString("There was an error opening the region map data. Please see %1 for full error details.\n\n%3")
|
||||
QString errorMsg = QString("There was an error opening the region map data. Please see %1 for full error details.\n\n%2")
|
||||
.arg(getLogPath())
|
||||
.arg(getMostRecentError());
|
||||
msgBox.critical(nullptr, "Error Opening Region Map Editor", errorMsg);
|
||||
}
|
||||
delete this->regionMapEditor;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project) :
|
|||
{
|
||||
this->ui->setupUi(this);
|
||||
this->project = project;
|
||||
this->configFilepath = QString("%1/%2").arg(this->project->root).arg(projectConfig.getFilePath(ProjectFilePath::json_region_porymap_cfg));
|
||||
this->mapSectionFilepath = QString("%1/%2").arg(this->project->root).arg(projectConfig.getFilePath(ProjectFilePath::json_region_map_entries));
|
||||
this->initShortcuts();
|
||||
this->restoreWindowState();
|
||||
}
|
||||
|
@ -110,12 +112,10 @@ void RegionMapEditor::applyUserShortcuts() {
|
|||
bool RegionMapEditor::loadRegionMapEntries() {
|
||||
this->region_map_entries.clear();
|
||||
|
||||
QString regionMapSectionFilepath = QString("%1/%2").arg(this->project->root).arg(projectConfig.getFilePath(ProjectFilePath::json_region_map_entries));
|
||||
|
||||
ParseUtil parser;
|
||||
QJsonDocument sectionsDoc;
|
||||
if (!parser.tryParseJsonFile(§ionsDoc, regionMapSectionFilepath)) {
|
||||
logError(QString("Failed to read map data from %1").arg(regionMapSectionFilepath));
|
||||
if (!parser.tryParseJsonFile(§ionsDoc, this->mapSectionFilepath)) {
|
||||
logError(QString("Failed to read map data from %1").arg(this->mapSectionFilepath));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -140,11 +140,9 @@ bool RegionMapEditor::loadRegionMapEntries() {
|
|||
}
|
||||
|
||||
bool RegionMapEditor::saveRegionMapEntries() {
|
||||
QString regionMapSectionFilepath = QString("%1/%2").arg(this->project->root).arg(projectConfig.getFilePath(ProjectFilePath::json_region_map_entries));
|
||||
|
||||
QFile sectionsFile(regionMapSectionFilepath);
|
||||
QFile sectionsFile(this->mapSectionFilepath);
|
||||
if (!sectionsFile.open(QIODevice::WriteOnly)) {
|
||||
logError(QString("Error: Could not open %1 for writing").arg(regionMapSectionFilepath));
|
||||
logError(QString("Could not open %1 for writing").arg(this->mapSectionFilepath));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -477,6 +475,7 @@ bool RegionMapEditor::setup() {
|
|||
if (!newMap->loadMapData(o)) {
|
||||
delete newMap;
|
||||
// TODO: consider continue, just reporting error loading single map?
|
||||
this->setupError = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -499,26 +498,21 @@ bool RegionMapEditor::setup() {
|
|||
if (!region_maps.empty()) {
|
||||
setRegionMap(region_maps.begin()->second);
|
||||
}
|
||||
this->setupError = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegionMapEditor::load(bool silent) {
|
||||
// check for config json file
|
||||
QString jsonConfigFilepath = this->project->root + "/" + projectConfig.getFilePath(ProjectFilePath::json_region_porymap_cfg);
|
||||
|
||||
bool badConfig = true;
|
||||
|
||||
if (QFile::exists(jsonConfigFilepath)) {
|
||||
logInfo("Region map configuration file found.");
|
||||
if (QFile::exists(this->configFilepath)) {
|
||||
ParseUtil parser;
|
||||
OrderedJson::object obj;
|
||||
if (parser.tryParseOrderedJsonFile(&obj, jsonConfigFilepath)) {
|
||||
if (parser.tryParseOrderedJsonFile(&obj, this->configFilepath)) {
|
||||
this->rmConfigJson = OrderedJson(obj);
|
||||
this->configSaved = true;
|
||||
}
|
||||
badConfig = !verifyConfig(this->rmConfigJson);
|
||||
} else {
|
||||
logWarn("Region Map config file not found.");
|
||||
}
|
||||
|
||||
if (badConfig) {
|
||||
|
@ -534,14 +528,15 @@ bool RegionMapEditor::load(bool silent) {
|
|||
if (warning.exec() == QMessageBox::Ok) {
|
||||
// there is a separate window that allows to load multiple region maps,
|
||||
if (!buildConfigDialog()) {
|
||||
logError("Region map loading interrupted [user]");
|
||||
// User canceled config set up
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// do not open editor
|
||||
logError("Region map loading interrupted [user]");
|
||||
// User declined config set up
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
logInfo("Successfully loaded region map configuration file.");
|
||||
}
|
||||
|
||||
return setup();
|
||||
|
@ -583,10 +578,9 @@ void RegionMapEditor::saveConfig() {
|
|||
mapsObject["region_maps"] = mapArray;
|
||||
|
||||
OrderedJson newConfigJson(mapsObject);
|
||||
QString filepath = QString("%1/%2").arg(this->project->root).arg(projectConfig.getFilePath(ProjectFilePath::json_region_porymap_cfg));
|
||||
QFile file(filepath);
|
||||
QFile file(this->configFilepath);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
logError(QString("Error: Could not open %1 for writing").arg(filepath));
|
||||
logError(QString("Could not open %1 for writing").arg(this->configFilepath));
|
||||
return;
|
||||
}
|
||||
OrderedJsonDoc jsonDoc(&newConfigJson);
|
||||
|
|
Loading…
Reference in a new issue