previewing dialogs, don't crash the game

This commit is contained in:
2025-02-26 21:36:09 -06:00
committed by Celtic Minstrel
parent ad43e8ab81
commit aa36b6cefb

View File

@@ -50,6 +50,7 @@ std::mt19937 cDialog::ui_rand;
extern std::map<std::string,sf::Color> colour_map; extern std::map<std::string,sf::Color> colour_map;
extern bool check_for_interrupt(std::string); extern bool check_for_interrupt(std::string);
extern void showError(std::string str1, cDialog* parent = nullptr);
std::string cDialog::generateRandomString(){ std::string cDialog::generateRandomString(){
// Not bothering to seed, because it doesn't actually matter if it's truly random. // Not bothering to seed, because it doesn't actually matter if it's truly random.
@@ -1170,8 +1171,10 @@ void cDialogIterator::increment() {
} }
void preview_dialog_xml(fs::path dialog_xml) { void preview_dialog_xml(fs::path dialog_xml) {
try{
std::unique_ptr<DialogDefn> defn(load_dialog_defn(dialog_xml)); std::unique_ptr<DialogDefn> defn(load_dialog_defn(dialog_xml));
cDialog dialog(*defn); cDialog dialog(*defn);
// Make every clickable control's click event close the dialog // Make every clickable control's click event close the dialog
for (auto control : dialog){ for (auto control : dialog){
try{ try{
@@ -1182,4 +1185,9 @@ void preview_dialog_xml(fs::path dialog_xml) {
}catch(...){} }catch(...){}
} }
dialog.run(); dialog.run();
}catch(std::exception& x) {
showError(x.what());
}catch(std::string& x){
showError(x);
}
} }