From b050a7634d3b0b24459dc322f9223555572b7ab8 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Thu, 22 Jan 2026 20:20:21 +0100 Subject: [PATCH] Reformat --- Unit testing/billy_objects_tests.cpp | 16 +++-- Unit testing/characteristics_tests.cpp | 24 +++---- include/billy_objects.hpp | 12 ++-- include/character_sheet.hpp | 14 ++-- include/characteristic.hpp | 29 ++++---- include/generic_object.hpp | 26 +++---- src/billy_objects.cpp | 94 ++++++++++++++------------ src/generic_object.cpp | 2 +- 8 files changed, 113 insertions(+), 104 deletions(-) diff --git a/Unit testing/billy_objects_tests.cpp b/Unit testing/billy_objects_tests.cpp index afeb14d..3270a11 100644 --- a/Unit testing/billy_objects_tests.cpp +++ b/Unit testing/billy_objects_tests.cpp @@ -23,11 +23,17 @@ namespace character::test { static std::unique_ptr get_obj(const billyEnums &object) noexcept { return std::visit(overloaded{ - [](const weapons &arg) { return std::unique_ptr(std::make_unique(arg)); }, - [](const equipments &arg) { return std::unique_ptr(std::make_unique(arg)); }, - [](const tools &arg) { return std::unique_ptr(std::make_unique(arg)); }, - }, - object); + [](const weapons &arg) { + return std::unique_ptr(std::make_unique(arg)); + }, + [](const equipments &arg) { + return std::unique_ptr(std::make_unique(arg)); + }, + [](const tools &arg) { + return std::unique_ptr(std::make_unique(arg)); + }, + }, + object); } } diff --git a/Unit testing/characteristics_tests.cpp b/Unit testing/characteristics_tests.cpp index 9888369..fb6bc62 100644 --- a/Unit testing/characteristics_tests.cpp +++ b/Unit testing/characteristics_tests.cpp @@ -16,9 +16,7 @@ TEST_CASE("[A] Serialize adresse", "[serialize][0]") { REQUIRE_NOTHROW(tester.at("base") == 1); REQUIRE_NOTHROW(tester.at("carac") == 0); REQUIRE_NOTHROW(tester.at("materiel") == 0); - REQUIRE_NOTHROW(tester.at("additional") == 0); - - { + REQUIRE_NOTHROW(tester.at("additional") == 0); { std::ofstream file{ "adresse.json" }; file << serializer << std::flush; } @@ -35,9 +33,7 @@ TEST_CASE("[A] Serialize chance", "[serialize][1]") { REQUIRE_NOTHROW(tester.at("base") == 3); REQUIRE_NOTHROW(tester.at("carac") == 0); REQUIRE_NOTHROW(tester.at("materiel") == 0); - REQUIRE_NOTHROW(tester.at("additional") == 0); - - { + REQUIRE_NOTHROW(tester.at("additional") == 0); { std::ofstream file{ "chance.json" }; file << serializer << std::flush; } @@ -54,9 +50,7 @@ TEST_CASE("[A] Serialize endurance", "[serialize][2]") { REQUIRE_NOTHROW(tester.at("base") == 2); REQUIRE_NOTHROW(tester.at("carac") == 0); REQUIRE_NOTHROW(tester.at("materiel") == 0); - REQUIRE_NOTHROW(tester.at("additional") == 0); - - { + REQUIRE_NOTHROW(tester.at("additional") == 0); { std::ofstream file{ "endurance.json" }; file << serializer << std::flush; } @@ -73,9 +67,7 @@ TEST_CASE("[A] Serialize habilete", "[serialize][3]") { REQUIRE_NOTHROW(tester.at("base") == 2); REQUIRE_NOTHROW(tester.at("carac") == 0); REQUIRE_NOTHROW(tester.at("materiel") == 0); - REQUIRE_NOTHROW(tester.at("additional") == 0); - - { + REQUIRE_NOTHROW(tester.at("additional") == 0); { std::ofstream file{ "habilete.json" }; file << serializer << std::flush; } @@ -93,7 +85,7 @@ TEST_CASE("[B] Deserialize adresse", "[deserialize][0]") { REQUIRE(adresse.get_carac() == 0); REQUIRE(adresse.get_materiel() == 0); REQUIRE(adresse.get_additional() == 0); - }()); + }()); } TEST_CASE("[B] Deserialize chance", "[deserialize][1]") { @@ -108,7 +100,7 @@ TEST_CASE("[B] Deserialize chance", "[deserialize][1]") { REQUIRE(adresse.get_carac() == 0); REQUIRE(adresse.get_materiel() == 0); REQUIRE(adresse.get_additional() == 0); - }()); + }()); } TEST_CASE("[B] Deserialize endurance", "[deserialize][2]") { @@ -123,7 +115,7 @@ TEST_CASE("[B] Deserialize endurance", "[deserialize][2]") { REQUIRE(adresse.get_carac() == 0); REQUIRE(adresse.get_materiel() == 0); REQUIRE(adresse.get_additional() == 0); - }()); + }()); } TEST_CASE("[B] Deserialize habilete", "[deserialize][3]") { @@ -138,5 +130,5 @@ TEST_CASE("[B] Deserialize habilete", "[deserialize][3]") { REQUIRE(adresse.get_carac() == 0); REQUIRE(adresse.get_materiel() == 0); REQUIRE(adresse.get_additional() == 0); - }()); + }()); } diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index c675a52..5b2a025 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -66,12 +66,12 @@ namespace character { std::minus minus; static void change_carac(const billyObjects &arg, - CharacterSheet &sheet, - characteristic::Characteristic &localHabilete, - characteristic::Characteristic &localAdresse, - characteristic::Characteristic &localEndurance, - characteristic::Characteristic &localChance, - const std::function &operation) noexcept; + CharacterSheet &sheet, + characteristic::Characteristic &localHabilete, + characteristic::Characteristic &localAdresse, + characteristic::Characteristic &localEndurance, + characteristic::Characteristic &localChance, + const std::function &operation) noexcept; }; } diff --git a/include/character_sheet.hpp b/include/character_sheet.hpp index c9ec58a..09f710a 100644 --- a/include/character_sheet.hpp +++ b/include/character_sheet.hpp @@ -7,15 +7,14 @@ namespace character { enum class classe : std::uint8_t { - Guerrier = 0, - Prudent = 1, - Paysan = 2, + Guerrier = 0, + Prudent = 1, + Paysan = 2, Debrouillard = 3, }; class CharacterSheet final { private: - friend BillyObjects; std::string caractere{}; @@ -33,8 +32,8 @@ namespace character { BillyObjects::container objects; std::unordered_set available_objects{ - BillyObjects::all_objects.cbegin(), - BillyObjects::all_objects.cend() + BillyObjects::all_objects.cbegin(), + BillyObjects::all_objects.cend() }; std::uint32_t health_point{ 0 }; @@ -54,6 +53,7 @@ namespace character { std::uint32_t nb_equipments{ 0 }; std::uint32_t nb_tools{ 0 }; + public: CharacterSheet() = default; @@ -146,4 +146,4 @@ namespace character { } -#endif //BILLYSHEET_CHARACTER_SHEET_HPP +#endif //BILLYSHEET_CHARACTER_SHEET_HPP \ No newline at end of file diff --git a/include/characteristic.hpp b/include/characteristic.hpp index 11d6a27..65a208d 100644 --- a/include/characteristic.hpp +++ b/include/characteristic.hpp @@ -1,6 +1,7 @@ #ifndef BILLYSHEET_CHARACTERISTIC_HPP #define BILLYSHEET_CHARACTERISTIC_HPP +#include #include #include @@ -12,10 +13,10 @@ namespace character { namespace character::characteristic { enum class characType : std::uint8_t { - Adresse = 0, + Adresse = 0, Endurance = 1, - Chance = 2, - Habilete = 3 + Chance = 2, + Habilete = 3 }; class Characteristic { @@ -46,14 +47,14 @@ namespace character::characteristic { Characteristic() noexcept = default; Characteristic(const characType inType, - const std::uint32_t carac, - const std::uint32_t materiel, - const std::uint32_t additional) : - base(get_base(inType)), - carac(carac), - materiel(materiel), - additional(additional), - type(inType) { (void) get_total(); } + const std::uint32_t carac, + const std::uint32_t materiel, + const std::uint32_t additional) : + base(get_base(inType)), + carac(carac), + materiel(materiel), + additional(additional), + type(inType) { (void) get_total(); } explicit Characteristic(const characType inType) : Characteristic(inType, 0, 0, 0) {} @@ -82,9 +83,7 @@ namespace character::characteristic { [[nodiscard]] std::size_t get_total() const noexcept { if (total == defaultValue::max()) { total = static_cast(base + carac + materiel + additional); - if (total < 0) { - total = 0; - } + total = std::max(total, 0); } return total; } @@ -110,4 +109,4 @@ namespace character::characteristic { } -#endif //BILLYSHEET_CHARACTERISTIC_HPP +#endif //BILLYSHEET_CHARACTERISTIC_HPP \ No newline at end of file diff --git a/include/generic_object.hpp b/include/generic_object.hpp index 56d5fb0..72c0353 100644 --- a/include/generic_object.hpp +++ b/include/generic_object.hpp @@ -12,7 +12,10 @@ // helper type for the visitor template -struct overloaded : Ts ... { using Ts::operator()...; }; +struct overloaded : Ts... { + using Ts::operator()...; +}; + template overloaded(Ts...) -> overloaded; @@ -24,24 +27,24 @@ namespace character { using namespace std::string_literals; enum class weapons : std::uint8_t { - Sword = 0, - Lance = 1, + Sword = 0, + Lance = 1, Morgenstern = 2, - Bow = 3 + Bow = 3 }; enum class equipments : std::uint8_t { - Chainmail = 4, - CookingPot = 5, + Chainmail = 4, + CookingPot = 5, PamphletTourist = 6, - MedicKit = 7 + MedicKit = 7 }; enum class tools : std::uint8_t { - Fourche = 8, - Dagger = 9, + Fourche = 8, + Dagger = 9, RockClimbingKit = 10, - SackOfGrain = 11 + SackOfGrain = 11 }; class Weapons; @@ -139,7 +142,6 @@ namespace character { [[nodiscard]] billyEnums get_type() const noexcept final { return type; } }; - } // character -#endif //BILLYSHEET_GENERIC_OBJECT_HPP +#endif //BILLYSHEET_GENERIC_OBJECT_HPP \ No newline at end of file diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index e737294..3c3b3b1 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -1,6 +1,7 @@ #include "billy_objects.hpp" #include "characteristic.hpp" #include "character_sheet.hpp" + #include constexpr std::uint32_t const_hash(const char *input) { @@ -18,16 +19,24 @@ namespace character { bool BillyObjects::insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept { if (sheet.objects.size() < 3) { sheet.objects.emplace(objType, - std::visit(overloaded{ - [](const weapons &arg) { - return std::unique_ptr(std::make_unique(arg)); - }, - [](const equipments &arg) { - return std::unique_ptr(std::make_unique(arg)); - }, - [](const tools &arg) { return std::unique_ptr(std::make_unique(arg)); }, - }, - objType)); + std::visit(overloaded{ + [](const weapons &arg) { + return std::unique_ptr( + std::make_unique(arg) + ); + }, + [](const equipments &arg) { + return std::unique_ptr( + std::make_unique(arg) + ); + }, + [](const tools &arg) { + return std::unique_ptr( + std::make_unique(arg) + ); + }, + }, + objType)); const auto &object = sheet.objects[objType]; sheet.available_objects.erase(objType); @@ -37,11 +46,11 @@ namespace character { auto &local_chance = static_cast(sheet.chance); std::visit(overloaded{ - [&](const weapons &arg) { ++sheet.nb_weapons; }, - [&](const equipments &arg) { ++sheet.nb_equipments; }, - [&](const tools &arg) { ++sheet.nb_tools; }, - }, - objType); + [&](const weapons &arg) { ++sheet.nb_weapons; }, + [&](const equipments &arg) { ++sheet.nb_equipments; }, + [&](const tools &arg) { ++sheet.nb_tools; }, + }, + objType); change_carac(object, sheet, local_habilete, local_adresse, local_endurance, local_chance, plus); return true; } @@ -60,22 +69,23 @@ namespace character { auto &local_chance = static_cast(sheet.chance); std::visit(overloaded{ - [&](const weapons &arg) { --sheet.nb_weapons; }, - [&](const equipments &arg) { --sheet.nb_equipments; }, - [&](const tools &arg) { --sheet.nb_tools; } - }, - objToErase); + [&](const weapons &arg) { --sheet.nb_weapons; }, + [&](const equipments &arg) { --sheet.nb_equipments; }, + [&](const tools &arg) { --sheet.nb_tools; } + }, + objToErase); change_carac(obj, sheet, local_habilete, local_adresse, local_endurance, local_chance, minus); } } void BillyObjects::change_carac(const billyObjects &arg, - CharacterSheet &sheet, - Characteristic &localHabilete, - Characteristic &localAdresse, - Characteristic &localEndurance, - Characteristic &localChance, - const std::function &operation) noexcept { + CharacterSheet &sheet, + Characteristic &localHabilete, + Characteristic &localAdresse, + Characteristic &localEndurance, + Characteristic &localChance, + const std::function &operation) + noexcept { localHabilete.materiel = operation(localHabilete.materiel, arg->add_materiel(localHabilete.type)); localAdresse.materiel = operation(localAdresse.materiel, arg->add_materiel(localAdresse.type)); localEndurance.materiel = operation(localEndurance.materiel, arg->add_materiel(localEndurance.type)); @@ -88,10 +98,10 @@ namespace character { void BillyObjects::check_dagger_conditions(CharacterSheet &sheet) { if (const auto it_dagger = sheet.get_objects().find(tools::Dagger); it_dagger != sheet.get_objects().cend()) { const std::size_t count_weapons = std::count_if(sheet.get_objects().cbegin(), - sheet.get_objects().cend(), - [](container::const_reference node) { - return std::get_if(&node.first) != nullptr; - } + sheet.get_objects().cend(), + [](container::const_reference node) { + return std::get_if(&node.first) != nullptr; + } ); if (const bool is_there_bow = sheet.get_objects().find(weapons::Bow) != sheet.get_objects().cend(); count_weapons > 1 || is_there_bow) { @@ -114,7 +124,7 @@ namespace character { break; case equipmentHash: billy.emplace(static_cast(value), - std::make_unique(static_cast(value))); + std::make_unique(static_cast(value))); break; case toolsHash: billy.emplace(static_cast(value), std::make_unique(static_cast(value))); @@ -128,17 +138,17 @@ namespace character { void BillyObjects::to_json(json &j, const container &billy) { for (const auto &[object_type, _]: billy) { std::visit(overloaded{ - [&j](const weapons weapon) { - j.emplace_back(std::pair{ weaponsHash, static_cast(weapon) }); - }, - [&j](const equipments equipment) { - j.emplace_back(std::pair{ equipmentHash, static_cast(equipment) }); - }, - [&j](const tools tool) { - j.emplace_back(std::pair{ toolsHash, static_cast(tool) }); - } - }, - object_type); + [&j](const weapons weapon) { + j.emplace_back(std::pair{ weaponsHash, static_cast(weapon) }); + }, + [&j](const equipments equipment) { + j.emplace_back(std::pair{ equipmentHash, static_cast(equipment) }); + }, + [&j](const tools tool) { + j.emplace_back(std::pair{ toolsHash, static_cast(tool) }); + } + }, + object_type); } } } diff --git a/src/generic_object.cpp b/src/generic_object.cpp index c0536df..70fd557 100644 --- a/src/generic_object.cpp +++ b/src/generic_object.cpp @@ -166,4 +166,4 @@ namespace character { return sackOfGrain; } } -} +} \ No newline at end of file