Skip to content

Commit 4039b57

Browse files
committed
Return a simpler lambda early instead if we're in test mode
1 parent ff7b894 commit 4039b57

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/npctalk.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6405,6 +6405,25 @@ talk_effect_fun_t::func f_run_eoc_selector( const JsonObject &jo, std::string_vi
64056405
translation title = to_translation( "Select an option." );
64066406
jo.read( "title", title );
64076407

6408+
// Selector dialog can't be initialized in tests, so either cancel or activate first eoc
6409+
if( test_mode ) {
6410+
return [eocs, context, allow_cancel]( dialogue & d ) {
6411+
if( allow_cancel ) {
6412+
return;
6413+
}
6414+
6415+
dialogue newDialog( d );
6416+
if( !context.empty() ) {
6417+
for( const auto &val : context[0] ) {
6418+
newDialog.set_value( val.first, val.second.evaluate( d ) );
6419+
}
6420+
}
6421+
const effect_on_condition_id first_eoc =
6422+
eocs[0].var ? effect_on_condition_id( eocs[0].var->evaluate( d ) ) : eocs[0].id;
6423+
first_eoc->activate( newDialog );
6424+
};
6425+
}
6426+
64086427
return [eocs, context, title, eoc_names, eoc_keys, eoc_descriptions,
64096428
hide_failing, allow_cancel, hilight_disabled]( dialogue & d ) {
64106429
uilist eoc_list;
@@ -6468,21 +6487,11 @@ talk_effect_fun_t::func f_run_eoc_selector( const JsonObject &jo, std::string_vi
64686487
return;
64696488
}
64706489

6471-
if( test_mode ) {
6472-
if( eoc_list.allow_cancel ) {
6473-
eoc_list.ret = -1;
6474-
} else {
6475-
eoc_list.ret = 0;
6476-
}
6477-
} else {
6478-
eoc_list.query();
6479-
}
6480-
6490+
eoc_list.query();
64816491
if( eoc_list.ret < 0 ) {
64826492
return;
64836493
}
64846494

6485-
64866495
// add context variables
64876496
dialogue newDialog( d );
64886497
int contextIndex = 0;

0 commit comments

Comments
 (0)