Feature: adding matériel to Billy.
No conformity is done when adding things (dagger or bow for example)
This commit is contained in:
parent
6ad47b12bf
commit
75f8db9f5a
@ -148,21 +148,7 @@ TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("[D] Printing Billy's objects", "[printing]") {
|
TEST_CASE("[D] Printing Billy's objects", "[printing]") {
|
||||||
constexpr std::array<BillyObjects::billyObject, 12> all_objects{
|
for (const auto &object: BillyObjects::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,
|
|
||||||
};
|
|
||||||
for (const auto &object: all_objects) {
|
|
||||||
REQUIRE_NOTHROW(BillyObjects::billy_object_to_string(object));
|
REQUIRE_NOTHROW(BillyObjects::billy_object_to_string(object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,21 @@ namespace character {
|
|||||||
using billyObject = std::variant<weapons, equipments, tools>;
|
using billyObject = std::variant<weapons, equipments, tools>;
|
||||||
using container = ankerl::svector<billyObject, max_num_obj>;
|
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 json_key{ "billy_objects" };
|
||||||
|
|
||||||
static constexpr std::string_view sword{ "Sword" };
|
static constexpr std::string_view sword{ "Sword" };
|
||||||
@ -76,7 +91,7 @@ namespace character {
|
|||||||
|
|
||||||
~BillyObjects() noexcept = default;
|
~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;
|
void pop_object(CharacterSheet &sheet) noexcept;
|
||||||
|
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
#include "characteristic/endurance.hpp"
|
#include "characteristic/endurance.hpp"
|
||||||
#include "characteristic/chance.hpp"
|
#include "characteristic/chance.hpp"
|
||||||
#include "characteristic/habilete.hpp"
|
#include "characteristic/habilete.hpp"
|
||||||
|
#include "billy_objects.hpp"
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class Gui;
|
class Gui;
|
||||||
@ -23,7 +25,7 @@ namespace character {
|
|||||||
private:
|
private:
|
||||||
friend gui::Gui;
|
friend gui::Gui;
|
||||||
|
|
||||||
friend class BillyObjects;
|
friend BillyObjects;
|
||||||
|
|
||||||
std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
|
std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
|
||||||
|
|
||||||
@ -39,6 +41,13 @@ namespace character {
|
|||||||
|
|
||||||
characteristic::Habilete habilete;
|
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 health_point{ 0 };
|
||||||
|
|
||||||
std::uint32_t armor{ 0 };
|
std::uint32_t armor{ 0 };
|
||||||
@ -79,6 +88,8 @@ namespace character {
|
|||||||
|
|
||||||
[[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; }
|
[[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; }
|
||||||
|
|
||||||
|
[[nodiscard]] const BillyObjects::container &get_objects() const { return objects; }
|
||||||
|
|
||||||
[[nodiscard]] classe get_current_class() const {
|
[[nodiscard]] classe get_current_class() const {
|
||||||
if (nb_weapons >= 2) {
|
if (nb_weapons >= 2) {
|
||||||
return classe::Guerrier;
|
return classe::Guerrier;
|
||||||
@ -121,6 +132,7 @@ namespace character {
|
|||||||
j.at("nb_weapons").get_to(billy.nb_weapons);
|
j.at("nb_weapons").get_to(billy.nb_weapons);
|
||||||
j.at("nb_equipments").get_to(billy.nb_equipments);
|
j.at("nb_equipments").get_to(billy.nb_equipments);
|
||||||
j.at("nb_tools").get_to(billy.nb_tools);
|
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_weapons"] = billy.get_nb_weapons();
|
||||||
j["nb_equipments"] = billy.get_nb_equipments();
|
j["nb_equipments"] = billy.get_nb_equipments();
|
||||||
j["nb_tools"] = billy.get_nb_tools();
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "gui/menu/menu.hpp"
|
#include "gui/menu/menu.hpp"
|
||||||
|
#include "billy_objects.hpp"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@ -24,6 +25,8 @@ namespace gui {
|
|||||||
private:
|
private:
|
||||||
GuiData &data;
|
GuiData &data;
|
||||||
|
|
||||||
|
character::BillyObjects deal_objects{};
|
||||||
|
|
||||||
menu::Menu menu;
|
menu::Menu menu;
|
||||||
|
|
||||||
const fs::path font;
|
const fs::path font;
|
||||||
|
@ -17,9 +17,10 @@ constexpr std::uint32_t toolsHash = const_hash("tools");
|
|||||||
namespace character {
|
namespace character {
|
||||||
using characteristic::Characteristic;
|
using characteristic::Characteristic;
|
||||||
|
|
||||||
void BillyObjects::push_object(const billyObject &object, CharacterSheet &sheet) noexcept {
|
bool BillyObjects::push_object(const billyObject &object, CharacterSheet &sheet) noexcept {
|
||||||
if (sheet.objects.size() < 3) {
|
if (sheet.objects.size() < 3) {
|
||||||
sheet.objects.emplace_back(object);
|
sheet.objects.emplace_back(object);
|
||||||
|
sheet.available_objects.erase(object);
|
||||||
|
|
||||||
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
|
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
|
||||||
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);
|
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);
|
||||||
@ -53,13 +54,16 @@ namespace character {
|
|||||||
plus);
|
plus);
|
||||||
},
|
},
|
||||||
}, object);
|
}, object);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BillyObjects::pop_object(CharacterSheet &sheet) noexcept {
|
void BillyObjects::pop_object(CharacterSheet &sheet) noexcept {
|
||||||
if (!sheet.objects.empty()) {
|
if (!sheet.objects.empty()) {
|
||||||
const billyObject obj = sheet.objects.back();
|
const billyObject obj = sheet.objects.back();
|
||||||
sheet.objects.pop_back();
|
sheet.objects.pop_back();
|
||||||
|
sheet.available_objects.insert(obj);
|
||||||
|
|
||||||
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
|
auto &local_habilete = static_cast<Characteristic &>(sheet.habilete);
|
||||||
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);
|
auto &local_adresse = static_cast<Characteristic &>(sheet.adresse);
|
||||||
@ -109,6 +113,7 @@ namespace character {
|
|||||||
localEndurance.materiel = operation(localEndurance.materiel, 3);
|
localEndurance.materiel = operation(localEndurance.materiel, 3);
|
||||||
break;
|
break;
|
||||||
case tools::Dagger:
|
case tools::Dagger:
|
||||||
|
sheet.critique = operation(sheet.critique, 6);
|
||||||
break;
|
break;
|
||||||
case tools::RockClimbingKit:
|
case tools::RockClimbingKit:
|
||||||
localAdresse.materiel = operation(localAdresse.materiel, 1);
|
localAdresse.materiel = operation(localAdresse.materiel, 1);
|
||||||
|
102
src/gui/gui.cpp
102
src/gui/gui.cpp
@ -174,32 +174,96 @@ void gui::Gui::stat_second_menu() noexcept {
|
|||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename MaterielEnum>
|
||||||
|
constexpr std::string_view combo_label() {
|
||||||
|
using character::weapons;
|
||||||
|
using character::equipments;
|
||||||
|
using character::tools;
|
||||||
|
if constexpr (std::is_same_v<MaterielEnum, weapons>) {
|
||||||
|
return "Weapons";
|
||||||
|
} else if constexpr (std::is_same_v<MaterielEnum, equipments>) {
|
||||||
|
return "Equipments";
|
||||||
|
} else {
|
||||||
|
return "Tools";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename MaterielEnum>
|
||||||
|
constexpr std::string_view material_child_win_id() {
|
||||||
|
using character::weapons;
|
||||||
|
using character::equipments;
|
||||||
|
using character::tools;
|
||||||
|
if constexpr (std::is_same_v<MaterielEnum, weapons>) {
|
||||||
|
return "weapons";
|
||||||
|
} else if constexpr (std::is_same_v<MaterielEnum, equipments>) {
|
||||||
|
return "equipments";
|
||||||
|
} else {
|
||||||
|
return "tools";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename MaterielEnum>
|
||||||
|
void generic_combo_menu(character::CharacterSheet &billy,
|
||||||
|
std::unordered_set<character::BillyObjects::billyObject> &availableObjects,
|
||||||
|
character::BillyObjects &dealObjects) noexcept {
|
||||||
|
using character::BillyObjects;
|
||||||
|
|
||||||
|
static auto selected = std::find_if(availableObjects.cbegin(), availableObjects.cend(), [](const auto &billyObj) {
|
||||||
|
return std::holds_alternative<MaterielEnum>(billyObj);
|
||||||
|
});
|
||||||
|
ImGui::BeginChild(material_child_win_id<MaterielEnum>().data(),
|
||||||
|
ImVec2(ImGui::GetWindowWidth(), 0),
|
||||||
|
ImGuiChildFlags_AutoResizeY);
|
||||||
|
if (ImGui::BeginCombo(combo_label<MaterielEnum>().data(),
|
||||||
|
BillyObjects::billy_object_to_string(*selected).data(),
|
||||||
|
ImGuiComboFlags_WidthFitPreview | ImGuiComboFlags_PopupAlignLeft)) {
|
||||||
|
for (auto iterator = availableObjects.cbegin();
|
||||||
|
iterator != availableObjects.cend(); ++iterator) {
|
||||||
|
if (!std::holds_alternative<MaterielEnum>(*iterator)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const bool is_selected = selected == iterator;
|
||||||
|
|
||||||
|
if (ImGui::Selectable(BillyObjects::billy_object_to_string(*iterator).data(), is_selected)) {
|
||||||
|
selected = iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_selected) {
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndCombo();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("+")) {
|
||||||
|
if (dealObjects.push_object(*selected, billy)) {
|
||||||
|
selected = std::find_if(availableObjects.cbegin(),
|
||||||
|
availableObjects.cend(),
|
||||||
|
[](const auto &billyObj) { return std::holds_alternative<MaterielEnum>(billyObj); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
void gui::Gui::materiel_menu() noexcept {
|
void gui::Gui::materiel_menu() noexcept {
|
||||||
|
using character::BillyObjects;
|
||||||
|
|
||||||
ImGui::BeginChild("materiel",
|
ImGui::BeginChild("materiel",
|
||||||
ImVec2(ImGui::GetWindowWidth() / 3, 0),
|
ImVec2(ImGui::GetWindowWidth() / 3, 0),
|
||||||
ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY);
|
ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY);
|
||||||
ImGui::Text("Matériel");
|
ImGui::Text("Matériel");
|
||||||
|
|
||||||
ImGui::BeginChild("weapons", ImVec2(0, 0), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY);
|
generic_combo_menu<character::weapons>(data.billy, data.billy.available_objects, deal_objects);
|
||||||
ImGui::Text(character::BillyObjects::sword.data());
|
generic_combo_menu<character::equipments>(data.billy, data.billy.available_objects, deal_objects);
|
||||||
ImGui::Text(character::BillyObjects::lance.data());
|
generic_combo_menu<character::tools>(data.billy, data.billy.available_objects, deal_objects);
|
||||||
ImGui::Text(character::BillyObjects::morgenstern.data());
|
|
||||||
ImGui::Text(character::BillyObjects::bow.data());
|
|
||||||
ImGui::EndChild();
|
|
||||||
|
|
||||||
ImGui::BeginChild("equipments", ImVec2(0, 0), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY);
|
for (const auto &object: data.billy.get_objects()) {
|
||||||
ImGui::Text(character::BillyObjects::chainmail.data());
|
ImGui::Text("%s", BillyObjects::billy_object_to_string(object).data());
|
||||||
ImGui::Text(character::BillyObjects::cooking_pot.data());
|
}
|
||||||
ImGui::Text(character::BillyObjects::pamphlet_tourist.data());
|
if (ImGui::Button("Remove last object")) {
|
||||||
ImGui::Text(character::BillyObjects::medic_kit.data());
|
deal_objects.pop_object(data.billy);
|
||||||
ImGui::EndChild();
|
}
|
||||||
|
|
||||||
ImGui::BeginChild("tools", ImVec2(0, 0), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY);
|
|
||||||
ImGui::Text(character::BillyObjects::fourche.data());
|
|
||||||
ImGui::Text(character::BillyObjects::dagger.data());
|
|
||||||
ImGui::Text(character::BillyObjects::rock_climbing_kit.data());
|
|
||||||
ImGui::Text(character::BillyObjects::sack_of_grain.data());
|
|
||||||
ImGui::EndChild();
|
|
||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user