2022-01-14 22:58:16 +01:00
|
|
|
#ifndef BILLYSHEET_CHARACTERISTIC_HPP
|
|
|
|
#define BILLYSHEET_CHARACTERISTIC_HPP
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
using json = nlohmann::json;
|
|
|
|
|
2024-02-26 12:17:19 +01:00
|
|
|
namespace character {
|
|
|
|
class BillyObjects;
|
|
|
|
}
|
|
|
|
|
2022-01-14 22:58:16 +01:00
|
|
|
namespace character::characteristic {
|
2024-01-28 20:31:50 +01:00
|
|
|
class Characteristic {
|
|
|
|
protected:
|
2024-02-26 12:17:19 +01:00
|
|
|
friend character::BillyObjects;
|
2024-02-26 11:36:22 +01:00
|
|
|
using defaultValue = std::numeric_limits<std::int32_t>;
|
|
|
|
mutable std::int32_t total{ defaultValue::max() };
|
2024-01-28 20:31:50 +01:00
|
|
|
const std::uint32_t base{ 0 };
|
|
|
|
std::uint32_t carac{ 0 };
|
|
|
|
std::uint32_t materiel{ 0 };
|
|
|
|
std::uint32_t additional{ 0 };
|
|
|
|
|
|
|
|
public:
|
|
|
|
Characteristic() noexcept = default;
|
|
|
|
|
|
|
|
Characteristic(const std::uint32_t base,
|
2024-02-29 12:04:09 +01:00
|
|
|
const std::uint32_t carac,
|
|
|
|
const std::uint32_t materiel,
|
|
|
|
const std::uint32_t additional) noexcept:
|
2024-02-26 11:36:22 +01:00
|
|
|
base(base), carac(carac), materiel(materiel), additional(additional) { (void) get_total(); }
|
2024-01-28 20:31:50 +01:00
|
|
|
|
|
|
|
Characteristic(const Characteristic &charac) noexcept = default;
|
|
|
|
|
|
|
|
Characteristic &operator=(const Characteristic &charac) noexcept {
|
|
|
|
const_cast<std::uint32_t &>(base) = charac.base;
|
|
|
|
carac = charac.carac;
|
|
|
|
materiel = charac.materiel;
|
|
|
|
additional = charac.additional;
|
2024-02-26 11:36:22 +01:00
|
|
|
total = charac.get_total();
|
2024-01-28 20:31:50 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Characteristic() noexcept = default;
|
|
|
|
|
|
|
|
[[nodiscard]] std::uint32_t get_base() const { return base; }
|
|
|
|
|
|
|
|
[[nodiscard]] std::uint32_t get_carac() const { return carac; }
|
|
|
|
|
|
|
|
[[nodiscard]] std::uint32_t get_materiel() const { return materiel; }
|
|
|
|
|
|
|
|
[[nodiscard]] std::uint32_t get_additional() const { return additional; }
|
|
|
|
|
2024-02-26 11:36:22 +01:00
|
|
|
[[nodiscard]] std::size_t get_total() const noexcept {
|
|
|
|
if (total == defaultValue::max()) {
|
|
|
|
total = static_cast<std::int32_t>(base + carac + materiel + additional);
|
|
|
|
if (total < 0) {
|
|
|
|
total = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2024-01-28 20:31:50 +01:00
|
|
|
friend void from_json(const json &j, Characteristic &charac) {
|
|
|
|
const_cast<std::uint32_t &>(charac.base) = j.at("base").get<std::uint32_t>();
|
|
|
|
charac.carac = j.at("carac").get<std::uint32_t>();
|
|
|
|
charac.materiel = j.at("materiel").get<std::uint32_t>();
|
|
|
|
charac.additional = j.at("additional").get<std::uint32_t>();
|
2024-02-26 11:36:22 +01:00
|
|
|
charac.total = j.at("total").get<std::uint32_t>();
|
2024-01-28 20:31:50 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void to_json(json &j, const Characteristic &charac) {
|
|
|
|
j["base"] = charac.get_base();
|
|
|
|
j["carac"] = charac.get_carac();
|
|
|
|
j["materiel"] = charac.get_materiel();
|
|
|
|
j["additional"] = charac.get_additional();
|
2024-02-26 11:36:22 +01:00
|
|
|
j["total"] = charac.get_total();
|
2024-01-28 20:31:50 +01:00
|
|
|
}
|
2022-01-14 22:58:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif //BILLYSHEET_CHARACTERISTIC_HPP
|