Fix Save All after layout split changes

This commit is contained in:
GriffinR
2025-02-19 11:07:11 -05:00
parent 559f2ae6da
commit 43d5e32b96
6 changed files with 60 additions and 42 deletions

View File

@@ -57,9 +57,8 @@ public:
GridSettings gridSettings;
void setProject(Project * project);
void save();
void saveProject();
void saveUiFields();
void saveAll();
void saveCurrent();
void saveEncounterTabData();
void closeProject();
@@ -204,6 +203,7 @@ private:
EditMode editMode = EditMode::None;
void save(bool currentOnly);
void clearMap();
void clearMetatileSelector();
void clearMovementPermissionSelector();

View File

@@ -175,6 +175,7 @@ private slots:
void on_action_Reload_Project_triggered();
void on_action_Close_Project_triggered();
void on_action_Save_Project_triggered();
void save(bool all = true);
void openWarpMap(QString map_name, int event_id, Event::Group event_group);

View File

@@ -167,13 +167,13 @@ public:
void loadTilesetMetatileLabels(Tileset*);
void readTilesetPaths(Tileset* tileset);
void saveAll();
void saveGlobalData();
void saveLayout(Layout *);
void saveLayoutBlockdata(Layout *);
void saveLayoutBorder(Layout *);
void writeBlockdata(QString, const Blockdata &);
void saveAllMaps();
void saveMap(Map *);
void saveAllDataStructures();
void saveMap(Map *map, bool skipLayout = false);
void saveConfig();
void saveMapLayouts();
void saveMapGroups();

View File

@@ -69,28 +69,30 @@ Editor::~Editor()
closeProject();
}
void Editor::saveProject() {
if (project) {
saveUiFields();
project->saveAllMaps();
project->saveAllDataStructures();
}
void Editor::saveCurrent() {
save(true);
}
void Editor::save() {
if (this->project && this->map) {
saveUiFields();
this->project->saveMap(this->map);
this->project->saveAllDataStructures();
}
else if (this->project && this->layout) {
this->project->saveLayout(this->layout);
this->project->saveAllDataStructures();
}
void Editor::saveAll() {
save(false);
}
void Editor::saveUiFields() {
void Editor::save(bool currentOnly) {
if (!this->project)
return;
saveEncounterTabData();
if (currentOnly) {
if (this->map) {
this->project->saveMap(this->map);
} else if (this->layout) {
this->project->saveLayout(this->layout);
}
this->project->saveGlobalData();
} else {
this->project->saveAll();
}
}
void Editor::setProject(Project * project) {
@@ -651,6 +653,9 @@ void Editor::configureEncounterJSON(QWidget *window) {
}
void Editor::saveEncounterTabData() {
if (!this->map || !this->project)
return;
// This function does not save to disk so it is safe to use before user clicks Save.
QStackedWidget *stack = ui->stackedWidget_WildMons;
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;

View File

@@ -1307,12 +1307,6 @@ void MainWindow::onNewMapCreated(Map *newMap, const QString &groupName) {
addNewEvent(Event::Type::HealLocation);
}
// TODO: Creating a new map shouldn't be automatically saved.
// For one, it takes away the option to discard the new map.
// For two, if the new map uses an existing layout, any unsaved changes to that layout will also be saved.
editor->project->saveMap(newMap);
editor->project->saveAllDataStructures();
// Add new map to the map lists
this->mapGroupModel->insertMapItem(newMap->name(), groupName);
this->mapLocationModel->insertMapItem(newMap->name(), newMap->header()->location());
@@ -1328,7 +1322,12 @@ void MainWindow::onNewMapCreated(Map *newMap, const QString &groupName) {
ui->comboBox_EmergeMap->insertItem(mapIndex, newMap->name());
}
userSetMap(newMap->name());
if (userSetMap(newMap->name())) {
// TODO: Creating a new map shouldn't be automatically saved.
// For one, it takes away the option to discard the new map.
// For two, if the new map uses an existing layout, any unsaved changes to that layout will also be saved.
save(true);
}
}
// Called any time a new layout is created (including as a byproduct of creating a new map)
@@ -1551,14 +1550,19 @@ void MainWindow::updateMapList() {
}
void MainWindow::on_action_Save_Project_triggered() {
editor->saveProject();
updateWindowTitle();
updateMapList();
saveGlobalConfigs();
save(false);
}
void MainWindow::on_action_Save_triggered() {
editor->save();
save(true);
}
void MainWindow::save(bool currentOnly) {
if (currentOnly) {
this->editor->saveCurrent();
} else {
this->editor->saveAll();
}
updateWindowTitle();
updateMapList();
saveGlobalConfigs();
@@ -3008,7 +3012,7 @@ bool MainWindow::closeProject() {
auto reply = msgBox.exec();
if (reply == QMessageBox::Yes) {
editor->saveProject();
save();
} else if (reply == QMessageBox::No) {
logWarn("Closing project with unsaved changes.");
} else if (reply == QMessageBox::Cancel) {

View File

@@ -1155,12 +1155,17 @@ void Project::writeBlockdata(QString path, const Blockdata &blockdata) {
}
}
void Project::saveAllMaps() {
for (auto *map : mapCache.values())
saveMap(map);
void Project::saveAll() {
for (auto map : this->mapCache) {
saveMap(map, true); // Avoid double-saving the layouts
}
for (auto layout : this->mapLayouts) {
saveLayout(layout);
}
saveGlobalData();
}
void Project::saveMap(Map *map) {
void Project::saveMap(Map *map, bool skipLayout) {
// Create/Modify a few collateral files for brand new maps.
const QString folderPath = projectConfig.getFilePath(ProjectFilePath::data_map_folders) + map->name();
const QString fullPath = QString("%1/%2").arg(this->root).arg(folderPath);
@@ -1289,12 +1294,15 @@ void Project::saveMap(Map *map) {
jsonDoc.dump(&mapFile);
mapFile.close();
saveLayout(map->layout());
if (!skipLayout) saveLayout(map->layout());
map->setClean();
}
void Project::saveLayout(Layout *layout) {
if (!layout || !layout->loaded)
return;
saveLayoutBorder(layout);
saveLayoutBlockdata(layout);
@@ -1317,7 +1325,7 @@ void Project::updateLayout(Layout *layout) {
}
}
void Project::saveAllDataStructures() {
void Project::saveGlobalData() {
saveMapLayouts();
saveMapGroups();
saveRegionMapSections();