Reformat
This commit is contained in:
parent
b3c59ffe0d
commit
b050a7634d
8 changed files with 113 additions and 104 deletions
|
|
@ -23,9 +23,15 @@ namespace character::test {
|
||||||
|
|
||||||
static std::unique_ptr<GenericObject> get_obj(const billyEnums &object) noexcept {
|
static std::unique_ptr<GenericObject> get_obj(const billyEnums &object) noexcept {
|
||||||
return std::visit(overloaded{
|
return std::visit(overloaded{
|
||||||
[](const weapons &arg) { return std::unique_ptr<GenericObject>(std::make_unique<Weapons>(arg)); },
|
[](const weapons &arg) {
|
||||||
[](const equipments &arg) { return std::unique_ptr<GenericObject>(std::make_unique<Equipments>(arg)); },
|
return std::unique_ptr<GenericObject>(std::make_unique<Weapons>(arg));
|
||||||
[](const tools &arg) { return std::unique_ptr<GenericObject>(std::make_unique<Tools>(arg)); },
|
},
|
||||||
|
[](const equipments &arg) {
|
||||||
|
return std::unique_ptr<GenericObject>(std::make_unique<Equipments>(arg));
|
||||||
|
},
|
||||||
|
[](const tools &arg) {
|
||||||
|
return std::unique_ptr<GenericObject>(std::make_unique<Tools>(arg));
|
||||||
|
},
|
||||||
},
|
},
|
||||||
object);
|
object);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,7 @@ TEST_CASE("[A] Serialize adresse", "[serialize][0]") {
|
||||||
REQUIRE_NOTHROW(tester.at("base") == 1);
|
REQUIRE_NOTHROW(tester.at("base") == 1);
|
||||||
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
||||||
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
||||||
REQUIRE_NOTHROW(tester.at("additional") == 0);
|
REQUIRE_NOTHROW(tester.at("additional") == 0); {
|
||||||
|
|
||||||
{
|
|
||||||
std::ofstream file{ "adresse.json" };
|
std::ofstream file{ "adresse.json" };
|
||||||
file << serializer << std::flush;
|
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("base") == 3);
|
||||||
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
||||||
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
||||||
REQUIRE_NOTHROW(tester.at("additional") == 0);
|
REQUIRE_NOTHROW(tester.at("additional") == 0); {
|
||||||
|
|
||||||
{
|
|
||||||
std::ofstream file{ "chance.json" };
|
std::ofstream file{ "chance.json" };
|
||||||
file << serializer << std::flush;
|
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("base") == 2);
|
||||||
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
||||||
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
||||||
REQUIRE_NOTHROW(tester.at("additional") == 0);
|
REQUIRE_NOTHROW(tester.at("additional") == 0); {
|
||||||
|
|
||||||
{
|
|
||||||
std::ofstream file{ "endurance.json" };
|
std::ofstream file{ "endurance.json" };
|
||||||
file << serializer << std::flush;
|
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("base") == 2);
|
||||||
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
||||||
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
||||||
REQUIRE_NOTHROW(tester.at("additional") == 0);
|
REQUIRE_NOTHROW(tester.at("additional") == 0); {
|
||||||
|
|
||||||
{
|
|
||||||
std::ofstream file{ "habilete.json" };
|
std::ofstream file{ "habilete.json" };
|
||||||
file << serializer << std::flush;
|
file << serializer << std::flush;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ namespace character {
|
||||||
|
|
||||||
class CharacterSheet final {
|
class CharacterSheet final {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend BillyObjects;
|
friend BillyObjects;
|
||||||
|
|
||||||
std::string caractere{};
|
std::string caractere{};
|
||||||
|
|
@ -54,6 +53,7 @@ namespace character {
|
||||||
std::uint32_t nb_equipments{ 0 };
|
std::uint32_t nb_equipments{ 0 };
|
||||||
|
|
||||||
std::uint32_t nb_tools{ 0 };
|
std::uint32_t nb_tools{ 0 };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CharacterSheet() = default;
|
CharacterSheet() = default;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef BILLYSHEET_CHARACTERISTIC_HPP
|
#ifndef BILLYSHEET_CHARACTERISTIC_HPP
|
||||||
#define BILLYSHEET_CHARACTERISTIC_HPP
|
#define BILLYSHEET_CHARACTERISTIC_HPP
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
|
@ -82,9 +83,7 @@ namespace character::characteristic {
|
||||||
[[nodiscard]] std::size_t get_total() const noexcept {
|
[[nodiscard]] std::size_t get_total() const noexcept {
|
||||||
if (total == defaultValue::max()) {
|
if (total == defaultValue::max()) {
|
||||||
total = static_cast<std::int32_t>(base + carac + materiel + additional);
|
total = static_cast<std::int32_t>(base + carac + materiel + additional);
|
||||||
if (total < 0) {
|
total = std::max(total, 0);
|
||||||
total = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,10 @@
|
||||||
|
|
||||||
// helper type for the visitor
|
// helper type for the visitor
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
struct overloaded : Ts ... { using Ts::operator()...; };
|
struct overloaded : Ts... {
|
||||||
|
using Ts::operator()...;
|
||||||
|
};
|
||||||
|
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
overloaded(Ts...) -> overloaded<Ts...>;
|
overloaded(Ts...) -> overloaded<Ts...>;
|
||||||
|
|
||||||
|
|
@ -139,7 +142,6 @@ namespace character {
|
||||||
|
|
||||||
[[nodiscard]] billyEnums get_type() const noexcept final { return type; }
|
[[nodiscard]] billyEnums get_type() const noexcept final { return type; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // character
|
} // character
|
||||||
|
|
||||||
#endif //BILLYSHEET_GENERIC_OBJECT_HPP
|
#endif //BILLYSHEET_GENERIC_OBJECT_HPP
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "billy_objects.hpp"
|
#include "billy_objects.hpp"
|
||||||
#include "characteristic.hpp"
|
#include "characteristic.hpp"
|
||||||
#include "character_sheet.hpp"
|
#include "character_sheet.hpp"
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
constexpr std::uint32_t const_hash(const char *input) {
|
constexpr std::uint32_t const_hash(const char *input) {
|
||||||
|
|
@ -20,12 +21,20 @@ namespace character {
|
||||||
sheet.objects.emplace(objType,
|
sheet.objects.emplace(objType,
|
||||||
std::visit(overloaded{
|
std::visit(overloaded{
|
||||||
[](const weapons &arg) {
|
[](const weapons &arg) {
|
||||||
return std::unique_ptr<GenericObject>(std::make_unique<Weapons>(arg));
|
return std::unique_ptr<GenericObject>(
|
||||||
|
std::make_unique<Weapons>(arg)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
[](const equipments &arg) {
|
[](const equipments &arg) {
|
||||||
return std::unique_ptr<GenericObject>(std::make_unique<Equipments>(arg));
|
return std::unique_ptr<GenericObject>(
|
||||||
|
std::make_unique<Equipments>(arg)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[](const tools &arg) {
|
||||||
|
return std::unique_ptr<GenericObject>(
|
||||||
|
std::make_unique<Tools>(arg)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
[](const tools &arg) { return std::unique_ptr<GenericObject>(std::make_unique<Tools>(arg)); },
|
|
||||||
},
|
},
|
||||||
objType));
|
objType));
|
||||||
const auto &object = sheet.objects[objType];
|
const auto &object = sheet.objects[objType];
|
||||||
|
|
@ -75,7 +84,8 @@ namespace character {
|
||||||
Characteristic &localAdresse,
|
Characteristic &localAdresse,
|
||||||
Characteristic &localEndurance,
|
Characteristic &localEndurance,
|
||||||
Characteristic &localChance,
|
Characteristic &localChance,
|
||||||
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation) noexcept {
|
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation)
|
||||||
|
noexcept {
|
||||||
localHabilete.materiel = operation(localHabilete.materiel, arg->add_materiel(localHabilete.type));
|
localHabilete.materiel = operation(localHabilete.materiel, arg->add_materiel(localHabilete.type));
|
||||||
localAdresse.materiel = operation(localAdresse.materiel, arg->add_materiel(localAdresse.type));
|
localAdresse.materiel = operation(localAdresse.materiel, arg->add_materiel(localAdresse.type));
|
||||||
localEndurance.materiel = operation(localEndurance.materiel, arg->add_materiel(localEndurance.type));
|
localEndurance.materiel = operation(localEndurance.materiel, arg->add_materiel(localEndurance.type));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue