Skip to content

Commit 07de00c

Browse files
authored
Merge pull request #54693 from dseguin/widget_phrase_ext
Conditional clauses for widgets
2 parents e514109 + be90bd7 commit 07de00c

File tree

13 files changed

+906
-443
lines changed

13 files changed

+906
-443
lines changed

data/json/ui/bodypart_status.json

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,90 @@
22
{
33
"id": "bodypart_status_indicator_template",
44
"type": "widget",
5-
"style": "phrase",
6-
"phrases": [
7-
{ "id": "bitten", "text": "bitten", "sym": "B", "color": "yellow" },
8-
{ "id": "infected", "text": "infected", "sym": "I", "color": "pink" },
9-
{ "id": "broken", "text": "broken", "sym": "%", "color": "magenta" },
10-
{ "id": "splinted", "text": "splinted", "sym": "=", "color": "light_gray" },
11-
{ "id": "bandaged", "text": "bandaged", "sym": "+", "color": "white" },
12-
{ "id": "disinfected", "text": "disinfected", "sym": "$", "color": "light_green" },
13-
{ "id": "bleeding", "text": "bleeding", "value": 0, "sym": "b", "color": "light_red" },
14-
{ "id": "bleeding", "text": "bleeding", "value": 11, "sym": "b", "color": "red" },
15-
{ "id": "bleeding", "text": "bleeding", "value": 21, "sym": "b", "color": "red_red" }
5+
"style": "clause",
6+
"clauses": [
7+
{ "id": "bitten", "text": "bitten", "sym": "B", "color": "yellow", "condition": { "u_has_effect": "bite" } },
8+
{
9+
"id": "infected",
10+
"text": "infected",
11+
"sym": "I",
12+
"color": "pink",
13+
"condition": { "u_has_effect": "infected" }
14+
},
15+
{
16+
"id": "broken",
17+
"text": "broken",
18+
"sym": "%",
19+
"color": "magenta",
20+
"condition": { "compare_int": [ { "u_val": "hp" }, "==", { "const": 0 } ] }
21+
},
22+
{
23+
"id": "splinted",
24+
"text": "splinted",
25+
"sym": "=",
26+
"color": "light_gray",
27+
"condition": { "u_has_worn_with_flag": "SPLINT" }
28+
},
29+
{
30+
"id": "bandaged",
31+
"text": "bandaged",
32+
"sym": "+",
33+
"color": "white",
34+
"condition": { "u_has_effect": "bandaged" }
35+
},
36+
{
37+
"id": "disinfected",
38+
"text": "disinfected",
39+
"sym": "$",
40+
"color": "light_green",
41+
"condition": { "u_has_effect": "disinfected" }
42+
},
43+
{
44+
"id": "bleeding",
45+
"text": "bleeding",
46+
"sym": "b",
47+
"color": "light_red",
48+
"condition": {
49+
"and": [
50+
{ "u_has_effect": "bleed", "intensity": 1 },
51+
{ "compare_int": [ { "u_val": "effect_intensity", "effect": "bleed" }, "<", { "const": 11 } ] }
52+
]
53+
}
54+
},
55+
{
56+
"id": "bleeding",
57+
"text": "bleeding",
58+
"sym": "b",
59+
"color": "red",
60+
"condition": {
61+
"and": [
62+
{ "u_has_effect": "bleed", "intensity": 11 },
63+
{ "compare_int": [ { "u_val": "effect_intensity", "effect": "bleed" }, "<", { "const": 21 } ] }
64+
]
65+
}
66+
},
67+
{
68+
"id": "bleeding",
69+
"text": "bleeding",
70+
"sym": "b",
71+
"color": "red_red",
72+
"condition": { "u_has_effect": "bleed", "intensity": 21 }
73+
}
1674
]
1775
},
1876
{
1977
"id": "bodypart_status_text",
2078
"//": "Base widget for showing body part status; needs bodypart field defined in derived widget.",
2179
"type": "widget",
2280
"style": "text",
23-
"var": "bp_status_text",
81+
"default_clause": { "text": "--" },
2482
"copy-from": "bodypart_status_indicator_template"
2583
},
2684
{
2785
"id": "bodypart_status_sym_text",
2886
"//": "Base widget for body part status symbols; needs bodypart field defined in derived widget.",
2987
"type": "widget",
30-
"style": "text",
31-
"var": "bp_status_sym_text",
88+
"style": "symbol",
3289
"text_align": "left",
3390
"copy-from": "bodypart_status_indicator_template"
3491
},
@@ -120,8 +177,8 @@
120177
"id": "bp_status_legend_text",
121178
"type": "widget",
122179
"label": "Status Legend",
123-
"style": "text",
124-
"var": "bp_status_legend_text",
180+
"style": "legend",
181+
"bodyparts": [ "head", "torso", "arm_l", "arm_r", "leg_l", "leg_r" ],
125182
"copy-from": "bodypart_status_indicator_template",
126183
"width": 0,
127184
"height": 3,

data/mods/TEST_DATA/widgets.json

Lines changed: 138 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,75 @@
22
{
33
"id": "test_bp_status_indicator_template",
44
"type": "widget",
5-
"style": "phrase",
6-
"phrases": [
7-
{ "id": "bitten", "text": "bitten", "sym": "B", "color": "yellow" },
8-
{ "id": "infected", "text": "infected", "sym": "I", "color": "pink" },
9-
{ "id": "broken", "text": "broken", "sym": "%", "color": "magenta" },
10-
{ "id": "splinted", "text": "splinted", "sym": "=", "color": "light_gray" },
11-
{ "id": "bandaged", "text": "bandaged", "sym": "+", "color": "white" },
12-
{ "id": "disinfected", "text": "disinfected", "sym": "$", "color": "light_green" },
13-
{ "id": "bleeding", "text": "bleeding", "value": 0, "sym": "b", "color": "light_red" },
14-
{ "id": "bleeding", "text": "bleeding", "value": 11, "sym": "b", "color": "red" },
15-
{ "id": "bleeding", "text": "bleeding", "value": 21, "sym": "b", "color": "red_red" }
5+
"style": "clause",
6+
"clauses": [
7+
{ "id": "bitten", "text": "bitten", "sym": "B", "color": "yellow", "condition": { "u_has_effect": "bite" } },
8+
{
9+
"id": "infected",
10+
"text": "infected",
11+
"sym": "I",
12+
"color": "pink",
13+
"condition": { "u_has_effect": "infected" }
14+
},
15+
{
16+
"id": "broken",
17+
"text": "broken",
18+
"sym": "%",
19+
"color": "magenta",
20+
"condition": { "compare_int": [ { "u_val": "hp" }, "==", { "const": 0 } ] }
21+
},
22+
{
23+
"id": "splinted",
24+
"text": "splinted",
25+
"sym": "=",
26+
"color": "light_gray",
27+
"condition": { "u_has_worn_with_flag": "SPLINT" }
28+
},
29+
{
30+
"id": "bandaged",
31+
"text": "bandaged",
32+
"sym": "+",
33+
"color": "white",
34+
"condition": { "u_has_effect": "bandaged" }
35+
},
36+
{
37+
"id": "disinfected",
38+
"text": "disinfected",
39+
"sym": "$",
40+
"color": "light_green",
41+
"condition": { "u_has_effect": "disinfected" }
42+
},
43+
{
44+
"id": "bleeding",
45+
"text": "bleeding",
46+
"sym": "b",
47+
"color": "light_red",
48+
"condition": {
49+
"and": [
50+
{ "u_has_effect": "bleed", "intensity": 1 },
51+
{ "compare_int": [ { "u_val": "effect_intensity", "effect": "bleed" }, "<", { "const": 11 } ] }
52+
]
53+
}
54+
},
55+
{
56+
"id": "bleeding",
57+
"text": "bleeding",
58+
"sym": "b",
59+
"color": "red",
60+
"condition": {
61+
"and": [
62+
{ "u_has_effect": "bleed", "intensity": 11 },
63+
{ "compare_int": [ { "u_val": "effect_intensity", "effect": "bleed" }, "<", { "const": 21 } ] }
64+
]
65+
}
66+
},
67+
{
68+
"id": "bleeding",
69+
"text": "bleeding",
70+
"sym": "b",
71+
"color": "red_red",
72+
"condition": { "u_has_effect": "bleed", "intensity": 21 }
73+
}
1674
]
1775
},
1876
{
@@ -122,6 +180,7 @@
122180
"type": "widget",
123181
"style": "text",
124182
"var": "compass_legend_text",
183+
"width": 0,
125184
"text_align": "left",
126185
"flags": [ "W_DYNAMIC_HEIGHT" ]
127186
},
@@ -131,6 +190,7 @@
131190
"style": "text",
132191
"var": "compass_legend_text",
133192
"height": 3,
193+
"width": 0,
134194
"text_align": "left",
135195
"flags": [ "W_DYNAMIC_HEIGHT" ]
136196
},
@@ -140,6 +200,7 @@
140200
"style": "text",
141201
"var": "compass_legend_text",
142202
"height": 5,
203+
"width": 0,
143204
"text_align": "left",
144205
"flags": [ "W_DYNAMIC_HEIGHT" ]
145206
},
@@ -347,34 +408,32 @@
347408
"id": "test_status_torso_text",
348409
"type": "widget",
349410
"label": "TORSO STATUS",
350-
"var": "bp_status_text",
351411
"bodypart": "torso",
352412
"style": "text",
413+
"default_clause": { "text": "--" },
353414
"copy-from": "test_bp_status_indicator_template"
354415
},
355416
{
356417
"id": "test_status_left_arm_text",
357418
"type": "widget",
358419
"label": "LEFT ARM STATUS",
359-
"var": "bp_status_text",
360420
"bodypart": "arm_l",
361421
"style": "text",
422+
"default_clause": { "text": "--" },
362423
"copy-from": "test_bp_status_indicator_template"
363424
},
364425
{
365426
"id": "test_status_sym_torso_text",
366427
"type": "widget",
367-
"style": "text",
368-
"var": "bp_status_sym_text",
428+
"style": "symbol",
369429
"label": "TORSO",
370430
"bodypart": "torso",
371431
"copy-from": "test_bp_status_indicator_template"
372432
},
373433
{
374434
"id": "test_status_sym_left_arm_text",
375435
"type": "widget",
376-
"style": "text",
377-
"var": "bp_status_sym_text",
436+
"style": "symbol",
378437
"label": "L ARM",
379438
"bodypart": "arm_l",
380439
"copy-from": "test_bp_status_indicator_template"
@@ -383,8 +442,8 @@
383442
"id": "test_status_legend_text",
384443
"type": "widget",
385444
"label": "Status Legend",
386-
"style": "text",
387-
"var": "bp_status_legend_text",
445+
"style": "legend",
446+
"bodyparts": [ "head", "torso", "arm_l", "arm_r", "leg_l", "leg_r" ],
388447
"copy-from": "test_bp_status_indicator_template",
389448
"width": 0,
390449
"height": 3,
@@ -407,6 +466,65 @@
407466
"width": 3,
408467
"height": 3
409468
},
469+
{
470+
"id": "test_clause_number",
471+
"type": "widget",
472+
"style": "number",
473+
"label": "Num Values",
474+
"default_clause": { "value": 1, "color": "dark_gray" },
475+
"clauses": [
476+
{ "value": -20, "color": "red_red", "condition": { "not": "u_can_see" } },
477+
{ "value": -10, "color": "i_yellow", "condition": "u_is_deaf" },
478+
{ "value": 0, "color": "yellow", "condition": "is_day" },
479+
{ "value": 10, "color": "white_green", "condition": { "u_has_trait": "GOODHEARING" } },
480+
{ "value": 20, "color": "light_green", "condition": { "u_has_trait": "NIGHTVISION" } }
481+
]
482+
},
483+
{
484+
"id": "test_clause_text",
485+
"type": "widget",
486+
"style": "text",
487+
"label": "Text Values",
488+
"default_clause": { "text": "None", "color": "dark_gray" },
489+
"clauses": [
490+
{ "text": "blind", "color": "red_red", "condition": { "not": "u_can_see" } },
491+
{ "text": "deaf", "color": "i_yellow", "condition": "u_is_deaf" },
492+
{ "text": "daylight", "color": "yellow", "condition": "is_day" },
493+
{ "text": "good hearing", "color": "white_green", "condition": { "u_has_trait": "GOODHEARING" } },
494+
{ "text": "good vision", "color": "light_green", "condition": { "u_has_trait": "NIGHTVISION" } }
495+
]
496+
},
497+
{
498+
"id": "test_clause_sym",
499+
"type": "widget",
500+
"style": "symbol",
501+
"label": "Symbol Values",
502+
"default_clause": { "sym": ".", "color": "dark_gray" },
503+
"clauses": [
504+
{ "sym": "<", "color": "red_red", "condition": { "not": "u_can_see" } },
505+
{ "sym": "-", "color": "i_yellow", "condition": "u_is_deaf" },
506+
{ "sym": "=", "color": "yellow", "condition": "is_day" },
507+
{ "sym": "+", "color": "white_green", "condition": { "u_has_trait": "GOODHEARING" } },
508+
{ "sym": ">", "color": "light_green", "condition": { "u_has_trait": "NIGHTVISION" } }
509+
]
510+
},
511+
{
512+
"id": "test_clause_legend",
513+
"type": "widget",
514+
"style": "legend",
515+
"label": "Legend Values",
516+
"height": 5,
517+
"width": 0,
518+
"default_clause": { "text": "None", "sym": ".", "color": "dark_gray" },
519+
"clauses": [
520+
{ "text": "blind", "sym": "<", "color": "red_red", "condition": { "not": "u_can_see" } },
521+
{ "text": "deaf", "sym": "-", "color": "i_yellow", "condition": "u_is_deaf" },
522+
{ "text": "daylight", "sym": "=", "color": "yellow", "condition": "is_day" },
523+
{ "text": "good hearing", "sym": "+", "color": "white_green", "condition": { "u_has_trait": "GOODHEARING" } },
524+
{ "text": "good vision", "sym": ">", "color": "light_green", "condition": { "u_has_trait": "NIGHTVISION" } }
525+
],
526+
"flags": [ "W_LABEL_NONE", "W_DYNAMIC_HEIGHT" ]
527+
},
410528
{
411529
"id": "test_stat_panel",
412530
"type": "widget",
@@ -438,7 +556,7 @@
438556
{
439557
"id": "test_text_widget",
440558
"type": "widget",
441-
"label": "PHRASE",
559+
"label": "CLAUSE",
442560
"style": "text",
443561
"strings": [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" ]
444562
},

0 commit comments

Comments
 (0)