save and reload new editor state

This commit is contained in:
2025-05-09 13:55:19 -05:00
parent 39ed4eb1f3
commit 757532b7af
2 changed files with 67 additions and 4 deletions

View File

@@ -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<Attribute> attr;
Iterator<Element> 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};
}
}
}

View File

@@ -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;