Skip to content

Commit

Permalink
Merge pull request CleverRaven#55364 from dseguin/widget_migrate_fatigue
Browse files Browse the repository at this point in the history
JSONify fatigue widget
  • Loading branch information
kevingranade authored Feb 17, 2022
2 parents 571b759 + fb34e5c commit 8e2acfe
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 10 deletions.
38 changes: 36 additions & 2 deletions data/json/ui/fatigue.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
[
{
"id": "fatigue_desc_template",
"type": "widget",
"style": "clause",
"clauses": [
{
"id": "tired",
"text": "Tired",
"color": "yellow",
"condition": {
"and": [
{ "compare_int": [ { "u_val": "fatigue" }, ">", { "const": 191 } ] },
{ "compare_int": [ { "u_val": "fatigue" }, "<=", { "const": 383 } ] }
]
}
},
{
"id": "dead_tired",
"text": "Dead Tired",
"color": "light_red",
"condition": {
"and": [
{ "compare_int": [ { "u_val": "fatigue" }, ">", { "const": 383 } ] },
{ "compare_int": [ { "u_val": "fatigue" }, "<=", { "const": 575 } ] }
]
}
},
{
"id": "exhausted",
"text": "Exhausted",
"color": "red",
"condition": { "compare_int": [ { "u_val": "fatigue" }, ">", { "const": 575 } ] }
}
]
},
{
"id": "fatigue_num",
"type": "widget",
Expand All @@ -22,7 +57,6 @@
"type": "widget",
"label": "Rest",
"style": "text",
"var": "fatigue_text",
"//": "Uses display::fatigue_text_color"
"copy-from": "fatigue_desc_template"
}
]
42 changes: 42 additions & 0 deletions data/mods/TEST_DATA/widgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,41 @@
}
]
},
{
"id": "test_fatigue_clause_template",
"type": "widget",
"style": "clause",
"clauses": [
{
"id": "tired",
"text": "Tired",
"color": "yellow",
"condition": {
"and": [
{ "compare_int": [ { "u_val": "fatigue" }, ">", { "const": 191 } ] },
{ "compare_int": [ { "u_val": "fatigue" }, "<=", { "const": 383 } ] }
]
}
},
{
"id": "dead_tired",
"text": "Dead Tired",
"color": "light_red",
"condition": {
"and": [
{ "compare_int": [ { "u_val": "fatigue" }, ">", { "const": 383 } ] },
{ "compare_int": [ { "u_val": "fatigue" }, "<=", { "const": 575 } ] }
]
}
},
{
"id": "exhausted",
"text": "Exhausted",
"color": "red",
"condition": { "compare_int": [ { "u_val": "fatigue" }, ">", { "const": 575 } ] }
}
]
},
{
"id": "test_bp_status_indicator_template",
"type": "widget",
Expand Down Expand Up @@ -954,6 +989,13 @@
"var": "weariness_level",
"style": "number"
},
{
"id": "test_fatigue_clause",
"type": "widget",
"label": "Rest",
"style": "text",
"copy-from": "test_fatigue_clause_template"
},
{
"id": "test_hp_head_graph",
"type": "widget",
Expand Down
1 change: 0 additions & 1 deletion doc/WIDGETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ Some vars refer to text descriptors. These must use style "text". Examples:
| `compass_text` | A compass direction (ex: NE), displaying visible creatures in that direction
| `date_text` | Current day within season, like "Summer, day 15"
| `env_temp_text` | Environment temperature, if thermometer is available
| `fatigue_text` | Fatigue level - "Tired", "Dead Tired", "Exhausted"
| `mood_text` | Avatar mood represented as an emoticon face
| `move_mode_letter` | Movement mode - "W": walking, "R": running, "C": crouching, "P": prone
| `move_mode_text` | Movement mode - "walking", "running", "crouching", "prone"
Expand Down
6 changes: 0 additions & 6 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ std::string enum_to_string<widget_var>( widget_var data )
return "date_text";
case widget_var::env_temp_text:
return "env_temp_text";
case widget_var::fatigue_text:
return "fatigue_text";
case widget_var::mood_text:
return "mood_text";
case widget_var::move_count_mode_text:
Expand Down Expand Up @@ -832,7 +830,6 @@ bool widget::uses_text_function()
case widget_var::compass_legend_text:
case widget_var::date_text:
case widget_var::env_temp_text:
case widget_var::fatigue_text:
case widget_var::mood_text:
case widget_var::move_count_mode_text:
case widget_var::pain_text:
Expand Down Expand Up @@ -898,9 +895,6 @@ std::string widget::color_text_function_string( const avatar &ava, unsigned int
case widget_var::env_temp_text:
desc.first = display::get_temp( ava );
break;
case widget_var::fatigue_text:
desc = display::fatigue_text_color( ava );
break;
case widget_var::mood_text:
desc = display::morale_face_color( ava );
break;
Expand Down
1 change: 0 additions & 1 deletion src/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enum class widget_var : int {
compass_legend_text, // Names of visible creatures that appear on the compass
date_text, // Current date, in terms of day within season
env_temp_text, // Environment temperature, if character has thermometer
fatigue_text, // Fagitue description text, color string
mood_text, // Mood as a text emote, color string
move_count_mode_text, // Movement counter and mode letter like "50(R)", color string
overmap_loc_text,// Local overmap position, pseudo latitude/longitude with Z-level
Expand Down
18 changes: 18 additions & 0 deletions tests/widget_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static const widget_id widget_test_compass_legend_3( "test_compass_legend_3" );
static const widget_id widget_test_compass_legend_5( "test_compass_legend_5" );
static const widget_id widget_test_dex_color_num( "test_dex_color_num" );
static const widget_id widget_test_disabled_when_empty( "test_disabled_when_empty" );
static const widget_id widget_test_fatigue_clause( "test_fatigue_clause" );
static const widget_id widget_test_focus_num( "test_focus_num" );
static const widget_id widget_test_health_clause( "test_health_clause" );
static const widget_id widget_test_health_color_num( "test_health_color_num" );
Expand Down Expand Up @@ -462,6 +463,23 @@ TEST_CASE( "widgets showing avatar stats with color for normal value", "[widget]
}
}

TEST_CASE( "widget showing character fatigue status", "[widget]" )
{
widget fatigue_w = widget_test_fatigue_clause.obj();

avatar &ava = get_avatar();
clear_avatar();

ava.set_fatigue( 0 );
CHECK( fatigue_w.layout( ava ) == "Rest: " );
ava.set_fatigue( 192 );
CHECK( fatigue_w.layout( ava ) == "Rest: <color_c_yellow>Tired</color>" );
ava.set_fatigue( 384 );
CHECK( fatigue_w.layout( ava ) == "Rest: <color_c_light_red>Dead Tired</color>" );
ava.set_fatigue( 576 );
CHECK( fatigue_w.layout( ava ) == "Rest: <color_c_red>Exhausted</color>" );
}

TEST_CASE( "widgets showing avatar health with color for normal value", "[widget][health][color]" )
{
widget health_w = widget_test_health_color_num.obj();
Expand Down

0 comments on commit 8e2acfe

Please sign in to comment.