DRY retrieval of some types from replay action

This commit is contained in:
2024-07-31 17:28:48 -05:00
committed by Celtic Minstrel
parent 40cec6e861
commit 1e68d32543
3 changed files with 20 additions and 6 deletions

View File

@@ -269,14 +269,10 @@ void replay_next_action() {
load_party(tempDir / "temp.exg", univ);
finish_load_party();
}else if(t == "move"){
location l;
std::istringstream sstr(next_action.GetText());
sstr >> l;
location l = location_from_action(next_action);
handle_move(l, did_something, need_redraw, need_reprint);
}else if(t == "handle_switch_pc"){
short which_pc;
std::istringstream sstr(next_action.GetText());
sstr >> which_pc;
short which_pc = short_from_action(next_action);
handle_switch_pc(which_pc, need_redraw, need_reprint);
}

View File

@@ -6,6 +6,7 @@
#include <ctime>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <boost/algorithm/string/predicate.hpp>
#include <cppcodec/base64_rfc4648.hpp>
using base64 = cppcodec::base64_rfc4648;
@@ -136,4 +137,18 @@ void decode_file(std::string data, fs::path file) {
std::vector<uint8_t> bytes = base64::decode(data.c_str(), strlen(data.c_str()) * sizeof(char));
char* bytes_as_c_str = reinterpret_cast<char*>(bytes.data());
ofs.write(bytes_as_c_str, bytes.size() / sizeof(char));
}
location location_from_action(Element& action) {
location l;
std::istringstream sstr(action.GetText());
sstr >> l;
return l;
}
short short_from_action(Element& action) {
short s;
std::istringstream sstr(action.GetText());
sstr >> s;
return s;
}

View File

@@ -5,6 +5,7 @@
#include <sstream>
#include <map>
#include <boost/filesystem.hpp>
#include "location.hpp"
// Input recording system
namespace ticpp { class Element; }
@@ -22,5 +23,7 @@ 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);
extern location location_from_action(Element& action);
extern short short_from_action(Element& action);
#endif