Cleaner includes
This commit is contained in:
parent
1f18499228
commit
e2d598d5d0
7 changed files with 17 additions and 17 deletions
|
|
@ -11,13 +11,14 @@
|
|||
#include <variant>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <ankerl/svector.h>
|
||||
#include "characteristic/characteristic.hpp"
|
||||
#include "generic_object.hpp"
|
||||
|
||||
|
||||
namespace character {
|
||||
class CharacterSheet;
|
||||
namespace characteristic{
|
||||
class Characteristic;
|
||||
}
|
||||
|
||||
class BillyObjects final {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef BILLYSHEET_CHARACTER_SHEET_HPP
|
||||
#define BILLYSHEET_CHARACTER_SHEET_HPP
|
||||
|
||||
#include "characteristic/characteristic.hpp"
|
||||
#include "characteristic.hpp"
|
||||
#include "billy_objects.hpp"
|
||||
#include <unordered_set>
|
||||
|
||||
|
|
|
|||
113
include/characteristic.hpp
Normal file
113
include/characteristic.hpp
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
#ifndef BILLYSHEET_CHARACTERISTIC_HPP
|
||||
#define BILLYSHEET_CHARACTERISTIC_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace character {
|
||||
class BillyObjects;
|
||||
}
|
||||
|
||||
namespace character::characteristic {
|
||||
enum class characType : std::uint8_t {
|
||||
Adresse = 0,
|
||||
Endurance = 1,
|
||||
Chance = 2,
|
||||
Habilete = 3
|
||||
};
|
||||
|
||||
class Characteristic {
|
||||
protected:
|
||||
friend character::BillyObjects;
|
||||
using defaultValue = std::numeric_limits<std::int32_t>;
|
||||
mutable std::int32_t total{ defaultValue::max() };
|
||||
const std::uint32_t base{ 0 };
|
||||
std::uint32_t carac{ 0 };
|
||||
std::uint32_t materiel{ 0 };
|
||||
std::uint32_t additional{ 0 };
|
||||
|
||||
static std::uint32_t get_base(const characType inType) noexcept {
|
||||
switch (inType) {
|
||||
case characType::Adresse:
|
||||
return 1;
|
||||
case characType::Chance:
|
||||
return 3;
|
||||
case characType::Endurance:
|
||||
case characType::Habilete:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
const characType type{ characType::Adresse };
|
||||
|
||||
Characteristic() noexcept = default;
|
||||
|
||||
Characteristic(const characType inType,
|
||||
const std::uint32_t carac,
|
||||
const std::uint32_t materiel,
|
||||
const std::uint32_t additional) :
|
||||
base(get_base(inType)),
|
||||
carac(carac),
|
||||
materiel(materiel),
|
||||
additional(additional),
|
||||
type(inType) { (void) get_total(); }
|
||||
|
||||
explicit Characteristic(const characType inType) : Characteristic(inType, 0, 0, 0) {}
|
||||
|
||||
Characteristic(const Characteristic &charac) noexcept = default;
|
||||
|
||||
Characteristic &operator=(const Characteristic &charac) noexcept {
|
||||
const_cast<std::uint32_t &>(base) = charac.base;
|
||||
const_cast<characType &>(type) = charac.type;
|
||||
carac = charac.carac;
|
||||
materiel = charac.materiel;
|
||||
additional = charac.additional;
|
||||
total = charac.get_total();
|
||||
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; }
|
||||
|
||||
[[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;
|
||||
}
|
||||
|
||||
friend void from_json(const json &j, Characteristic &charac) {
|
||||
const_cast<std::uint32_t &>(charac.base) = j.at("base").get<std::uint32_t>();
|
||||
const_cast<characType &>(charac.type) = static_cast<characType>(j.at("type").get<std::uint8_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>();
|
||||
charac.total = j.at("total").get<std::int32_t>();
|
||||
}
|
||||
};
|
||||
|
||||
static void to_json(json &j, const Characteristic &charac) {
|
||||
j["base"] = charac.get_base();
|
||||
j["type"] = charac.type;
|
||||
j["carac"] = charac.get_carac();
|
||||
j["materiel"] = charac.get_materiel();
|
||||
j["additional"] = charac.get_additional();
|
||||
j["total"] = charac.get_total();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //BILLYSHEET_CHARACTERISTIC_HPP
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
#include <variant>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include "characteristic/characteristic.hpp"
|
||||
|
||||
// helper type for the visitor
|
||||
template<typename... Ts>
|
||||
|
|
@ -18,6 +17,10 @@ template<typename... Ts>
|
|||
overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
namespace character {
|
||||
namespace characteristic {
|
||||
enum class characType : std::uint8_t;
|
||||
}
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
enum class weapons : std::uint8_t {
|
||||
|
|
@ -59,7 +62,7 @@ namespace character {
|
|||
|
||||
[[nodiscard]] virtual std::uint32_t add_damage() const noexcept = 0;
|
||||
|
||||
[[nodiscard]] virtual std::int32_t add_materiel(const characteristic::characType inType) const noexcept = 0;
|
||||
[[nodiscard]] virtual std::int32_t add_materiel(const characteristic::characType &inType) const noexcept = 0;
|
||||
|
||||
[[nodiscard]] virtual std::string_view to_string() const noexcept = 0;
|
||||
|
||||
|
|
@ -84,7 +87,7 @@ namespace character {
|
|||
|
||||
[[nodiscard]] std::uint32_t add_damage() const noexcept final;
|
||||
|
||||
[[nodiscard]] std::int32_t add_materiel(const characteristic::characType inType) const noexcept final;
|
||||
[[nodiscard]] std::int32_t add_materiel(const characteristic::characType &inType) const noexcept final;
|
||||
|
||||
[[nodiscard]] std::string_view to_string() const noexcept final;
|
||||
|
||||
|
|
@ -107,7 +110,7 @@ namespace character {
|
|||
|
||||
[[nodiscard]] std::uint32_t add_damage() const noexcept final;
|
||||
|
||||
[[nodiscard]] std::int32_t add_materiel(const characteristic::characType inType) const noexcept final;
|
||||
[[nodiscard]] std::int32_t add_materiel(const characteristic::characType &inType) const noexcept final;
|
||||
|
||||
[[nodiscard]] std::string_view to_string() const noexcept final;
|
||||
|
||||
|
|
@ -130,7 +133,7 @@ namespace character {
|
|||
|
||||
[[nodiscard]] std::uint32_t add_damage() const noexcept final;
|
||||
|
||||
[[nodiscard]] std::int32_t add_materiel(const characteristic::characType inType) const noexcept final;
|
||||
[[nodiscard]] std::int32_t add_materiel(const characteristic::characType &inType) const noexcept final;
|
||||
|
||||
[[nodiscard]] std::string_view to_string() const noexcept final;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
//
|
||||
// Created by postaron on 23/02/24.
|
||||
//
|
||||
#include "billy_objects.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "characteristic/characteristic.hpp"
|
||||
#include "characteristic.hpp"
|
||||
#include "character_sheet.hpp"
|
||||
|
||||
std::uint32_t constexpr const_hash(const char *input) {
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
#include "character_sheet.hpp"
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
#include "generic_object.hpp"
|
||||
#include "characteristic.hpp"
|
||||
|
||||
namespace character {
|
||||
using characteristic::characType;
|
||||
|
|
@ -30,7 +31,7 @@ namespace character {
|
|||
|
||||
std::uint32_t Weapons::add_damage() const noexcept { return type == weapons::Morgenstern ? 1 : 0; }
|
||||
|
||||
std::int32_t Weapons::add_materiel(const characteristic::characType inType) const noexcept {
|
||||
std::int32_t Weapons::add_materiel(const characteristic::characType &inType) const noexcept {
|
||||
switch (type) {
|
||||
case weapons::Sword:
|
||||
if (inType == characType::Habilete) {
|
||||
|
|
@ -93,7 +94,7 @@ namespace character {
|
|||
|
||||
std::uint32_t Equipments::add_damage() const noexcept { return 0; }
|
||||
|
||||
std::int32_t Equipments::add_materiel(const characteristic::characType inType) const noexcept {
|
||||
std::int32_t Equipments::add_materiel(const characteristic::characType &inType) const noexcept {
|
||||
switch (type) {
|
||||
case equipments::Chainmail:
|
||||
if (inType == characType::Habilete ||
|
||||
|
|
@ -129,7 +130,7 @@ namespace character {
|
|||
|
||||
std::uint32_t Tools::add_damage() const noexcept { return 0; }
|
||||
|
||||
std::int32_t Tools::add_materiel(const characteristic::characType inType) const noexcept {
|
||||
std::int32_t Tools::add_materiel(const characteristic::characType &inType) const noexcept {
|
||||
switch (type) {
|
||||
case tools::Fourche:
|
||||
switch (inType) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue