Encode startup buttons as string in replays, fix #533

This commit is contained in:
2025-01-16 12:08:46 -06:00
parent 3455327363
commit 2d824e869e
5 changed files with 49 additions and 16 deletions

View File

@@ -10,6 +10,7 @@
#define BOE_GAME_CONSTS_H
#include <set>
#include <map>
/* overall mode; some seem to be missing */
enum eGameMode {
@@ -84,14 +85,9 @@ enum eTrapType {
// Startup buttons
enum eStartButton {
// Left Column
STARTBTN_TUTORIAL = 0,
STARTBTN_LOAD = 1,
STARTBTN_PREFS = 2,
// Right Column
STARTBTN_NEW = 3,
STARTBTN_JOIN = 4,
STARTBTN_SCROLL = 5,
STARTBTN_TUTORIAL = 0, STARTBTN_NEW = 3,
STARTBTN_LOAD = 1, STARTBTN_JOIN = 4,
STARTBTN_PREFS = 2, STARTBTN_SCROLL = 5,
// Keep last:
MAX_eStartButton = 6
};

View File

@@ -6,6 +6,7 @@
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include "boe.consts.hpp"
#define ASB add_string_to_buf
@@ -26,4 +27,8 @@ struct effect_pat_type {
unsigned short pattern[9][9];
};
extern std::map<std::string, int> startup_button_indices;
extern std::map<int, std::string> startup_button_names;
extern std::map<int, std::string> startup_button_names_v1;
#endif

View File

@@ -414,12 +414,9 @@ void draw_startup_stats() {
void draw_start_button(eStartButton which_position,short which_button) {
rectangle from_rect,to_rect;
const char *button_labels[MAX_eStartButton];
button_labels[STARTBTN_TUTORIAL] = "Tutorial";
button_labels[STARTBTN_LOAD] = "Load Game";
button_labels[STARTBTN_PREFS] = "Preferences";
button_labels[STARTBTN_NEW] = "Make New Party";
button_labels[STARTBTN_JOIN] = "Start Scenario";
button_labels[STARTBTN_SCROLL] = "";
for(int i = 0; i < MAX_eStartButton; ++i){
button_labels[i] = startup_button_names[i].c_str();
}
// The 0..65535 version of the blue component was 14472; the commented version was 43144431
sf::Color base_color = {0,0,57};

View File

@@ -310,6 +310,29 @@ static void process_args(int argc, char* argv[]) {
}
}
std::map<std::string, int> startup_button_indices = {
// Button layout since 11/30/24
{"Tutorial", 0}, {"Make New Party", 3},
{"Load Game", 1}, {"Start Scenario", 4},
{"Preferences", 2},
// Buttons that don't exist anymore
{"Custom Scenario", -1},
};
std::map<int, std::string> startup_button_names = {
{0, "Tutorial"}, {3, "Make New Party"},
{1, "Load Game"}, {4, "Start Scenario"},
{2, "Preferences"}, {5, ""},
};
// Map legacy int indices onto new string-mapped layout
std::map<int, std::string> startup_button_names_v1 = {
{0, "Load Game"}, {3, "Start Scenario"},
{1, "Make New Party"}, {4, "Custom Scenario"},
{2, "Preferences"},
};
void replay_action(Element& action) {
bool did_something = false, need_redraw = false, need_reprint = false;
@@ -320,7 +343,19 @@ void replay_action(Element& action) {
// NOTE: Action replay blocks need to return early unless the action advances time
if(overall_mode == MODE_STARTUP && t == "startup_button_click"){
auto info = info_from_action(action);
eStartButton btn = static_cast<eStartButton>(std::stoi(info["btn"]));
int btn_idx = -1;
try{
// Legacy replays use ints to encode startup buttons
btn_idx = std::stoi(info["btn"]);
}catch(std::invalid_argument& err){
// Newer replays use strings to encode startup buttons
btn_idx = startup_button_indices[info["btn"]];
}
// No-op button
if(btn_idx == -1){
return;
}
eStartButton btn = static_cast<eStartButton>(btn_idx);
eKeyMod mods = static_cast<eKeyMod>(std::stoi(info["mods"]));
handle_startup_button_click(btn, mods);
return;

View File

@@ -42,7 +42,7 @@ enum_map(eStartButton, rectangle) startup_button;
void handle_startup_button_click(eStartButton btn, eKeyMod mods) {
if(recording){
std::map<std::string, std::string> info;
info["btn"] = boost::lexical_cast<std::string>(btn);
info["btn"] = startup_button_names[btn];
info["mods"] = boost::lexical_cast<std::string>(mods);
record_action("startup_button_click", info);
}