make pop_next_action() return a reference

This commit is contained in:
2024-07-27 20:17:22 -05:00
committed by Celtic Minstrel
parent 902fdb7a61
commit 3c3a105ae4
6 changed files with 23 additions and 20 deletions

View File

@@ -538,12 +538,12 @@ void cDialog::handle_events() {
while(dialogNotToast) {
if(replaying){
if(next_action_type() == "control_click"){
Element* next_action = pop_next_action();
Element& next_action = pop_next_action();
auto info = info_from_action(next_action);
eKeyMod mods = static_cast<eKeyMod>(atoi(info["mods"].c_str()));
controls[info["id"]]->triggerClickHandler(*this, info["id"], mods);
}else if(next_action_type() == "control_focus"){
Element* next_action = pop_next_action();
Element& next_action = pop_next_action();
auto info = info_from_action(next_action);
bool losing;
istringstream sstr(info["losing"]);

View File

@@ -35,8 +35,8 @@ extern fs::path nav_put_party(fs::path def);
fs::path nav_get_or_decode_party() {
if(replaying){
Element* next_action = pop_next_action("load_party");
decode_file(next_action->GetText(), tempDir / "temp.exg");
Element& next_action = pop_next_action("load_party");
decode_file(next_action.GetText(), tempDir / "temp.exg");
return tempDir / "temp.exg";
}else{
return nav_get_party();

View File

@@ -257,19 +257,19 @@ void process_args(int argc, char* argv[]) {
void replay_next_action() {
bool did_something = false, need_redraw = false, need_reprint = false;
auto next_action = pop_next_action();
std::string t = next_action->Value();
Element& next_action = pop_next_action();
std::string t = next_action.Value();
if(overall_mode == MODE_STARTUP && t == "startup_button_click"){
eStartButton btn = static_cast<eStartButton>(atoi(next_action->GetText().c_str()));
eStartButton btn = static_cast<eStartButton>(atoi(next_action.GetText().c_str()));
handle_startup_button_click(btn);
}else if(t == "load_party"){
decode_file(next_action->GetText(), tempDir / "temp.exg");
decode_file(next_action.GetText(), tempDir / "temp.exg");
load_party(tempDir / "temp.exg", univ);
finish_load_party();
}else if(t == "move"){
location l;
std::istringstream sstr(next_action->GetText());
std::istringstream sstr(next_action.GetText());
sstr >> l;
handle_move(l, did_something, need_redraw, need_reprint);
}
@@ -304,9 +304,9 @@ void init_boe(int argc, char* argv[]) {
// Seed the RNG
if(replaying) {
auto srand_element = pop_next_action("srand");
Element& srand_element = pop_next_action("srand");
std::string ts(srand_element->GetText());
std::string ts(srand_element.GetText());
srand(atoi(ts.c_str()));
} else {
auto t = time(nullptr);

View File

@@ -160,8 +160,8 @@ static bool load_prefs(fs::path fpath) {
// When replaying a BoE session, disregard the system settings and use the ones
// that were recorded
if (replaying) {
Element* prefs_action = pop_next_action("load_prefs");
std::istringstream in(prefs_action->GetText());
Element& prefs_action = pop_next_action("load_prefs");
std::istringstream in(prefs_action.GetText());
return load_prefs(in);
} else {
std::ifstream in(fpath.c_str());

View File

@@ -89,8 +89,11 @@ std::string next_action_type() {
return next_action->Value();
}
Element* pop_next_action(std::string expected_action_type) {
if (expected_action_type != "" && next_action->Value() != expected_action_type) {
Element& pop_next_action(std::string expected_action_type) {
if(next_action == nullptr){
throw "Replay error! No action left to pop";
}
if(expected_action_type != "" && next_action->Value() != expected_action_type){
std::ostringstream stream;
stream << "Replay error! Expected '" << expected_action_type << "' action next";
throw stream.str();
@@ -100,12 +103,12 @@ Element* pop_next_action(std::string expected_action_type) {
next_action = next_action->NextSiblingElement(false);
return to_return;
return *to_return;
}
std::map<std::string,std::string> info_from_action(Element* action) {
std::map<std::string,std::string> info_from_action(Element& action) {
std::map<std::string,std::string> info = {};
Element* next_child = action->FirstChildElement(false);
Element* next_child = action.FirstChildElement(false);
while(next_child){
info[next_child->Value()] = next_child->GetText();
next_child = next_child->NextSiblingElement(false);

View File

@@ -18,8 +18,8 @@ extern void record_action(std::string action_type, std::string inner_text);
extern void record_action(std::string action_type, std::map<std::string,std::string> info);
extern bool has_next_action();
extern std::string next_action_type();
extern Element* pop_next_action(std::string expected_action_type="");
extern std::map<std::string,std::string> info_from_action(Element* action);
extern Element& pop_next_action(std::string expected_action_type="");
extern std::map<std::string,std::string> info_from_action(Element& action);
extern std::string encode_file(fs::path file);
extern void decode_file(std::string data, fs::path file);