@@ -49,6 +49,7 @@ static bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, eLoadSc
49
49
// Some of these are non-static so that the test cases can access them.
50
50
ticpp::Document xmlDocFromStream (std::istream& stream, std::string name);
51
51
void readScenarioFromXml (ticpp::Document&& data, cScenario& scenario);
52
+ void readEditorStateFromXml (ticpp::Document&& data, cScenario& scenario);
52
53
void readTerrainFromXml (ticpp::Document&& data, cScenario& scenario);
53
54
void readItemsFromXml (ticpp::Document&& data, cScenario& scenario);
54
55
void readMonstersFromXml (ticpp::Document&& data, cScenario& scenario);
@@ -932,19 +933,22 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
932
933
if (!reqs.empty ())
933
934
throw xMissingElem (" game" , *reqs.begin (), elem->Row (), elem->Column (), fname);
934
935
} else if (type == " editor" ) {
935
- std::set<std::string> reqs = {" default-ground" , " last-out-section " , " last-town " };
936
+ std::set<std::string> reqs = {" default-ground" };
936
937
Iterator<Element> edit;
937
938
int num_storage = 0 , num_pics = 0 ;
938
939
for (edit = edit.begin (elem.Get ()); edit != edit.end (); edit++) {
939
940
edit->GetValue (&type);
940
941
reqs.erase (type);
941
942
if (type == " default-ground" ) {
942
943
edit->GetText (&scenario.default_ground );
943
- } else if (type == " last-out-section" ) {
944
+ }
945
+ // Old scenario files may have last-out-section and last-town in scenario.xml
946
+ else if (type == " last-out-section" ) {
944
947
scenario.last_out_edited = readLocFromXml (*edit);
945
948
} else if (type == " last-town" ) {
946
949
edit->GetText (&scenario.last_town_edited );
947
- } else if (type == " sound" ) {
950
+ }
951
+ else if (type == " sound" ) {
948
952
int sndnum = 0 ;
949
953
edit->GetAttribute (" id" , &sndnum);
950
954
if (sndnum < 100 )
@@ -1066,6 +1070,23 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
1066
1070
throw xMissingElem (" scenario" , *reqs.begin (), data.FirstChildElement ()->Row (), data.FirstChildElement ()->Column (), fname);
1067
1071
}
1068
1072
1073
+ void readEditorStateFromXml (ticpp::Document&& data, cScenario& scenario) {
1074
+ using namespace ticpp ;
1075
+ int maj, min, rev;
1076
+ std::string fname, type, name, val;
1077
+ initialXmlRead (data, " editor" , maj, min, rev, fname);
1078
+ Iterator<Attribute> attr;
1079
+ Iterator<Element> elem;
1080
+ for (elem = elem.begin (data.FirstChildElement ()); elem != elem.end (); elem++) {
1081
+ elem->GetValue (&type);
1082
+ if (type == " last-out-section" ) {
1083
+ scenario.last_out_edited = readLocFromXml (*elem);
1084
+ } else if (type == " last-town" ) {
1085
+ elem->GetText (&scenario.last_town_edited );
1086
+ }
1087
+ }
1088
+ }
1089
+
1069
1090
void readTerrainFromXml (ticpp::Document&& data, cScenario& scenario) {
1070
1091
using namespace ticpp ;
1071
1092
int maj, min, rev;
@@ -2187,6 +2208,10 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, eLoadScenario
2187
2208
return false ;
2188
2209
}
2189
2210
}
2211
+ auto hasFile = [&](std::string relpath) -> bool {
2212
+ if (is_packed) return pack.hasFile (" scenario/" + relpath);
2213
+ return fs::exists (file_to_load/relpath);
2214
+ };
2190
2215
auto getFile = [&](std::string relpath) -> std::istream& {
2191
2216
if (is_packed) return pack.getFile (" scenario/" + relpath);
2192
2217
if (fin.is_open ()) fin.close ();
@@ -2217,6 +2242,12 @@ bool load_scenario_v2(fs::path file_to_load, cScenario& scenario, eLoadScenario
2217
2242
2218
2243
if (load_type == eLoadScenario::ONLY_HEADER) return true ;
2219
2244
if (load_type != eLoadScenario::SAVE_PREVIEW){
2245
+ // Editor state, even though the game won't need it
2246
+ if (hasFile (" editor.xml" )){
2247
+ std::istream& editor = getFile (" editor.xml" );
2248
+ readEditorStateFromXml (xmlDocFromStream (editor, " editor.xml" ), scenario);
2249
+ }
2250
+
2220
2251
// Next, terrain types...
2221
2252
std::istream& terrain = getFile (" terrain.xml" );
2222
2253
readTerrainFromXml (xmlDocFromStream (terrain, " terrain.xml" ), scenario);
0 commit comments