Feature: adding matériel to Billy.

No conformity is done when adding things (dagger or bow for example)
This commit is contained in:
Pcornat 2024-09-02 12:46:04 +02:00
parent 6ad47b12bf
commit 75f8db9f5a
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
6 changed files with 124 additions and 37 deletions

View file

@ -49,6 +49,21 @@ namespace character {
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" };
@ -76,7 +91,7 @@ namespace character {
~BillyObjects() noexcept = default;
void push_object(const billyObject &object, CharacterSheet &sheet) noexcept;
[[nodiscard]] bool push_object(const billyObject &object, CharacterSheet &sheet) noexcept;
void pop_object(CharacterSheet &sheet) noexcept;

View file

@ -5,7 +5,9 @@
#include "characteristic/endurance.hpp"
#include "characteristic/chance.hpp"
#include "characteristic/habilete.hpp"
#include "billy_objects.hpp"
#include <random>
#include <unordered_set>
namespace gui {
class Gui;
@ -23,7 +25,7 @@ namespace character {
private:
friend gui::Gui;
friend class BillyObjects;
friend BillyObjects;
std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
@ -39,6 +41,13 @@ namespace character {
characteristic::Habilete habilete;
BillyObjects::container objects;
std::unordered_set<BillyObjects::billyObject> available_objects{
BillyObjects::all_objects.cbegin(),
BillyObjects::all_objects.cend()
};
std::uint32_t health_point{ 0 };
std::uint32_t armor{ 0 };
@ -79,6 +88,8 @@ namespace character {
[[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; }
[[nodiscard]] const BillyObjects::container &get_objects() const { return objects; }
[[nodiscard]] classe get_current_class() const {
if (nb_weapons >= 2) {
return classe::Guerrier;
@ -121,6 +132,7 @@ namespace character {
j.at("nb_weapons").get_to(billy.nb_weapons);
j.at("nb_equipments").get_to(billy.nb_equipments);
j.at("nb_tools").get_to(billy.nb_tools);
BillyObjects::from_json(j.at(BillyObjects::json_key), billy.objects);
}
};
@ -139,6 +151,8 @@ namespace character {
j["nb_weapons"] = billy.get_nb_weapons();
j["nb_equipments"] = billy.get_nb_equipments();
j["nb_tools"] = billy.get_nb_tools();
j.emplace(std::pair{ BillyObjects::json_key, json::array() });
BillyObjects::to_json(j.at(BillyObjects::json_key), billy.get_objects());
}
}

View file

@ -3,6 +3,7 @@
#include <filesystem>
#include "gui/menu/menu.hpp"
#include "billy_objects.hpp"
namespace fs = std::filesystem;
@ -24,6 +25,8 @@ namespace gui {
private:
GuiData &data;
character::BillyObjects deal_objects{};
menu::Menu menu;
const fs::path font;