Compare commits

..

No commits in common. "f9f973b51ebf4f90e6fc13ba1b5854df62f88242" and "8a5b2dd927c69241519459a6863239598a49932f" have entirely different histories.

3 changed files with 9 additions and 22 deletions

View file

@ -153,18 +153,6 @@ TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") {
} }
} }
TEST_CASE("[D] Double erase no throw", "[pushpop][1]") {
BillyObjects gestionnaire{};
CharacterSheet sheet;
REQUIRE(sheet.get_objects().empty());
REQUIRE_NOTHROW(gestionnaire.insert_object(sheet, weapons::Sword));
REQUIRE(gestionnaire.insert_object(sheet, weapons::Sword));
REQUIRE_NOTHROW(gestionnaire.erase_object(sheet, weapons::Bow));
REQUIRE_FALSE(gestionnaire.erase_object(sheet, weapons::Bow));
}
TEST_CASE("[D] Printing Billy's objects", "[printing]") { TEST_CASE("[D] Printing Billy's objects", "[printing]") {
for (const auto &object: BillyObjects::all_objects) { for (const auto &object: BillyObjects::all_objects) {
const std::unique_ptr<GenericObject> obj = test::get_obj(object); const std::unique_ptr<GenericObject> obj = test::get_obj(object);

View file

@ -52,7 +52,7 @@ namespace character {
[[nodiscard]] bool insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept; [[nodiscard]] bool insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept;
bool erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept; void erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept;
[[nodiscard]] const std::plus<std::uint32_t> &get_plus_operation() const { return plus; } [[nodiscard]] const std::plus<std::uint32_t> &get_plus_operation() const { return plus; }

View file

@ -57,9 +57,9 @@ namespace character {
return false; return false;
} }
bool BillyObjects::erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept { void BillyObjects::erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept {
if (const auto it = sheet.objects.find(objToErase); it != std::end(sheet.objects)) { if (!sheet.objects.empty()) {
const billyObjects obj{ it->second.release() }; const billyObjects obj{ sheet.objects[objToErase].release() };
sheet.objects.erase(objToErase); sheet.objects.erase(objToErase);
sheet.available_objects.insert(objToErase); sheet.available_objects.insert(objToErase);
@ -69,15 +69,13 @@ namespace character {
auto &local_chance = static_cast<Characteristic &>(sheet.chance); auto &local_chance = static_cast<Characteristic &>(sheet.chance);
std::visit(overloaded{ std::visit(overloaded{
[&](const weapons &) { --sheet.nb_weapons; }, [&](const weapons &arg) { --sheet.nb_weapons; },
[&](const equipments &) { --sheet.nb_equipments; }, [&](const equipments &arg) { --sheet.nb_equipments; },
[&](const tools &) { --sheet.nb_tools; } [&](const tools &arg) { --sheet.nb_tools; }
}, },
objToErase); objToErase);
change_carac(obj, sheet, local_habilete, local_adresse, local_endurance, local_chance, minus); change_carac(obj, sheet, local_habilete, local_adresse, local_endurance, local_chance, minus);
return true;
} }
return false;
} }
void BillyObjects::change_carac(const billyObjects &arg, void BillyObjects::change_carac(const billyObjects &arg,
@ -105,7 +103,8 @@ namespace character {
return std::get_if<weapons>(&node.first) != nullptr; return std::get_if<weapons>(&node.first) != nullptr;
} }
); );
if (count_weapons > 1 || sheet.get_objects().find(weapons::Bow) != sheet.get_objects().cend()) { if (const bool is_there_bow = sheet.get_objects().find(weapons::Bow) != sheet.get_objects().cend();
count_weapons > 1 || is_there_bow) {
sheet.habilete.materiel -= it_dagger->second->add_materiel(sheet.get_habilete().type); sheet.habilete.materiel -= it_dagger->second->add_materiel(sheet.get_habilete().type);
} }
} }