Skip to content

Commit

Permalink
fix: Sort body parts in Character::get_all_body_parts (#5835)
Browse files Browse the repository at this point in the history
Sort body parts in Character::get_all_body_parts
  • Loading branch information
Coolthulhu authored Dec 27, 2024
1 parent 4f44eeb commit 099aeff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion data/json/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"accusative": { "ctxt": "bodypart_accusative", "str": "appendix" },
"heading": "appendix",
"heading_multiple": "Appendices",
"encumbrance_text": "It's inflamed."
"encumbrance_text": "It's inflamed.",
"sort_order": -1000
},
{
"id": "torso",
Expand All @@ -18,6 +19,7 @@
"heading": "Torso",
"hp_bar_ui_text": "TORSO",
"encumbrance_text": "Dodging and melee is hampered.",
"sort_order": 100,
"essential": true,
"hit_size": 45,
"hit_size_relative": [ 20, 33.33, 36.57 ],
Expand All @@ -37,6 +39,7 @@
"accusative": { "ctxt": "bodypart_accusative", "str": "head" },
"heading": "Head",
"hp_bar_ui_text": "HEAD",
"sort_order": 0,
"essential": true,
"hit_size": 6,
"hit_size_relative": [ 0, 2.33, 5.71 ],
Expand All @@ -56,6 +59,7 @@
"accusative": { "ctxt": "bodypart_accusative", "str": "eyes" },
"heading": "Eyes",
"encumbrance_text": "Ranged combat is hampered.",
"sort_order": 10,
"main_part": "head",
"hit_size": 1,
"hit_size_relative": [ 0, 0.33, 0.57 ],
Expand All @@ -73,6 +77,7 @@
"accusative": { "ctxt": "bodypart_accusative", "str": "mouth" },
"heading": "Mouth",
"encumbrance_text": "Stamina regeneration is slowed.",
"sort_order": 20,
"main_part": "head",
"hit_size": 1,
"hit_difficulty": 1.15,
Expand All @@ -94,6 +99,7 @@
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "arms" },
"heading": "L. Arm",
"heading_multiple": "Arms",
"sort_order": 200,
"encumbrance_text": "Melee and ranged combat is hampered.",
"hp_bar_ui_text": "L ARM",
"opposite_part": "arm_r",
Expand All @@ -117,6 +123,7 @@
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "arms" },
"heading": "R. Arm",
"heading_multiple": "Arms",
"sort_order": 300,
"hp_bar_ui_text": "R ARM",
"encumbrance_text": "Melee and ranged combat is hampered.",
"opposite_part": "arm_l",
Expand All @@ -140,6 +147,7 @@
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "hands" },
"heading": "L. Hand",
"heading_multiple": "Hands",
"sort_order": 250,
"encumbrance_text": "Manual tasks are slowed.",
"main_part": "arm_l",
"opposite_part": "hand_r",
Expand All @@ -163,6 +171,7 @@
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "hands" },
"heading": "R. Hand",
"heading_multiple": "Hands",
"sort_order": 350,
"encumbrance_text": "Manual tasks are slowed.",
"main_part": "arm_r",
"opposite_part": "hand_l",
Expand All @@ -187,6 +196,7 @@
"heading": "L. Leg",
"heading_multiple": "Legs",
"hp_bar_ui_text": "L LEG",
"sort_order": 500,
"encumbrance_text": "Running and swimming are slowed.",
"opposite_part": "leg_r",
"hit_size": 9,
Expand All @@ -211,6 +221,7 @@
"heading": "R. Leg",
"heading_multiple": "Legs",
"hp_bar_ui_text": "R LEG",
"sort_order": 600,
"encumbrance_text": "Running and swimming are slowed.",
"opposite_part": "leg_l",
"hit_size": 9,
Expand All @@ -234,6 +245,7 @@
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "feet" },
"heading": "L. Foot",
"heading_multiple": "Feet",
"sort_order": 550,
"encumbrance_text": "Running is slowed.",
"main_part": "leg_l",
"opposite_part": "foot_r",
Expand All @@ -257,6 +269,7 @@
"accusative_multiple": { "ctxt": "bodypart_accusative", "str": "feet" },
"heading": "R. Foot",
"heading_multiple": "Feet",
"sort_order": 650,
"encumbrance_text": "Running is slowed.",
"main_part": "leg_r",
"opposite_part": "foot_l",
Expand Down
2 changes: 2 additions & 0 deletions src/bodypart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ void body_part_type::load( const JsonObject &jo, const std::string & )
optional( jo, was_loaded, "hp_bar_ui_text", hp_bar_ui_text );
optional( jo, was_loaded, "encumbrance_text", encumb_text );

mandatory( jo, was_loaded, "sort_order", sort_order );

assign( jo, "hit_size", hit_size, true );
assign( jo, "hit_difficulty", hit_difficulty, true );
assign( jo, "hit_size_relative", hit_size_relative, true );
Expand Down
2 changes: 2 additions & 0 deletions src/bodypart.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ struct body_part_type {
bodypart_str_id id;
bool was_loaded = false;

int sort_order = 0;

// Those are stored untranslated
translation name;
translation name_multiple;
Expand Down
4 changes: 4 additions & 0 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,10 @@ std::vector<bodypart_id> Creature::get_all_body_parts( bool only_main ) const
all_bps.emplace_back( elem.first );
}

std::sort( all_bps.begin(), all_bps.end(),
[]( const bodypart_id & lhs, const bodypart_id & rhs ) {
return lhs->sort_order < rhs->sort_order;
} );
return all_bps;
}

Expand Down

0 comments on commit 099aeff

Please sign in to comment.