From ae45391ec0545792de0cf2e6730996163dd46789 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Tue, 2 Jun 2020 12:59:54 +0200 Subject: [PATCH] Add editor saving/loading error messages Previously, the editor would always say it saved or loaded a level, even if it was not successful. For example, because a file to load does not exist, a file to save has illegal characters in its name or the name is too long to be stored. Now failure is reported. Also, when quitting the editor and saving before quitting is unsuccessful, the editor will abort quitting. --- desktop_version/src/editor.cpp | 34 +++++++++++++++++++++++++--------- desktop_version/src/editor.h | 4 ++-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index e45abc6d..e2c27515 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -1644,7 +1644,7 @@ int editorclass::findwarptoken(int t) return 0; } -void editorclass::load(std::string& _path) +bool editorclass::load(std::string& _path) { reset(); @@ -1694,7 +1694,7 @@ void editorclass::load(std::string& _path) if (!FILESYSTEM_loadTiXmlDocument(_path.c_str(), &doc)) { printf("No level %s to load :(\n", _path.c_str()); - return; + return false; } @@ -1905,9 +1905,11 @@ void editorclass::load(std::string& _path) gethooks(); version=2; + + return true; } -void editorclass::save(std::string& _path) +bool editorclass::save(std::string& _path) { TiXmlDocument doc; TiXmlElement* msg; @@ -2058,7 +2060,7 @@ void editorclass::save(std::string& _path) msg->LinkEndChild( new TiXmlText( scriptString.c_str() )); data->LinkEndChild( msg ); - FILESYSTEM_saveTiXmlDocument(("levels/" + _path).c_str(), &doc); + return FILESYSTEM_saveTiXmlDocument(("levels/" + _path).c_str(), &doc); } @@ -4048,15 +4050,22 @@ void editorinput() else if(ed.savemod) { std::string savestring=ed.filename+".vvvvvv"; - ed.save(savestring); - ed.note="[ Saved map: " + ed.filename+ ".vvvvvv]"; + bool success = ed.save(savestring); + if (success) + { + ed.note="[ Saved map: " + ed.filename+ ".vvvvvv]"; + } + else + { + ed.note="[ ERROR: Could not save level! ]"; + } ed.notedelay=45; ed.savemod=false; ed.shiftmenu=false; ed.shiftkey=false; - if(ed.saveandquit) + if(ed.saveandquit && success) { //quit editor graphics.fademode = 2; @@ -4065,8 +4074,15 @@ void editorinput() else if(ed.loadmod) { std::string loadstring=ed.filename+".vvvvvv"; - ed.load(loadstring); - ed.note="[ Loaded map: " + ed.filename+ ".vvvvvv]"; + bool success = ed.load(loadstring); + if (success) + { + ed.note="[ Loaded map: " + ed.filename+ ".vvvvvv]"; + } + else + { + ed.note="[ ERROR: Could not load level ]"; + } ed.notedelay=45; ed.loadmod=false; diff --git a/desktop_version/src/editor.h b/desktop_version/src/editor.h index 59abef02..4d5942ce 100644 --- a/desktop_version/src/editor.h +++ b/desktop_version/src/editor.h @@ -123,8 +123,8 @@ class editorclass{ int backmatch(int x, int y); - void load(std::string& _path); - void save(std::string& _path); + bool load(std::string& _path); + bool save(std::string& _path); void generatecustomminimap(); int edgetile(int x, int y); int warpzoneedgetile(int x, int y);