From a4385848711fa327ffd15a1795f26f53929548ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sat, 21 Jan 2023 22:01:42 +0100 Subject: [PATCH] Only save custom GOL data if it changed --- src/gui/game/GameModel.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index 072fa320b..1bc81c3cd 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -310,11 +310,13 @@ void GameModel::BuildMenus() auto customGOLTypes = prefs.Get("CustomGOL.Types", std::vector{}); std::vector validatedCustomLifeTypes; std::vector newCustomGol; + bool removedAny = false; for (auto gol : customGOLTypes) { auto parts = gol.FromUtf8().PartitionBy(' '); if (parts.size() != 4) { + removedAny = true; continue; } Simulation::CustomGOLData gd; @@ -324,11 +326,13 @@ void GameModel::BuildMenus() auto &colour2String = parts[3]; if (!ValidateGOLName(gd.nameString)) { + removedAny = true; continue; } gd.rule = ParseGOLString(gd.ruleString); if (gd.rule == -1) { + removedAny = true; continue; } try @@ -338,13 +342,17 @@ void GameModel::BuildMenus() } catch (std::exception &) { + removedAny = true; continue; } newCustomGol.push_back(gd); validatedCustomLifeTypes.push_back(gol); } - // All custom rules that fail validation will be removed - prefs.Set("CustomGOL.Types", validatedCustomLifeTypes); + if (removedAny) + { + // All custom rules that fail validation will be removed + prefs.Set("CustomGOL.Types", validatedCustomLifeTypes); + } for (auto &gd : newCustomGol) { Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(gd.rule), gd.nameString, "Custom GOL type: " + gd.ruleString, PIXR(gd.colour1), PIXG(gd.colour1), PIXB(gd.colour1), "DEFAULT_PT_LIFECUST_"+gd.nameString.ToAscii(), NULL); @@ -1654,7 +1662,10 @@ bool GameModel::RemoveCustomGOLType(const ByteString &identifier) else newCustomGOLTypes.push_back(gol); } - prefs.Set("CustomGOL.Types", newCustomGOLTypes); + if (removedAny) + { + prefs.Set("CustomGOL.Types", newCustomGOLTypes); + } BuildMenus(); return removedAny; }