From 099aeff3198cd52196134591cc31c268dfe5ea72 Mon Sep 17 00:00:00 2001 From: Coolthulhu Date: Fri, 27 Dec 2024 01:15:03 +0100 Subject: [PATCH] fix: Sort body parts in Character::get_all_body_parts (#5835) Sort body parts in Character::get_all_body_parts --- data/json/body_parts.json | 15 ++++++++++++++- src/bodypart.cpp | 2 ++ src/bodypart.h | 2 ++ src/creature.cpp | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/data/json/body_parts.json b/data/json/body_parts.json index fe85f600cb07..6d8c9de89f7a 100644 --- a/data/json/body_parts.json +++ b/data/json/body_parts.json @@ -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", @@ -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 ], @@ -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 ], @@ -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 ], @@ -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, @@ -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", @@ -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", @@ -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", @@ -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", @@ -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, @@ -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, @@ -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", @@ -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", diff --git a/src/bodypart.cpp b/src/bodypart.cpp index d33f47e781fd..dfce68ebc46b 100644 --- a/src/bodypart.cpp +++ b/src/bodypart.cpp @@ -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 ); diff --git a/src/bodypart.h b/src/bodypart.h index 52a17874a920..748427890e97 100644 --- a/src/bodypart.h +++ b/src/bodypart.h @@ -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; diff --git a/src/creature.cpp b/src/creature.cpp index 2623c073312a..e0615c6dc796 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -1835,6 +1835,10 @@ std::vector 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; }