Write editor state to a new, separate xml file (fix #728)
This commit is contained in:
@@ -241,8 +241,7 @@ static bool handle_lb_action(location the_point) {
|
||||
case LB_LOAD_SCEN:
|
||||
file_to_load = nav_get_scenario();
|
||||
if(!file_to_load.empty() && load_scenario(file_to_load, scenario)) {
|
||||
set_current_town(scenario.last_town_edited);
|
||||
set_current_out(scenario.last_out_edited);
|
||||
restore_editor_state();
|
||||
} else if(!file_to_load.empty())
|
||||
// If we tried to load but failed, the scenario record is messed up, so boot to start screen.
|
||||
set_up_start_screen();
|
||||
@@ -2881,3 +2880,8 @@ bool monst_on_space(location loc,short m_num) {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void restore_editor_state() {
|
||||
set_current_town(scenario.last_town_edited);
|
||||
set_current_out(scenario.last_out_edited);
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
#include "scen.global.hpp"
|
||||
#include "tools/undo.hpp"
|
||||
|
||||
void restore_editor_state();
|
||||
void init_screen_locs();
|
||||
void handle_action(location the_point,sf::Event event);
|
||||
void flash_rect(rectangle to_flash);
|
||||
|
@@ -51,10 +51,9 @@ void set_up_apple_events() {
|
||||
std::copy(msg.get(), msg.get() + len, std::inserter(fileName, fileName.begin()));
|
||||
|
||||
if(load_scenario(fileName, scenario)) {
|
||||
set_current_town(scenario.last_town_edited);
|
||||
restore_editor_state();
|
||||
change_made = false;
|
||||
ae_loading = true;
|
||||
set_current_out(scenario.last_out_edited);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@ void load_spec_graphics();
|
||||
|
||||
// These aren't static solely so that the test cases can access them.
|
||||
void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario);
|
||||
void writeEditorStateToXml(ticpp::Printer&& data, cScenario& scenario);
|
||||
void writeTerrainToXml(ticpp::Printer&& data, cScenario& scenario);
|
||||
void writeItemsToXml(ticpp::Printer&& data, cScenario& scenario);
|
||||
void writeMonstersToXml(ticpp::Printer&& data, cScenario& scenario);
|
||||
@@ -121,6 +122,14 @@ namespace ticpp {
|
||||
}
|
||||
}
|
||||
|
||||
void writeEditorStateToXml(ticpp::Printer&& data, cScenario& scenario) {
|
||||
data.OpenElement("editor");
|
||||
data.PushAttribute("boes", scenario.format_ed_version());
|
||||
data.PushElement("last-out-section", cur_out);
|
||||
data.PushElement("last-town", cur_town);
|
||||
data.CloseElement("editor");
|
||||
}
|
||||
|
||||
void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario) {
|
||||
data.OpenElement("scenario");
|
||||
data.PushAttribute("boes", scenario.format_ed_version());
|
||||
@@ -357,8 +366,6 @@ void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario) {
|
||||
data.CloseElement("game");
|
||||
data.OpenElement("editor");
|
||||
data.PushElement("default-ground", scenario.default_ground);
|
||||
data.PushElement("last-out-section", cur_out);
|
||||
data.PushElement("last-town", cur_town);
|
||||
if(!scenario.custom_graphics.empty()) {
|
||||
data.OpenElement("graphics");
|
||||
for(size_t i = 0; i < scenario.custom_graphics.size(); i++) {
|
||||
@@ -1075,6 +1082,10 @@ void save_scenario(bool rename) {
|
||||
std::ostream& header = scen_file.newFile("scenario/header.exs");
|
||||
header.write(reinterpret_cast<char*>(&scenario.format), sizeof(scenario_header_flags));
|
||||
|
||||
// Write scenario's editor state to a file that can be added to .gitignore
|
||||
std::ostream& editor_data = scen_file.newFile("scenario/editor.xml");
|
||||
writeEditorStateToXml(ticpp::Printer("scenario.xml", editor_data), scenario);
|
||||
|
||||
// Next, the bulk scenario data.
|
||||
std::ostream& scen_data = scen_file.newFile("scenario/scenario.xml");
|
||||
writeScenarioToXml(ticpp::Printer("scenario.xml", scen_data), scenario);
|
||||
|
@@ -301,10 +301,9 @@ static void process_args(int argc, char* argv[]) {
|
||||
}
|
||||
if(!file.empty()) {
|
||||
if(load_scenario(file, scenario)) {
|
||||
set_current_town(scenario.last_town_edited);
|
||||
restore_editor_state();
|
||||
change_made = false;
|
||||
ae_loading = true;
|
||||
set_current_out(scenario.last_out_edited);
|
||||
} else {
|
||||
std::cout << "Failed to load scenario: " << file << std::endl;
|
||||
}
|
||||
|
Reference in New Issue
Block a user