diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp deleted file mode 100644 index 3841153..0000000 --- a/include/billy_objects.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// -// Created by postaron on 20/02/24. -// - -#ifndef BILLYSHEET_BILLY_OBJECTS_HPP -#define BILLYSHEET_BILLY_OBJECTS_HPP - -#include -#include -#include -#include -#include -#include "characteristic/characteristic.hpp" - -// helper type for the visitor -template -struct overloaded : Ts ... { using Ts::operator()...; }; -template -overloaded(Ts...) -> overloaded; - -namespace character { - class CharacterSheet; - - enum class weapons : std::uint8_t { - Sword = 0, - Lance = 1, - Morgenstern = 2, - Bow = 3 - }; - - enum class equipments : std::uint8_t { - Chainmail = 0, - CookingPot = 1, - PamphletTourist = 2, - MedicKit = 3, - }; - - enum class tools : std::uint8_t { - Fourche = 0, - Dagger = 1, - RockClimbingKit = 2, - SackOfGrain = 3 - }; - - class BillyObjects final { - public: - using billyObject = std::variant; - using container = std::array; - - static constexpr std::string_view sword{ "Sword" }; - static constexpr std::string_view lance{ "Lance" }; - static constexpr std::string_view morgenstern{ "Morgenstern" }; - static constexpr std::string_view bow{ "Bow" }; - - static constexpr std::string_view chainmail{ "Chainmail" }; - static constexpr std::string_view cooking_pot{ "Cooking pot" }; - static constexpr std::string_view medic_kit{ "Medic kit" }; - - static constexpr std::string_view fourche{ "Fourche" }; - static constexpr std::string_view dagger{ "Dagger" }; - static constexpr std::string_view rock_climbing_kit{ "Rock climbing kit" }; - static constexpr std::string_view sack_of_grain{ "Sack of grain" }; - - static std::string_view billy_object_to_string(const billyObject &object) noexcept; - - void add_object(const billyObject &object, CharacterSheet &sheet) noexcept; - - void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept; - - private: - container objects; - std::plus plus; - std::minus minus; - std::uint8_t end_object{ 0 }; - - static void change_carac_weapon(CharacterSheet &sheet, - const weapons &arg, - characteristic::Characteristic &localHabilete, - characteristic::Characteristic &localAdresse, - characteristic::Characteristic &localEndurance, - const std::function &operation) noexcept; - - static void change_carac_equipment(const equipments &arg, - CharacterSheet &sheet, - characteristic::Characteristic &localHabilete, - characteristic::Characteristic &localAdresse, - characteristic::Characteristic &localEndurance, - characteristic::Characteristic &localChance, - const std::function &primary, - const std::function &complement) noexcept; - - static void change_carac_tools(const tools &arg, - CharacterSheet &sheet, - characteristic::Characteristic &localHabilete, - characteristic::Characteristic &localAdresse, - characteristic::Characteristic &localEndurance, - characteristic::Characteristic &localChance, - const std::function &operation) noexcept; - }; -} - -#endif //BILLYSHEET_BILLY_OBJECTS_HPP diff --git a/include/character_sheet.hpp b/include/character_sheet.hpp index b19ce82..ace76ed 100644 --- a/include/character_sheet.hpp +++ b/include/character_sheet.hpp @@ -23,14 +23,12 @@ namespace character { private: friend gui::Gui; - friend class BillyObjects; + friend class Controller; std::mt19937_64 engine{ std::random_device{ "rdseed" }() }; std::string caractere{}; - //TODO: bad design pour les caractéristiques. Je dois trouver autre chose. - characteristic::Adresse adresse; characteristic::Endurance endurance; @@ -39,6 +37,8 @@ namespace character { characteristic::Habilete habilete; + classe current_class{ classe::Guerrier }; + std::uint32_t health_point{ 0 }; std::uint32_t armor{ 0 }; @@ -48,12 +48,6 @@ namespace character { std::uint32_t glory{ 0 }; std::uint32_t money{ 0 }; - - std::uint32_t nb_weapons{ 0 }; - - std::uint32_t nb_equipments{ 0 }; - - std::uint32_t nb_tools{ 0 }; public: CharacterSheet() = default; @@ -77,17 +71,7 @@ namespace character { [[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; } - [[nodiscard]] classe get_current_class() const { - if (nb_weapons >= 2) { - return classe::Guerrier; - } else if (nb_equipments >= 2) { - return classe::Prudent; - } else if (nb_tools >= 2) { - return classe::Paysan; - } else { - return classe::Debrouillard; - } - } + [[nodiscard]] classe get_current_class() const { return current_class; } [[nodiscard]] std::uint32_t get_health_point() const { return health_point; } @@ -99,26 +83,18 @@ namespace character { [[nodiscard]] std::uint32_t get_money() const { return money; } - [[nodiscard]] std::uint32_t get_nb_weapons() const { return nb_weapons; } - - [[nodiscard]] std::uint32_t get_nb_equipments() const { return nb_equipments; } - - [[nodiscard]] std::uint32_t get_nb_tools() const { return nb_tools; } - friend void from_json(const json &j, CharacterSheet &billy) { j.at("caractere").get_to(billy.caractere); j.at("adresse").get_to(billy.adresse); j.at("endurance").get_to(billy.endurance); j.at("chance").get_to(billy.chance); j.at("habilete").get_to(billy.habilete); + j.at("classe").get_to(billy.current_class); j.at("health_point").get_to(billy.health_point); j.at("armor").get_to(billy.armor); j.at("damage").get_to(billy.damage); j.at("glory").get_to(billy.glory); j.at("money").get_to(billy.money); - j.at("nb_weapons").get_to(billy.nb_weapons); - j.at("nb_equipments").get_to(billy.nb_equipments); - j.at("nb_tools").get_to(billy.nb_tools); } }; @@ -134,9 +110,6 @@ namespace character { j["damage"] = billy.get_damage(); j["glory"] = billy.get_glory(); j["money"] = billy.get_money(); - j["nb_weapons"] = billy.get_nb_weapons(); - j["nb_equipments"] = billy.get_nb_equipments(); - j["nb_tools"] = billy.get_nb_tools(); } } diff --git a/include/characteristic/adresse.hpp b/include/characteristic/adresse.hpp index dbb1ce9..4847854 100644 --- a/include/characteristic/adresse.hpp +++ b/include/characteristic/adresse.hpp @@ -11,9 +11,6 @@ namespace character::characteristic { public: Adresse() noexcept: Characteristic(1, 0, 0, 0) {} - Adresse(const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) : - Characteristic(1, carac, materiel, additional) {} - ~Adresse() noexcept final = default; friend void from_json(const json &j, Adresse &adresse) { diff --git a/include/characteristic/chance.hpp b/include/characteristic/chance.hpp index aed65ee..7e36426 100644 --- a/include/characteristic/chance.hpp +++ b/include/characteristic/chance.hpp @@ -8,9 +8,6 @@ namespace character::characteristic { public: Chance() noexcept: Characteristic(3, 0, 0, 0) {} - Chance(const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) : - Characteristic(3, carac, materiel, additional) {} - ~Chance() noexcept final = default; friend void from_json(const json &j, Chance &chance) { diff --git a/include/characteristic/characteristic.hpp b/include/characteristic/characteristic.hpp index d52479c..495ee3a 100644 --- a/include/characteristic/characteristic.hpp +++ b/include/characteristic/characteristic.hpp @@ -6,16 +6,9 @@ using json = nlohmann::json; -namespace character { - class BillyObjects; -} - namespace character::characteristic { class Characteristic { protected: - friend character::BillyObjects; - using defaultValue = std::numeric_limits; - mutable std::int32_t total{ defaultValue::max() }; const std::uint32_t base{ 0 }; std::uint32_t carac{ 0 }; std::uint32_t materiel{ 0 }; @@ -28,7 +21,7 @@ namespace character::characteristic { const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) noexcept: - base(base), carac(carac), materiel(materiel), additional(additional) { (void) get_total(); } + base(base), carac(carac), materiel(materiel), additional(additional) {} Characteristic(const Characteristic &charac) noexcept = default; @@ -37,7 +30,6 @@ namespace character::characteristic { carac = charac.carac; materiel = charac.materiel; additional = charac.additional; - total = charac.get_total(); return *this; } @@ -51,22 +43,11 @@ namespace character::characteristic { [[nodiscard]] std::uint32_t get_additional() const { return additional; } - [[nodiscard]] std::size_t get_total() const noexcept { - if (total == defaultValue::max()) { - total = static_cast(base + carac + materiel + additional); - if (total < 0) { - total = 0; - } - } - return total; - } - friend void from_json(const json &j, Characteristic &charac) { const_cast(charac.base) = j.at("base").get(); charac.carac = j.at("carac").get(); charac.materiel = j.at("materiel").get(); charac.additional = j.at("additional").get(); - charac.total = j.at("total").get(); } }; @@ -75,7 +56,6 @@ namespace character::characteristic { j["carac"] = charac.get_carac(); j["materiel"] = charac.get_materiel(); j["additional"] = charac.get_additional(); - j["total"] = charac.get_total(); } } diff --git a/include/characteristic/endurance.hpp b/include/characteristic/endurance.hpp index 91ad534..2853a9b 100644 --- a/include/characteristic/endurance.hpp +++ b/include/characteristic/endurance.hpp @@ -11,9 +11,6 @@ namespace character::characteristic { public: Endurance() noexcept: Characteristic(2, 0, 0, 0) {}; - Endurance(const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) noexcept: - Characteristic(2, carac, materiel, additional) {} - ~Endurance() noexcept final = default; [[nodiscard]] std::uint32_t get_max_lp() const noexcept; diff --git a/include/characteristic/habilete.hpp b/include/characteristic/habilete.hpp index ef5d4ad..dbde189 100644 --- a/include/characteristic/habilete.hpp +++ b/include/characteristic/habilete.hpp @@ -9,9 +9,6 @@ namespace character::characteristic { public: Habilete() noexcept: Characteristic(2, 0, 0, 0) {}; - Habilete(const uint32_t carac, const uint32_t materiel, const uint32_t additional) noexcept: - Characteristic(2, carac, materiel, additional) {} - ~Habilete() noexcept final = default; friend void from_json(const json &j, Habilete &habilete) { diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp deleted file mode 100644 index fd439b6..0000000 --- a/src/billy_objects.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// -// Created by postaron on 23/02/24. -// -#include "billy_objects.hpp" -#include "characteristic/characteristic.hpp" -#include "character_sheet.hpp" - -namespace character { - using characteristic::Characteristic; - - void BillyObjects::add_object(const billyObject &object, CharacterSheet &sheet) noexcept { - if (end_object < 3) { - objects.at(end_object) = object; - - auto &local_habilete = static_cast(sheet.habilete); - auto &local_adresse = static_cast(sheet.adresse); - auto &local_endurance = static_cast(sheet.endurance); - auto &local_chance = static_cast(sheet.chance); - - std::visit(overloaded{ - [&](const weapons &arg) { - ++sheet.nb_weapons; - change_carac_weapon(sheet, arg, local_habilete, local_adresse, local_endurance, plus); - }, - [&](const equipments &arg) { - ++sheet.nb_equipments; - change_carac_equipment(arg, - sheet, - local_habilete, - local_adresse, - local_endurance, - local_chance, - plus, - minus); - }, - [&](const tools &arg) { - ++sheet.nb_tools; - change_carac_tools(arg, sheet, local_habilete, local_adresse, local_endurance, plus); - }, - }, object); - } - } - - void BillyObjects::change_carac_tools(const tools &arg, - CharacterSheet &sheet, - Characteristic &localHabilete, - Characteristic &localAdresse, - Characteristic &localEndurance, - Characteristic &localChance, - const std::function &operation) noexcept { - switch (arg) { - case tools::Fourche: - localHabilete.materiel = operation(localHabilete.materiel, 1); - localEndurance.materiel = operation(localEndurance.materiel, 3); - break; - case tools::Dagger: - break; - case tools::RockClimbingKit: - localAdresse.materiel = operation(localAdresse.materiel, 1); - break; - case tools::SackOfGrain: - localEndurance.materiel = operation(localEndurance.materiel, 2); - localChance.materiel = operation(localChance.materiel, 2); - break; - } - } - - void BillyObjects::change_carac_equipment(const equipments &arg, - CharacterSheet &sheet, - Characteristic &localHabilete, - Characteristic &localAdresse, - Characteristic &localEndurance, - Characteristic &localChance, - const std::function &primary, - const std::function &complement) noexcept { - switch (arg) { - case equipments::Chainmail: - localHabilete.materiel = complement(localHabilete.materiel, 1); - localAdresse.materiel = complement(localAdresse.materiel, 1); - localEndurance.materiel = primary(localEndurance.materiel, 1); - sheet.armor = primary(sheet.armor, 2); - break; - case equipments::CookingPot: - localEndurance.materiel = primary(localEndurance.materiel, 2); - sheet.armor = primary(sheet.armor, 1); - break; - case equipments::PamphletTourist: - localChance.materiel = primary(localChance.materiel, 4); - break; - case equipments::MedicKit: - localChance.materiel = primary(localChance.materiel, 1); - break; - } - } - - void BillyObjects::change_carac_weapon(CharacterSheet &sheet, - const weapons &arg, - Characteristic &localHabilete, - Characteristic &localAdresse, - Characteristic &localEndurance, - const std::function &operation) noexcept { - switch (arg) { - case weapons::Sword: - localHabilete.materiel = operation(localHabilete.materiel, 4); - break; - case weapons::Lance: - localHabilete.materiel = operation(localHabilete.materiel, 3); - localAdresse.materiel = operation(localAdresse.materiel, 1); - break; - case weapons::Morgenstern: - localHabilete.materiel = operation(localHabilete.materiel, 1); - localEndurance.materiel = operation(localEndurance.materiel, 1); - sheet.damage = operation(sheet.damage, 1); - break; - case weapons::Bow: - localHabilete.materiel = operation(localHabilete.materiel, 3); - localAdresse.materiel = operation(localAdresse.materiel, 1); - break; - } - } - - std::string_view BillyObjects::billy_object_to_string(const billyObject &object) noexcept { - return std::visit(overloaded{ - [](const weapons &arg) { - switch (arg) { - case weapons::Sword: - return sword; - case weapons::Lance: - return lance; - case weapons::Morgenstern: - return morgenstern; - case weapons::Bow: - return bow; - } - }, - [](const equipments &arg) { - switch (arg) { - case equipments::Chainmail: - return chainmail; - case equipments::CookingPot: - return cooking_pot; - case equipments::MedicKit: - return medic_kit; - } - }, - [](const tools &arg) { - switch (arg) { - case tools::Fourche: - return fourche; - case tools::Dagger: - return dagger; - case tools::RockClimbingKit: - return rock_climbing_kit; - case tools::SackOfGrain: - return sack_of_grain; - } - } - }, object); - } -} \ No newline at end of file diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 000df05..17d1f68 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -53,6 +53,8 @@ void gui::Gui::render_gui(const Controller &controller) { ImGuiComboFlags_PopupAlignLeft)) { for (std::size_t i = 0; i < GuiData::classes.size(); ++i) { const bool is_selected = (data.billy.get_current_class() == static_cast(i)); + if (ImGui::Selectable(GuiData::classes[i].data(), is_selected)) + data.billy.current_class = static_cast(i); if (is_selected) ImGui::SetItemDefaultFocus();