Compare commits

..

No commits in common. "9d8156291721a30abff8082ad0809163637c4876" and "f9f973b51ebf4f90e6fc13ba1b5854df62f88242" have entirely different histories.

5 changed files with 51 additions and 64 deletions

View file

@ -81,7 +81,7 @@ target_include_directories(BillySheet
target_include_directories(BillySheet INTERFACE $<INSTALL_INTERFACE:include/billySheet>) target_include_directories(BillySheet INTERFACE $<INSTALL_INTERFACE:include/billySheet>)
set_target_properties(BillySheet PROPERTIES set_target_properties(BillySheet PROPERTIES
CXX_STANDARD 23 CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF CXX_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION ON

View file

@ -165,19 +165,6 @@ TEST_CASE("[D] Double erase no throw", "[pushpop][1]") {
REQUIRE_FALSE(gestionnaire.erase_object(sheet, weapons::Bow)); REQUIRE_FALSE(gestionnaire.erase_object(sheet, weapons::Bow));
} }
TEST_CASE("[D] Insert no more than 3", "[pushpop][2]") {
BillyObjects gestionnaire{};
CharacterSheet sheet;
REQUIRE(sheet.get_objects().empty());
REQUIRE_NOTHROW(gestionnaire.insert_object(sheet, weapons::Sword));
REQUIRE(gestionnaire.insert_object(sheet, weapons::Morgenstern));
REQUIRE(gestionnaire.insert_object(sheet, weapons::Bow));
REQUIRE(sheet.get_objects().size() == 3);
REQUIRE_FALSE(gestionnaire.insert_object(sheet, equipments::Chainmail));
REQUIRE(sheet.get_objects().size() == 3);
}
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

@ -22,7 +22,7 @@ TEST_CASE("[E] Serialize sheet", "[serialize][0]") {
} }
TEST_CASE("[F] Deserialize sheet", "[deserialize][0]") { TEST_CASE("[F] Deserialize sheet", "[deserialize][0]") {
const auto deserializer = [] { const auto deserializer = []() {
std::ifstream file{ "character_sheet.json" }; std::ifstream file{ "character_sheet.json" };
return json::parse(file); return json::parse(file);
}(); }();

View file

@ -80,10 +80,15 @@ namespace character {
[[nodiscard]] const BillyObjects::container &get_objects() const { return objects; } [[nodiscard]] const BillyObjects::container &get_objects() const { return objects; }
[[nodiscard]] classe get_current_class() const { [[nodiscard]] classe get_current_class() const {
if (nb_weapons >= 2) { return classe::Guerrier; } if (nb_weapons >= 2) {
if (nb_equipments >= 2) { return classe::Prudent; } return classe::Guerrier;
if (nb_tools >= 2) { return classe::Paysan; } } else if (nb_equipments >= 2) {
return classe::Debrouillard; return classe::Prudent;
} else if (nb_tools >= 2) {
return classe::Paysan;
} else {
return classe::Debrouillard;
}
} }
[[nodiscard]] std::uint32_t get_health_point() const { return health_point; } [[nodiscard]] std::uint32_t get_health_point() const { return health_point; }
@ -121,24 +126,24 @@ namespace character {
}; };
static void to_json(json &j, const CharacterSheet &billy) { static void to_json(json &j, const CharacterSheet &billy) {
j.emplace("caractere", billy.get_caractere()); j["caractere"] = billy.get_caractere();
j.emplace("adresse", billy.get_adresse()); j["adresse"] = billy.get_adresse();
j.emplace("endurance", billy.get_endurance()); j["endurance"] = billy.get_endurance();
j.emplace("chance", billy.get_chance()); j["chance"] = billy.get_chance();
j.emplace("habilete", billy.get_habilete()); j["habilete"] = billy.get_habilete();
j.emplace("classe", billy.get_current_class()); j["classe"] = billy.get_current_class();
j.emplace("health_point", billy.get_health_point()); j["health_point"] = billy.get_health_point();
j.emplace("armor", billy.get_armor()); j["armor"] = billy.get_armor();
j.emplace("damage", billy.get_damage()); j["damage"] = billy.get_damage();
j.emplace("glory", billy.get_glory()); j["glory"] = billy.get_glory();
j.emplace("money", billy.get_money()); j["money"] = billy.get_money();
j.emplace("nb_weapons", billy.get_nb_weapons()); j["nb_weapons"] = billy.get_nb_weapons();
j.emplace("nb_equipments", billy.get_nb_equipments()); j["nb_equipments"] = billy.get_nb_equipments();
j.emplace("nb_tools", billy.get_nb_tools()); j["nb_tools"] = billy.get_nb_tools();
j.emplace(std::pair{ BillyObjects::json_key, json::array() }); j.emplace(std::pair{ BillyObjects::json_key, json::array() });
BillyObjects::to_json(j.at(BillyObjects::json_key), billy.get_objects()); BillyObjects::to_json(j.at(BillyObjects::json_key), billy.get_objects());
} }
} }
#endif //BILLYSHEET_CHARACTER_SHEET_HPP #endif //BILLYSHEET_CHARACTER_SHEET_HPP

View file

@ -46,9 +46,9 @@ 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; },
}, },
objType); objType);
change_carac(object, sheet, local_habilete, local_adresse, local_endurance, local_chance, plus); change_carac(object, sheet, local_habilete, local_adresse, local_endurance, local_chance, plus);
@ -99,13 +99,13 @@ namespace character {
void BillyObjects::check_dagger_conditions(CharacterSheet &sheet) { void BillyObjects::check_dagger_conditions(CharacterSheet &sheet) {
if (const auto it_dagger = sheet.get_objects().find(tools::Dagger); it_dagger != sheet.get_objects().cend()) { if (const auto it_dagger = sheet.get_objects().find(tools::Dagger); it_dagger != sheet.get_objects().cend()) {
const std::size_t count_weapons = std::ranges::count_if(sheet.get_objects(), const std::size_t count_weapons = std::count_if(sheet.get_objects().cbegin(),
[](container::const_reference node) { sheet.get_objects().cend(),
return std::get_if<weapons>(&node.first) != [](container::const_reference node) {
nullptr; return std::get_if<weapons>(&node.first) != nullptr;
} }
); );
if (count_weapons > 1 || sheet.get_objects().contains(weapons::Bow)) { if (count_weapons > 1 || sheet.get_objects().find(weapons::Bow) != sheet.get_objects().cend()) {
sheet.habilete.materiel -= it_dagger->second->add_materiel(sheet.get_habilete().type); sheet.habilete.materiel -= it_dagger->second->add_materiel(sheet.get_habilete().type);
} }
} }
@ -130,31 +130,26 @@ namespace character {
case toolsHash: case toolsHash:
billy.emplace(static_cast<tools>(value), std::make_unique<Tools>(static_cast<tools>(value))); billy.emplace(static_cast<tools>(value), std::make_unique<Tools>(static_cast<tools>(value)));
break; break;
default:
throw std::logic_error("Wrong hash for from_json in BillyObjects::from_json");
} }
} }
} }
void BillyObjects::to_json(json &j, const container &billy) { void BillyObjects::to_json(json &j, const container &billy) {
std::ranges::for_each(billy | std::views::keys, for (const auto &[object_type, _]: billy) {
[&j](const auto &obj) { std::visit(overloaded{
std::visit(overloaded{ [&j](const weapons weapon) {
[&j](const weapons weapon) { j.emplace_back(std::pair{ weaponsHash, static_cast<std::uint8_t>(weapon) });
j.emplace_back(std::pair{ },
weaponsHash, static_cast<std::uint8_t>(weapon) [&j](const equipments equipment) {
}); j.emplace_back(std::pair{ equipmentHash, static_cast<std::uint8_t>(equipment) });
}, },
[&j](const equipments equipment) { [&j](const tools tool) {
j.emplace_back(std::pair{ j.emplace_back(std::pair{ toolsHash, static_cast<std::uint8_t>(tool) });
equipmentHash, static_cast<std::uint8_t>(equipment) }
}); },
}, object_type);
[&j](const tools tool) { }
j.emplace_back(std::pair{
toolsHash, static_cast<std::uint8_t>(tool)
});
}
},
obj);
});
} }
} }