From 757532b7af907daff90f092be017b9f8ccdd8728 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 9 May 2025 13:55:19 -0500 Subject: [PATCH] save and reload new editor state --- src/fileio/fileio_scen.cpp | 46 +++++++++++++++++++++++++++++++++--- src/scenedit/scen.fileio.cpp | 25 +++++++++++++++++++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/fileio/fileio_scen.cpp b/src/fileio/fileio_scen.cpp index e0c794fa..efc92965 100644 --- a/src/fileio/fileio_scen.cpp +++ b/src/fileio/fileio_scen.cpp @@ -1074,15 +1074,55 @@ void readEditorStateFromXml(ticpp::Document&& data, cScenario& scenario) { using namespace ticpp; int maj, min, rev; std::string fname, type, name, val; + editor_state_t& editor_state = scenario.editor_state; initialXmlRead(data, "editor", maj, min, rev, fname); Iterator attr; Iterator elem; + + std::string child_type; + short num; + location section; + location center; + short viewing_mode; + for(elem = elem.begin(data.FirstChildElement()); elem != elem.end(); elem++) { elem->GetValue(&type); if(type == "last-out-section") { - scenario.editor_state.last_out_edited = readLocFromXml(*elem); - } else if(type == "last-town") { - elem->GetText(&scenario.editor_state.last_town_edited); + editor_state.last_out_edited = readLocFromXml(*elem); + }else if(type == "last-town") { + elem->GetText(&editor_state.last_town_edited); + }else if(type == "drawing"){ + editor_state.drawing = str_to_bool(elem->GetText()); + }else if(type == "editing-town"){ + editor_state.editing_town = str_to_bool(elem->GetText()); + }else if(type == "town-view-state"){ + Element* child = elem->FirstChildElement(); + while(child != nullptr){ + child->GetValue(&child_type); + if(child_type == "num"){ + child->GetText(&num); + }else if(child_type == "center"){ + center = readLocFromXml(*child); + }else if(child_type == "viewing-mode"){ + child->GetText(&viewing_mode); + } + child = child->NextSiblingElement(false); + } + editor_state.town_view_state[num] = {center, viewing_mode}; + }else if(type == "out-view-state"){ + Element* child = elem->FirstChildElement(); + while(child != nullptr){ + child->GetValue(&child_type); + if(child_type == "section"){ + section = readLocFromXml(*child); + }else if(child_type == "center"){ + center = readLocFromXml(*child); + }else if(child_type == "viewing-mode"){ + child->GetText(&viewing_mode); + } + child = child->NextSiblingElement(false); + } + editor_state.out_view_state[section] = {center, viewing_mode}; } } } diff --git a/src/scenedit/scen.fileio.cpp b/src/scenedit/scen.fileio.cpp index cf61b52c..a58326b3 100644 --- a/src/scenedit/scen.fileio.cpp +++ b/src/scenedit/scen.fileio.cpp @@ -123,10 +123,31 @@ namespace ticpp { } void writeEditorStateToXml(ticpp::Printer&& data, cScenario& scenario) { + editor_state_t editor_state = scenario.editor_state; + data.OpenElement("editor"); data.PushAttribute("boes", scenario.format_ed_version()); - data.PushElement("last-out-section", cur_out); + data.PushElement("drawing", editor_state.drawing); + data.PushElement("editing-town", editor_state.editing_town); + data.PushElement("last-town", cur_town); + for(auto pair : scenario.editor_state.town_view_state){ + data.OpenElement("town-view-state"); + data.PushElement("num", pair.first); + data.PushElement("center", pair.second.center); + data.PushElement("viewing-mode", pair.second.cur_viewing_mode); + data.CloseElement("town-view-state"); + } + + data.PushElement("last-out-section", cur_out); + for(auto pair : scenario.editor_state.out_view_state){ + data.OpenElement("out-view-state"); + data.PushElement("section", pair.first); + data.PushElement("center", pair.second.center); + data.PushElement("viewing-mode", pair.second.cur_viewing_mode); + data.CloseElement("out-view-state"); + } + data.CloseElement("editor"); } @@ -1059,7 +1080,9 @@ struct overrides_sheet { extern std::string scenario_temp_dir_name; extern fs::path scenDir; +extern void store_current_terrain_state(); void save_scenario(bool rename) { + store_current_terrain_state(); fs::path toFile = scenario.scen_file; if(rename || toFile.empty()) { fs::path def = scenario.scen_file;