BillySheet/include/billy_objects.hpp
2026-02-27 22:10:35 +01:00

101 lines
3.1 KiB
C++

//
// Created by postaron on 20/02/24.
//
#ifndef BILLYSHEET_BILLY_OBJECTS_HPP
#define BILLYSHEET_BILLY_OBJECTS_HPP
#include <array>
#include <cstdint>
#include <functional>
#include <string_view>
#include <unordered_map>
#include <variant>
#include <nlohmann/json_fwd.hpp>
#include "generic_object.hpp"
namespace character {
class CharacterSheet;
namespace characteristic {
class Characteristic;
}
class BillyObjects final {
public:
using json = nlohmann::json;
using container = std::unordered_map<billyEnums, billyObjects>;
static constexpr std::array<billyEnums, 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::uint32_t max_obj{ 3 };
static std::string_view billy_object_to_string(const billyObjects &object) noexcept;
static std::string_view billy_object_to_string(const billyEnums &object) noexcept;
static void to_json(json &j, const container &billy);
static void from_json(const json &j, container &billy);
/*!
* \brief It inserts the object inside the sheet.
*
* This method changes values inside the sheet according to the book's rules.
* \param sheet sheet to insert object into
* \param objType the object to insert
* \return true: object inserted, false otherwise
*/
[[nodiscard]] bool insert_object(CharacterSheet &sheet, const billyEnums objType) noexcept;
/*!
* \brief
* \param sheet sheet to erase object from
* \param objToErase the object to erase
* \return true: object erased, false otherwise
*/
[[nodiscard]] bool erase_object(CharacterSheet &sheet, const billyEnums objToErase) noexcept;
[[nodiscard]] static bool is_full(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; }
static void check_dagger_conditions(CharacterSheet &sheet);
private:
std::plus<std::uint32_t> plus;
std::minus<std::uint32_t> minus;
/*!
* \brief
* \param arg object used to change values
* \param sheet sheet to change
* \param operation Operation to apply to change values
*/
static void change_carac(const billyObjects &arg,
CharacterSheet &sheet,
const std::function<uint32_t(uint32_t, uint32_t)> &operation) noexcept;
};
}
#endif //BILLYSHEET_BILLY_OBJECTS_HPP