BillySheet/include/billy_objects.hpp

139 lines
5.1 KiB
C++

//
// Created by postaron on 20/02/24.
//
#ifndef BILLYSHEET_BILLY_OBJECTS_HPP
#define BILLYSHEET_BILLY_OBJECTS_HPP
#include <cstdint>
#include <array>
#include <functional>
#include <variant>
#include <string_view>
#include <ankerl/svector.h>
#include "characteristic/characteristic.hpp"
// helper type for the visitor
template<typename... Ts>
struct overloaded : Ts ... { using Ts::operator()...; };
template<typename... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
namespace character {
class CharacterSheet;
enum class weapons : std::uint8_t {
Sword = 0,
Lance = 1,
Morgenstern = 2,
Bow = 3
};
enum class equipments : std::uint8_t {
Chainmail = 4,
CookingPot = 5,
PamphletTourist = 6,
MedicKit = 7
};
enum class tools : std::uint8_t {
Fourche = 8,
Dagger = 9,
RockClimbingKit = 10,
SackOfGrain = 11
};
class BillyObjects final {
public:
static constexpr std::size_t max_num_obj{ 3 };
using billyObject = std::variant<weapons, equipments, tools>;
using container = ankerl::svector<billyObject, max_num_obj>;
static constexpr std::array<BillyObjects::billyObject, 12> all_objects{
weapons::Sword,
weapons::Lance,
weapons::Morgenstern,
weapons::Bow,
equipments::Chainmail,
equipments::CookingPot,
equipments::PamphletTourist,
equipments::MedicKit,
tools::Fourche,
tools::Dagger,
tools::RockClimbingKit,
tools::SackOfGrain,
};
static constexpr std::string_view json_key{ "billy_objects" };
static constexpr std::string_view sword{ "Sword" };
static constexpr std::string_view lance{ "Lance" };
static constexpr std::string_view morgenstern{ "Morgenstern" };
static constexpr std::string_view bow{ "Bow" };
static constexpr std::string_view chainmail{ "Chainmail" };
static constexpr std::string_view cooking_pot{ "Cooking pot" };
static constexpr std::string_view pamphlet_tourist{ "Touristic pamphlet" };
static constexpr std::string_view medic_kit{ "Medic kit" };
static constexpr std::string_view fourche{ "Fourche" };
static constexpr std::string_view dagger{ "Dagger" };
static constexpr std::string_view rock_climbing_kit{ "Rock climbing kit" };
static constexpr std::string_view sack_of_grain{ "Sack of grain" };
static std::string_view billy_object_to_string(const billyObject &object) noexcept;
static void to_json(json &j, const BillyObjects::container &billy);
static void from_json(const json &j, BillyObjects::container &billy);
BillyObjects() noexcept = default;
~BillyObjects() noexcept = default;
[[nodiscard]] bool push_object(const billyObject &object, CharacterSheet &sheet) noexcept;
void pop_object(CharacterSheet &sheet) noexcept;
[[nodiscard]] static ankerl::svector<bool, 3> check_conformity(const CharacterSheet &sheet) noexcept;
[[nodiscard]] const std::plus<std::uint32_t> &get_plus_operation() const { return plus; }
[[nodiscard]] const std::minus<std::uint32_t> &get_minus_operation() const { return minus; }
private:
std::plus<std::uint32_t> plus;
std::minus<std::uint32_t> minus;
static void change_carac_weapon(const weapons &arg,
CharacterSheet &sheet,
characteristic::Characteristic &localHabilete,
characteristic::Characteristic &localAdresse,
characteristic::Characteristic &localEndurance,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation) noexcept;
static void change_carac_equipment(const equipments &arg,
CharacterSheet &sheet,
characteristic::Characteristic &localHabilete,
characteristic::Characteristic &localAdresse,
characteristic::Characteristic &localEndurance,
characteristic::Characteristic &localChance,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &primary,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &complement) noexcept;
static void change_carac_tools(const tools &arg,
CharacterSheet &sheet,
characteristic::Characteristic &localHabilete,
characteristic::Characteristic &localAdresse,
characteristic::Characteristic &localEndurance,
characteristic::Characteristic &localChance,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation) noexcept;
static void check_dagger_conditions(const CharacterSheet &sheet,
characteristic::Characteristic &localHabilete,
const std::function<std::uint32_t(std::uint32_t, std::uint32_t)> &operation);
};
}
#endif //BILLYSHEET_BILLY_OBJECTS_HPP