Skip to content

Commit

Permalink
[EoC] Parse tags of run_eoc_selector (CleverRaven#69602)
Browse files Browse the repository at this point in the history
* parse run_eoc_selector

* fix

* update

* update sample
  • Loading branch information
lispcoc authored Nov 22, 2023
1 parent dc23b79 commit a23d68a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions data/json/effects_on_condition/example_eocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
"type": "effect_on_condition",
"id": "EOC_selector_test",
"effect": [
{ "set_string_var": "EOC Selector Test", "target_var": { "context_val": "title" } },
{ "set_string_var": "name_3", "target_var": { "context_val": "name" } },
{ "set_string_var": "option 3", "target_var": { "context_val": "description" } },
{
"run_eoc_selector": [ "EOC_selector_test_1", "EOC_selector_test_2", "EOC_selector_test_3", "EOC_selector_test_4" ],
"names": [ "name_1", "name_2", "name_3", "should_fail" ],
"names": [ "name_1", "name_2", "<context_val:name>", "should_fail" ],
"keys": [ "a", "b", "c", "d" ],
"descriptions": [ "option 1", "option 2", "option 3", "should not be available" ],
"descriptions": [ "option 1", "option 2", "<context_val:description>", "should not be available" ],
"variables": [ { "val": "8" } ],
"title": "<context_val:title>",
"allow_cancel": true
}
]
Expand Down
20 changes: 16 additions & 4 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4648,9 +4648,15 @@ void talk_effect_fun_t::set_run_eoc_selector( const JsonObject &jo, std::string_
hide_failing, allow_cancel]( dialogue & d ) {
uilist eoc_list;

std::unique_ptr<talker> default_talker = get_talker_for( get_player_character() );
talker &alpha = d.has_alpha ? *d.actor( false ) : *default_talker;
talker &beta = d.has_beta ? *d.actor( true ) : *default_talker;


eoc_list.text = title;
eoc_list.allow_cancel = allow_cancel;
eoc_list.desc_enabled = !eoc_descriptions.empty();
parse_tags( eoc_list.text, alpha, beta, d );

for( size_t i = 0; i < eocs.size(); i++ ) {
effect_on_condition_id eoc_id = effect_on_condition_id( eocs[i].evaluate( d ) );
Expand All @@ -4669,17 +4675,23 @@ void talk_effect_fun_t::set_run_eoc_selector( const JsonObject &jo, std::string_
continue;
}

std::string name;
std::string description;
if( eoc_names.empty() ) {
name = eoc_id.str();
} else {
name = eoc_names[i].evaluate( d );
parse_tags( name, alpha, beta, d );
}
if( !eoc_descriptions.empty() ) {
description = eoc_descriptions[i].evaluate( d );
parse_tags( description, alpha, beta, d );
}

if( eoc_keys.empty() ) {
eoc_list.entries.emplace_back( static_cast<int>( i ), display, std::nullopt,
( eoc_names.empty() ? eoc_id.str() : eoc_names[i].evaluate( d ) ), description );
eoc_list.entries.emplace_back( static_cast<int>( i ), display, std::nullopt, name, description );
} else {
eoc_list.entries.emplace_back( static_cast<int>( i ), display, eoc_keys[i],
( eoc_names.empty() ? eoc_id.str() : eoc_names[i].evaluate( d ) ), description );
eoc_list.entries.emplace_back( static_cast<int>( i ), display, eoc_keys[i], name, description );
}
}

Expand Down

0 comments on commit a23d68a

Please sign in to comment.