Skip to content

Commit

Permalink
Use priority value to chose between multiple end screens with valid c…
Browse files Browse the repository at this point in the history
…onditions
  • Loading branch information
Fris0uman committed Jul 5, 2024
1 parent a49db66 commit b9b5c72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
26 changes: 13 additions & 13 deletions data/json/ascii_art/graveyard.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
" > _ _ (",
" | |_) | |_) |",
" | | \\ | | |",
" ______.__%_| |________ __",
" ______.__<color_green>%</color>_| |________ __",
" _/ \\| |",
"| <",
"| |",
Expand All @@ -20,11 +20,11 @@
" | |",
" | _ |",
" |__/ |",
" % / `--. |%",
" * .%%| -< @%%%",
" `\\%`@| |@@%@%%",
" .%%%@@@|% ` % @@@%%@%%%%",
" _.%%%%%%@@@@@@%%%__/\\%@@%%@@@@@@@%%%%%%"
" <color_green>%</color> / `--. |<color_green>%</color>",
" <color_red>*</color> .<color_green>%%</color>| -< <color_brown>@</color><color_green>%%%</color>",
" `\\<color_green>%</color>`<color_brown>@</color>| |<color_brown>@@</color><color_green>%</color><color_brown>@</color><color_green>%%</color>",
" .<color_green>%%%</color><color_brown>@@@</color>|<color_green>%</color> ` <color_green>%</color> <color_brown>@@@</color><color_green>%%</color><color_brown>@</color><color_green>%%%%</color>",
" _.<color_green>%%%%%%</color><color_brown>@@@@@@</color><color_green>%%%</color>__/\\<color_green>%</color><color_brown>@@</color><color_green>%%</color><color_brown>@@@@@@@</color><color_green>%%%%%%</color>"
]
},
{
Expand All @@ -34,8 +34,8 @@
" _________ ____ ",
" _/ `/ \\_ ",
" _/ _ _ \\_. ",
" _%\\ |_) | |_) \\_ ",
" _/ \/ | \\ | | \\_ ",
" _<color_green>%</color>\\ |_) | |_) \\_ ",
" _/ \\/ | \\ | | \\_ ",
" _/ \\_ ",
"| |",
" ) < ",
Expand All @@ -47,11 +47,11 @@
"| ( ",
"| |",
"| |",
"| % . |",
"| @` %% |",
"| %@%@%\\ * %`%@%|",
"%%@@@.%@%\\%% `\\ %%.%%@@%@",
"@%@@%%%%%@@@@@@%%%%%%%%@@%%@@@%%%@%%@"
"| <color_green>%</color> . |",
"| <color_brown>@</color>` <color_green>%%</color> |",
"| <color_green>%</color><color_brown>@</color><color_green>%</color><color_brown>@</color><color_green>%</color>\\ <color_red>*</color> <color_green>%</color>`<color_green>%</color><color_brown>@</color><color_green>%</color>|",
"<color_green>%%</color><color_brown>@@@</color>.<color_green>%</color><color_brown>@</color><color_green>%</color>\\<color_green>%%</color> `\\ <color_green>%%</color>.<color_green>%%</color><color_brown>@@</color><color_green>%</color><color_brown>@</color>",
"<color_brown>@</color><color_green>%</color><color_brown>@@</color><color_green>%%%%%</color><color_brown>@@@@@@</color><color_green>%%%%%%%%</color><color_brown>@@</color><color_green>%%</color><color_brown>@@@</color><color_green>%%%</color><color_brown>@</color><color_green>%%</color><color_brown>@</color>"
]
}
]
1 change: 1 addition & 0 deletions src/end_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void end_screen::load( const JsonObject &jo, std::string_view )
{
mandatory( jo, was_loaded, "id", id );
mandatory( jo, was_loaded, "picture_id", picture_id );
mandatory( jo, was_loaded, "priority", priority );
read_condition( jo, "condition", condition, false );

optional( jo, was_loaded, "added_info", added_info );
Expand Down
1 change: 1 addition & 0 deletions src/end_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class end_screen
end_screen_id id;
ascii_art_id picture_id;
std::function<bool( dialogue & )> condition;
int priority;
std::vector<std::pair<std::pair<int, int>, std::string>> added_info;
std::string last_words_label;
};
Expand Down
11 changes: 10 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2846,7 +2846,15 @@ void end_screen_ui_impl::draw_controls()
dialogue d( get_talker_for( u ), nullptr );
std::string input_label;
std::vector<std::pair<std::pair<int, int>, std::string>> added_info;
for( const end_screen &e_screen : end_screen::get_all() ) {

//Sort end_screens in order of decreasing priority
std::vector<end_screen> sorted_screens = end_screen::get_all();
std::sort( sorted_screens.begin(), sorted_screens.end(), []( end_screen const & a,
end_screen const & b ) {
return a.priority > b.priority;
} );

for( const end_screen &e_screen : sorted_screens ) {
if( e_screen.condition( d ) ) {
art = e_screen.picture_id;
if( !e_screen.added_info.empty() ) {
Expand All @@ -2855,6 +2863,7 @@ void end_screen_ui_impl::draw_controls()
if( !e_screen.last_words_label.empty() ) {
input_label = e_screen.last_words_label;
}
break;
}
}

Expand Down

0 comments on commit b9b5c72

Please sign in to comment.