extract editor state vars in cScenario to a new struct
This commit is contained in:
@@ -944,9 +944,9 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
|
|||||||
}
|
}
|
||||||
// Old scenario files may have last-out-section and last-town in scenario.xml
|
// Old scenario files may have last-out-section and last-town in scenario.xml
|
||||||
else if(type == "last-out-section") {
|
else if(type == "last-out-section") {
|
||||||
scenario.last_out_edited = readLocFromXml(*edit);
|
scenario.editor_state.last_out_edited = readLocFromXml(*edit);
|
||||||
} else if(type == "last-town") {
|
} else if(type == "last-town") {
|
||||||
edit->GetText(&scenario.last_town_edited);
|
edit->GetText(&scenario.editor_state.last_town_edited);
|
||||||
}
|
}
|
||||||
else if(type == "sound") {
|
else if(type == "sound") {
|
||||||
int sndnum = 0;
|
int sndnum = 0;
|
||||||
@@ -1080,9 +1080,9 @@ void readEditorStateFromXml(ticpp::Document&& data, cScenario& scenario) {
|
|||||||
for(elem = elem.begin(data.FirstChildElement()); elem != elem.end(); elem++) {
|
for(elem = elem.begin(data.FirstChildElement()); elem != elem.end(); elem++) {
|
||||||
elem->GetValue(&type);
|
elem->GetValue(&type);
|
||||||
if(type == "last-out-section") {
|
if(type == "last-out-section") {
|
||||||
scenario.last_out_edited = readLocFromXml(*elem);
|
scenario.editor_state.last_out_edited = readLocFromXml(*elem);
|
||||||
} else if(type == "last-town") {
|
} else if(type == "last-town") {
|
||||||
elem->GetText(&scenario.last_town_edited);
|
elem->GetText(&scenario.editor_state.last_town_edited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,8 +110,7 @@ cScenario::cScenario(const cScenario& other)
|
|||||||
, scenario_timers(other.scenario_timers)
|
, scenario_timers(other.scenario_timers)
|
||||||
, scen_specials(other.scen_specials)
|
, scen_specials(other.scen_specials)
|
||||||
, storage_shortcuts(other.storage_shortcuts)
|
, storage_shortcuts(other.storage_shortcuts)
|
||||||
, last_out_edited(other.last_out_edited)
|
, editor_state(other.editor_state)
|
||||||
, last_town_edited(other.last_town_edited)
|
|
||||||
, format(other.format)
|
, format(other.format)
|
||||||
, campaign_id(other.campaign_id)
|
, campaign_id(other.campaign_id)
|
||||||
, scen_items(other.scen_items)
|
, scen_items(other.scen_items)
|
||||||
@@ -178,8 +177,7 @@ void swap(cScenario& lhs, cScenario& rhs) {
|
|||||||
swap(lhs.scenario_timers, rhs.scenario_timers);
|
swap(lhs.scenario_timers, rhs.scenario_timers);
|
||||||
swap(lhs.scen_specials, rhs.scen_specials);
|
swap(lhs.scen_specials, rhs.scen_specials);
|
||||||
swap(lhs.storage_shortcuts, rhs.storage_shortcuts);
|
swap(lhs.storage_shortcuts, rhs.storage_shortcuts);
|
||||||
swap(lhs.last_out_edited, rhs.last_out_edited);
|
swap(lhs.editor_state, rhs.editor_state);
|
||||||
swap(lhs.last_town_edited, rhs.last_town_edited);
|
|
||||||
swap(lhs.format, rhs.format);
|
swap(lhs.format, rhs.format);
|
||||||
swap(lhs.campaign_id, rhs.campaign_id);
|
swap(lhs.campaign_id, rhs.campaign_id);
|
||||||
swap(lhs.scen_items, rhs.scen_items);
|
swap(lhs.scen_items, rhs.scen_items);
|
||||||
@@ -263,9 +261,9 @@ void cScenario::import_legacy(legacy::scenario_data_type& old){
|
|||||||
scenario_timers[i].time = old.scenario_timer_times[i];
|
scenario_timers[i].time = old.scenario_timer_times[i];
|
||||||
scenario_timers[i].node = old.scenario_timer_specs[i];
|
scenario_timers[i].node = old.scenario_timer_specs[i];
|
||||||
}
|
}
|
||||||
last_out_edited.x = old.last_out_edited.x;
|
editor_state.last_out_edited.x = old.last_out_edited.x;
|
||||||
last_out_edited.y = old.last_out_edited.y;
|
editor_state.last_out_edited.y = old.last_out_edited.y;
|
||||||
last_town_edited = old.last_town_edited;
|
editor_state.last_town_edited = old.last_town_edited;
|
||||||
adjust_diff = true;
|
adjust_diff = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,15 @@ struct town_entrance_t {
|
|||||||
int town;
|
int town;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is completely unnecessary outside of the scenario editor, but harmless to load anyway,
|
||||||
|
// and much easier to store in cScenario so readScenarioFromXML() doesn't need conditionally compiled
|
||||||
|
// access to scenedit-specific global variables (which won't work unless we want to compile the common
|
||||||
|
// sources 3 times), or globals redeclared for no reason in boe.main.cpp and pc.main.cpp
|
||||||
|
struct editor_state_t {
|
||||||
|
short last_town_edited;
|
||||||
|
location last_out_edited;
|
||||||
|
};
|
||||||
|
|
||||||
class cScenario {
|
class cScenario {
|
||||||
public:
|
public:
|
||||||
class cItemStorage {
|
class cItemStorage {
|
||||||
@@ -84,9 +93,7 @@ public:
|
|||||||
std::array<cTimer,20> scenario_timers;
|
std::array<cTimer,20> scenario_timers;
|
||||||
std::vector<cSpecial> scen_specials;
|
std::vector<cSpecial> scen_specials;
|
||||||
std::array<cItemStorage,10> storage_shortcuts;
|
std::array<cItemStorage,10> storage_shortcuts;
|
||||||
// These two \/ are populated at load time and then never used again
|
editor_state_t editor_state;
|
||||||
location last_out_edited;
|
|
||||||
short last_town_edited;
|
|
||||||
scenario_header_flags format;
|
scenario_header_flags format;
|
||||||
std::string campaign_id; // A hopefully unique identifier to specify the campaign this scenario is a part of.
|
std::string campaign_id; // A hopefully unique identifier to specify the campaign this scenario is a part of.
|
||||||
std::vector<cItem> scen_items;
|
std::vector<cItem> scen_items;
|
||||||
|
|||||||
@@ -2882,6 +2882,6 @@ bool monst_on_space(location loc,short m_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void restore_editor_state() {
|
void restore_editor_state() {
|
||||||
set_current_town(scenario.last_town_edited);
|
set_current_town(scenario.editor_state.last_town_edited);
|
||||||
set_current_out(scenario.last_out_edited);
|
set_current_out(scenario.editor_state.last_out_edited);
|
||||||
}
|
}
|
||||||
@@ -448,10 +448,8 @@ void handle_menu_choice(eMenu item_hit) {
|
|||||||
break;
|
break;
|
||||||
file_to_load = item_hit == eMenu::FILE_OPEN ? nav_get_scenario() : scenario.scen_file;
|
file_to_load = item_hit == eMenu::FILE_OPEN ? nav_get_scenario() : scenario.scen_file;
|
||||||
if(!file_to_load.empty() && load_scenario(file_to_load, scenario)) {
|
if(!file_to_load.empty() && load_scenario(file_to_load, scenario)) {
|
||||||
cur_town = scenario.last_town_edited;
|
restore_editor_state();
|
||||||
town = scenario.towns[cur_town];
|
|
||||||
change_made = false;
|
change_made = false;
|
||||||
set_current_out(scenario.last_out_edited);
|
|
||||||
} else if(!file_to_load.empty())
|
} else if(!file_to_load.empty())
|
||||||
set_up_start_screen(); // Failed to load file, dump to start
|
set_up_start_screen(); // Failed to load file, dump to start
|
||||||
undo_list.clear();
|
undo_list.clear();
|
||||||
|
|||||||
@@ -1529,12 +1529,12 @@ void set_current_town(int to) {
|
|||||||
if(to < 0 || to >= scenario.towns.size()) return;
|
if(to < 0 || to >= scenario.towns.size()) return;
|
||||||
cur_town = to;
|
cur_town = to;
|
||||||
town = scenario.towns[cur_town];
|
town = scenario.towns[cur_town];
|
||||||
scenario.last_town_edited = cur_town;
|
scenario.editor_state.last_town_edited = cur_town;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_current_out(location out_sec) {
|
void set_current_out(location out_sec) {
|
||||||
cur_out = out_sec;
|
cur_out = out_sec;
|
||||||
scenario.last_out_edited = cur_out;
|
scenario.editor_state.last_out_edited = cur_out;
|
||||||
current_terrain = scenario.outdoors[cur_out.x][cur_out.y];
|
current_terrain = scenario.outdoors[cur_out.x][cur_out.y];
|
||||||
set_up_main_screen();
|
set_up_main_screen();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ TEST_CASE("Converting legacy scenario data") {
|
|||||||
CHECK(scen.intro_pic == 27);
|
CHECK(scen.intro_pic == 27);
|
||||||
CHECK(scen.is_legacy);
|
CHECK(scen.is_legacy);
|
||||||
CHECK(scen.journal_strs.empty());
|
CHECK(scen.journal_strs.empty());
|
||||||
CHECK(scen.last_out_edited == loc(1,1));
|
CHECK(scen.editor_state.last_out_edited == loc(1,1));
|
||||||
CHECK(scen.last_town_edited == 2);
|
CHECK(scen.editor_state.last_town_edited == 2);
|
||||||
CHECK(scen.out_sec_start == loc(4,4));
|
CHECK(scen.out_sec_start == loc(4,4));
|
||||||
CHECK(scen.out_start == loc(1,1));
|
CHECK(scen.out_start == loc(1,1));
|
||||||
CHECK(scen.rating == eContentRating::R);
|
CHECK(scen.rating == eContentRating::R);
|
||||||
|
|||||||
Reference in New Issue
Block a user