C++23
This commit is contained in:
parent
f9f973b51e
commit
02d7895033
3 changed files with 32 additions and 27 deletions
|
|
@ -81,7 +81,7 @@ target_include_directories(BillySheet
|
|||
target_include_directories(BillySheet INTERFACE $<INSTALL_INTERFACE:include/billySheet>)
|
||||
|
||||
set_target_properties(BillySheet PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD 23
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
CXX_EXTENSIONS OFF
|
||||
INTERPROCEDURAL_OPTIMIZATION ON
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ TEST_CASE("[E] Serialize sheet", "[serialize][0]") {
|
|||
}
|
||||
|
||||
TEST_CASE("[F] Deserialize sheet", "[deserialize][0]") {
|
||||
const auto deserializer = []() {
|
||||
const auto deserializer = [] {
|
||||
std::ifstream file{ "character_sheet.json" };
|
||||
return json::parse(file);
|
||||
}();
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ namespace character {
|
|||
auto &local_chance = static_cast<Characteristic &>(sheet.chance);
|
||||
|
||||
std::visit(overloaded{
|
||||
[&](const weapons &arg) { ++sheet.nb_weapons; },
|
||||
[&](const equipments &arg) { ++sheet.nb_equipments; },
|
||||
[&](const tools &arg) { ++sheet.nb_tools; },
|
||||
[&](const weapons &) { ++sheet.nb_weapons; },
|
||||
[&](const equipments &) { ++sheet.nb_equipments; },
|
||||
[&](const tools &) { ++sheet.nb_tools; },
|
||||
},
|
||||
objType);
|
||||
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) {
|
||||
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<weapons>(&node.first) != nullptr;
|
||||
}
|
||||
const std::size_t count_weapons = std::ranges::count_if(sheet.get_objects(),
|
||||
[](container::const_reference node) {
|
||||
return std::get_if<weapons>(&node.first) !=
|
||||
nullptr;
|
||||
}
|
||||
);
|
||||
if (count_weapons > 1 || sheet.get_objects().find(weapons::Bow) != sheet.get_objects().cend()) {
|
||||
if (count_weapons > 1 || sheet.get_objects().contains(weapons::Bow)) {
|
||||
sheet.habilete.materiel -= it_dagger->second->add_materiel(sheet.get_habilete().type);
|
||||
}
|
||||
}
|
||||
|
|
@ -130,26 +130,31 @@ namespace character {
|
|||
case toolsHash:
|
||||
billy.emplace(static_cast<tools>(value), std::make_unique<Tools>(static_cast<tools>(value)));
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("Wrong hash for from_json in BillyObjects::from_json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<std::uint8_t>(weapon) });
|
||||
},
|
||||
[&j](const equipments equipment) {
|
||||
j.emplace_back(std::pair{ equipmentHash, static_cast<std::uint8_t>(equipment) });
|
||||
},
|
||||
[&j](const tools tool) {
|
||||
j.emplace_back(std::pair{ toolsHash, static_cast<std::uint8_t>(tool) });
|
||||
}
|
||||
},
|
||||
object_type);
|
||||
}
|
||||
std::ranges::for_each(billy | std::views::keys,
|
||||
[&j](const auto &obj) {
|
||||
std::visit(overloaded{
|
||||
[&j](const weapons 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 tools tool) {
|
||||
j.emplace_back(std::pair{
|
||||
toolsHash, static_cast<std::uint8_t>(tool)
|
||||
});
|
||||
}
|
||||
},
|
||||
obj);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue