Debug action: crash the game

This commit is contained in:
2025-03-06 19:24:41 -06:00
committed by Celtic Minstrel
parent 4cc6d7efb9
commit 14c36ed5a8
5 changed files with 31 additions and 1 deletions

View File

@@ -66,6 +66,8 @@ cKey charToKey(char ch) {
return {false, w('/'), mod_shift};
case '~':
return {false, w('`'), mod_shift};
case '\\':
return {false, w('\\'), mod_none};
}
throw std::string {"Tried to convert unsupported char '"} + ch + "' to cKey!";
}

View File

@@ -2456,7 +2456,7 @@ void debug_launch_scen(std::string scen_name) {
}
// Non-comprehensive list of unused keys:
// chjklnoqvy -_+[]{},.'"`\|;:
// chjklnoqvy -_+[]{},.'"`|;:
// We want to keep lower-case for normal gameplay.
void init_debug_actions() {
// optional `true` argument means you can use this action in the startup menu.
@@ -2507,6 +2507,7 @@ void init_debug_actions() {
add_debug_action({'^'}, "Fight special encounter from this section", []() {debug_fight_encounter(false);});
add_debug_action({'/', '?'}, "Bring up this window", show_debug_help, true);
add_debug_action({'Z'}, "Save the current action log for bug reporting", save_replay_log, true);
add_debug_action({'\\'}, "Crash the game", debug_crash, true);
}
// Later we might want to know whether the key is used or not
@@ -4066,6 +4067,18 @@ void save_replay_log(){
start_log_file(out_file.string());
}
void debug_crash() {
// If they don't confirm, the game can continue normally, and we'll need to replay
// that the confirmation opened and closed.
if(recording){
record_action("debug_crash", "");
}
std::string confirm = cChoiceDlog("debug-crash-confirm",{"yes","no"}).show();
if(confirm == "yes"){
throw std::string { "Be careful what you wish for!" };
}
}
void clear_trapped_monst() {
if(recording){
record_action("clear_trapped_monst", "");

View File

@@ -120,6 +120,7 @@ void easter_egg(int idx);
void preview_dialog_xml();
void preview_every_dialog_xml();
void save_replay_log();
void debug_crash();
void clear_trapped_monst();
#endif

View File

@@ -954,6 +954,8 @@ static void replay_action(Element& action) {
clear_trapped_monst();
}else if(t == "error"){
// The error is recorded for debugging only. It should be triggered by replaying the actions.
}else if(t == "debug_crash"){
debug_crash();
}else if(t == "advance_time"){
// This is bad regardless of strictness, because visual changes may have occurred which won't get redrawn/reprinted
throw std::string { "Replay system internal error! advance_time() was supposed to be called by the last action, but wasn't: " } + _last_action_type;