Reformat.

This commit is contained in:
Pcornat 2024-01-28 20:31:50 +01:00
parent 7d1a0473ff
commit 2755f4827e
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD
24 changed files with 6140 additions and 5829 deletions

View File

@ -14,7 +14,7 @@ set(PRECOMPILE_HEADERS
include/gui/gui.hpp include/gui/gui.hpp
include/gui/gui_data.hpp include/gui/gui_data.hpp
include/gui/window.hpp include/gui/window.hpp
) )
set(SOURCE_HEADERS set(SOURCE_HEADERS
include/imgui/imconfig.h include/imgui/imconfig.h
@ -42,7 +42,7 @@ set(SOURCE_HEADERS
include/characteristic/characteristic.hpp include/characteristic/characteristic.hpp
include/controller.hpp include/controller.hpp
include/gui_data_interface.hpp include/gui_data_interface.hpp
) )
set(SOURCE_FILES set(SOURCE_FILES
src/imgui/imgui.cpp src/imgui/imgui.cpp
@ -63,7 +63,7 @@ set(SOURCE_FILES
src/characteristic/chance.cpp src/characteristic/chance.cpp
src/gui/menu/menu.cpp src/gui/menu/menu.cpp
src/controller.cpp src/controller.cpp
) )
set(SOURCES set(SOURCES
${SOURCE_HEADERS} ${SOURCE_HEADERS}
@ -123,16 +123,16 @@ set(COMPILE_FLAGS
-funroll-loops -funroll-loops
-fdevirtualize-at-ltrans -fdevirtualize-at-ltrans
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
) )
set(LINKER_OPTIONS set(LINKER_OPTIONS
-Wl,--sort-common,--as-needed,--gc-sections,--strip-all -Wl,--sort-common,--as-needed,--gc-sections,--strip-all
-fuse-ld=gold -fuse-ld=gold
-fdevirtualize-at-ltrans -fdevirtualize-at-ltrans
) )
set(LINKER_FLAGS set(LINKER_FLAGS
jemalloc jemalloc
) )
option(ENABLE_COVERAGE "Enabling coverage" OFF) option(ENABLE_COVERAGE "Enabling coverage" OFF)
@ -155,7 +155,7 @@ set_target_properties(BillySheet spdlog PROPERTIES
CXX_EXTENSIONS OFF CXX_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION ON
# UNITY_BUILD ON # UNITY_BUILD ON
) )
set_target_properties(spdlog PROPERTIES UNITY_BUILD ON) set_target_properties(spdlog PROPERTIES UNITY_BUILD ON)
@ -165,7 +165,7 @@ set_target_properties(glfw PROPERTIES
C_EXTENSIONS OFF C_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION ON
UNITY_BUILD ON UNITY_BUILD ON
) )
set_target_properties(spdlog PROPERTIES UNITY_BUILD ON) set_target_properties(spdlog PROPERTIES UNITY_BUILD ON)

View File

@ -7,12 +7,12 @@ include(../external/catch2/contrib/Catch.cmake)
add_executable(UnitTest adummy.cpp characteristics_tests.cpp) add_executable(UnitTest adummy.cpp characteristics_tests.cpp)
set_target_properties(Catch2 UnitTest PROPERTIES set_target_properties(Catch2 UnitTest PROPERTIES
CXX_STANDARD 17 CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF CXX_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION ON
# UNITY_BUILD ON # UNITY_BUILD ON
) )
target_include_directories(UnitTest PRIVATE ${CMAKE_SOURCE_DIR}/include) target_include_directories(UnitTest PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_compile_definitions(UnitTest PRIVATE ${DEF_COMP}) target_compile_definitions(UnitTest PRIVATE ${DEF_COMP})
target_compile_options(UnitTest PRIVATE ${COMPILE_FLAGS}) target_compile_options(UnitTest PRIVATE ${COMPILE_FLAGS})

View File

@ -1,2 +1,3 @@
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp> #include <catch2/catch.hpp>

View File

@ -8,137 +8,137 @@
using namespace character::characteristic; using namespace character::characteristic;
TEST_CASE("[A] Serialize adresse", "[serialize][0]") { TEST_CASE("[A] Serialize adresse", "[serialize][0]") {
Adresse adresse; Adresse adresse;
json serializer; json serializer;
REQUIRE_NOTHROW(serializer.emplace("adresse", adresse)); REQUIRE_NOTHROW(serializer.emplace("adresse", adresse));
const auto &tester = serializer.at("adresse"); const auto &tester = serializer.at("adresse");
REQUIRE_NOTHROW(tester.at("base") == 1); REQUIRE_NOTHROW(tester.at("base") == 1);
REQUIRE_NOTHROW(tester.at("carac") == 0); REQUIRE_NOTHROW(tester.at("carac") == 0);
REQUIRE_NOTHROW(tester.at("materiel") == 0); REQUIRE_NOTHROW(tester.at("materiel") == 0);
REQUIRE_NOTHROW(tester.at("additional") == 0); REQUIRE_NOTHROW(tester.at("additional") == 0);
{ {
std::ofstream file{ "adresse.json" }; std::ofstream file{ "adresse.json" };
file << serializer << std::flush; file << serializer << std::flush;
} }
} }
TEST_CASE("[A] Serialize chance", "[serialize][1]") { TEST_CASE("[A] Serialize chance", "[serialize][1]") {
Chance chance; Chance chance;
json serializer; json serializer;
REQUIRE_NOTHROW(serializer.emplace("chance", chance)); REQUIRE_NOTHROW(serializer.emplace("chance", chance));
const auto &tester = serializer.at("chance"); const auto &tester = serializer.at("chance");
REQUIRE_NOTHROW(tester.at("base") == 3); REQUIRE_NOTHROW(tester.at("base") == 3);
REQUIRE_NOTHROW(tester.at("carac") == 0); REQUIRE_NOTHROW(tester.at("carac") == 0);
REQUIRE_NOTHROW(tester.at("materiel") == 0); REQUIRE_NOTHROW(tester.at("materiel") == 0);
REQUIRE_NOTHROW(tester.at("additional") == 0); REQUIRE_NOTHROW(tester.at("additional") == 0);
{ {
std::ofstream file{ "chance.json" }; std::ofstream file{ "chance.json" };
file << serializer << std::flush; file << serializer << std::flush;
} }
} }
TEST_CASE("[A] Serialize endurance", "[serialize][2]") { TEST_CASE("[A] Serialize endurance", "[serialize][2]") {
Endurance endurance; Endurance endurance;
json serializer; json serializer;
REQUIRE_NOTHROW(serializer.emplace("endurance", endurance)); REQUIRE_NOTHROW(serializer.emplace("endurance", endurance));
const auto &tester = serializer.at("endurance"); const auto &tester = serializer.at("endurance");
REQUIRE_NOTHROW(tester.at("base") == 2); REQUIRE_NOTHROW(tester.at("base") == 2);
REQUIRE_NOTHROW(tester.at("carac") == 0); REQUIRE_NOTHROW(tester.at("carac") == 0);
REQUIRE_NOTHROW(tester.at("materiel") == 0); REQUIRE_NOTHROW(tester.at("materiel") == 0);
REQUIRE_NOTHROW(tester.at("additional") == 0); REQUIRE_NOTHROW(tester.at("additional") == 0);
{ {
std::ofstream file{ "endurance.json" }; std::ofstream file{ "endurance.json" };
file << serializer << std::flush; file << serializer << std::flush;
} }
} }
TEST_CASE("[A] Serialize habilete", "[serialize][3]") { TEST_CASE("[A] Serialize habilete", "[serialize][3]") {
Habilete habilete; Habilete habilete;
json serializer; json serializer;
REQUIRE_NOTHROW(serializer.emplace("habilete", habilete)); REQUIRE_NOTHROW(serializer.emplace("habilete", habilete));
const auto &tester = serializer.at("habilete"); const auto &tester = serializer.at("habilete");
REQUIRE_NOTHROW(tester.at("base") == 2); REQUIRE_NOTHROW(tester.at("base") == 2);
REQUIRE_NOTHROW(tester.at("carac") == 0); REQUIRE_NOTHROW(tester.at("carac") == 0);
REQUIRE_NOTHROW(tester.at("materiel") == 0); REQUIRE_NOTHROW(tester.at("materiel") == 0);
REQUIRE_NOTHROW(tester.at("additional") == 0); REQUIRE_NOTHROW(tester.at("additional") == 0);
{ {
std::ofstream file{ "habilete.json" }; std::ofstream file{ "habilete.json" };
file << serializer << std::flush; file << serializer << std::flush;
} }
} }
TEST_CASE("[B] Deserialize adresse", "[deserialize][0]") { TEST_CASE("[B] Deserialize adresse", "[deserialize][0]") {
const json deserializer = []() -> json { const json deserializer = []() -> json {
std::ifstream file{ "adresse.json" }; std::ifstream file{ "adresse.json" };
json des = json::parse(file); json des = json::parse(file);
return des; return des;
}(); }();
REQUIRE_NOTHROW([&]() -> void { REQUIRE_NOTHROW([&]() -> void {
const auto adresse = deserializer.at("adresse").get<Adresse>(); const auto adresse = deserializer.at("adresse").get<Adresse>();
REQUIRE(adresse.get_base() == 1); REQUIRE(adresse.get_base() == 1);
REQUIRE(adresse.get_carac() == 0); REQUIRE(adresse.get_carac() == 0);
REQUIRE(adresse.get_materiel() == 0); REQUIRE(adresse.get_materiel() == 0);
REQUIRE(adresse.get_additional() == 0); REQUIRE(adresse.get_additional() == 0);
}()); }());
} }
TEST_CASE("[B] Deserialize chance", "[deserialize][1]") { TEST_CASE("[B] Deserialize chance", "[deserialize][1]") {
const json deserializer = []() -> json { const json deserializer = []() -> json {
std::ifstream file{ "chance.json" }; std::ifstream file{ "chance.json" };
json des = json::parse(file); json des = json::parse(file);
return des; return des;
}(); }();
REQUIRE_NOTHROW([&]() -> void { REQUIRE_NOTHROW([&]() -> void {
const auto adresse = deserializer.at("chance").get<Adresse>(); const auto adresse = deserializer.at("chance").get<Adresse>();
REQUIRE(adresse.get_base() == 3); REQUIRE(adresse.get_base() == 3);
REQUIRE(adresse.get_carac() == 0); REQUIRE(adresse.get_carac() == 0);
REQUIRE(adresse.get_materiel() == 0); REQUIRE(adresse.get_materiel() == 0);
REQUIRE(adresse.get_additional() == 0); REQUIRE(adresse.get_additional() == 0);
}()); }());
} }
TEST_CASE("[B] Deserialize endurance", "[deserialize][2]") { TEST_CASE("[B] Deserialize endurance", "[deserialize][2]") {
const json deserializer = []() -> json { const json deserializer = []() -> json {
std::ifstream file{ "endurance.json" }; std::ifstream file{ "endurance.json" };
json des = json::parse(file); json des = json::parse(file);
return des; return des;
}(); }();
REQUIRE_NOTHROW([&]() -> void { REQUIRE_NOTHROW([&]() -> void {
const auto adresse = deserializer.at("endurance").get<Adresse>(); const auto adresse = deserializer.at("endurance").get<Adresse>();
REQUIRE(adresse.get_base() == 2); REQUIRE(adresse.get_base() == 2);
REQUIRE(adresse.get_carac() == 0); REQUIRE(adresse.get_carac() == 0);
REQUIRE(adresse.get_materiel() == 0); REQUIRE(adresse.get_materiel() == 0);
REQUIRE(adresse.get_additional() == 0); REQUIRE(adresse.get_additional() == 0);
}()); }());
} }
TEST_CASE("[B] Deserialize habilete", "[deserialize][3]") { TEST_CASE("[B] Deserialize habilete", "[deserialize][3]") {
const json deserializer = []() -> json { const json deserializer = []() -> json {
std::ifstream file{ "habilete.json" }; std::ifstream file{ "habilete.json" };
json des = json::parse(file); json des = json::parse(file);
return des; return des;
}(); }();
REQUIRE_NOTHROW([&]() -> void { REQUIRE_NOTHROW([&]() -> void {
const auto adresse = deserializer.at("habilete").get<Adresse>(); const auto adresse = deserializer.at("habilete").get<Adresse>();
REQUIRE(adresse.get_base() == 2); REQUIRE(adresse.get_base() == 2);
REQUIRE(adresse.get_carac() == 0); REQUIRE(adresse.get_carac() == 0);
REQUIRE(adresse.get_materiel() == 0); REQUIRE(adresse.get_materiel() == 0);
REQUIRE(adresse.get_additional() == 0); REQUIRE(adresse.get_additional() == 0);
}()); }());
} }

View File

@ -8,101 +8,109 @@
#include <random> #include <random>
namespace gui { namespace gui {
class Gui; class Gui;
} }
namespace character { namespace character {
enum class classe : std::uint32_t { enum class classe : std::uint8_t {
Guerrier = 0, Guerrier = 0,
Prudent = 1, Prudent = 1,
Paysan = 2, Paysan = 2,
Debrouillard = 3, Debrouillard = 3,
}; };
class CharacterSheet final { class CharacterSheet final {
private: private:
friend gui::Gui; friend gui::Gui;
friend class Controller; friend class Controller;
std::mt19937_64 engine{ std::random_device{ "rdseed" }() }; std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
std::string caractere{}; std::string caractere{};
characteristic::Adresse adresse; characteristic::Adresse adresse;
characteristic::Endurance endurance; characteristic::Endurance endurance;
characteristic::Chance chance; characteristic::Chance chance;
characteristic::Habilete habilete; characteristic::Habilete habilete;
classe current_class{ classe::Guerrier }; classe current_class{ classe::Guerrier };
std::uint32_t health_point{ 0 }; std::uint32_t health_point{ 0 };
std::uint32_t armor{ 0 }; std::uint32_t armor{ 0 };
std::uint32_t damage{ 0 }; std::uint32_t damage{ 0 };
std::uint32_t glory{ 0 }; std::uint32_t glory{ 0 };
std::uint32_t money{ 0 }; std::uint32_t money{ 0 };
public: public:
CharacterSheet() = default; CharacterSheet() = default;
~CharacterSheet() noexcept = default; CharacterSheet(const CharacterSheet &sheet) noexcept = default;
[[nodiscard]] const std::string &get_caractere() const { return caractere; } CharacterSheet(CharacterSheet &&sheet) noexcept = default;
[[nodiscard]] const characteristic::Adresse &get_adresse() const { return adresse; } CharacterSheet &operator=(const CharacterSheet &characterSheet) noexcept = default;
[[nodiscard]] const characteristic::Endurance &get_endurance() const { return endurance; } CharacterSheet &operator=(CharacterSheet &&characterSheet) noexcept = default;
[[nodiscard]] const characteristic::Chance &get_chance() const { return chance; } ~CharacterSheet() noexcept = default;
[[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; } [[nodiscard]] const std::string &get_caractere() const { return caractere; }
[[nodiscard]] classe get_current_class() const { return current_class; } [[nodiscard]] const characteristic::Adresse &get_adresse() const { return adresse; }
[[nodiscard]] std::uint32_t get_health_point() const { return health_point; } [[nodiscard]] const characteristic::Endurance &get_endurance() const { return endurance; }
[[nodiscard]] std::uint32_t get_armor() const { return armor; } [[nodiscard]] const characteristic::Chance &get_chance() const { return chance; }
[[nodiscard]] std::uint32_t get_damage() const { return damage; } [[nodiscard]] const characteristic::Habilete &get_habilete() const { return habilete; }
[[nodiscard]] std::uint32_t get_glory() const { return glory; } [[nodiscard]] classe get_current_class() const { return current_class; }
[[nodiscard]] std::uint32_t get_money() const { return money; } [[nodiscard]] std::uint32_t get_health_point() const { return health_point; }
friend void from_json(const json &j, CharacterSheet &billy) { [[nodiscard]] std::uint32_t get_armor() const { return armor; }
j.at("caractere").get_to(billy.caractere);
j.at("adresse").get_to(billy.adresse);
j.at("endurance").get_to(billy.endurance);
j.at("chance").get_to(billy.chance);
j.at("habilete").get_to(billy.habilete);
j.at("classe").get_to(billy.current_class);
j.at("health_point").get_to(billy.health_point);
j.at("armor").get_to(billy.armor);
j.at("damage").get_to(billy.damage);
j.at("glory").get_to(billy.glory);
j.at("money").get_to(billy.money);
}
};
static void to_json(json &j, const CharacterSheet &billy) { [[nodiscard]] std::uint32_t get_damage() const { return damage; }
j["caractere"] = billy.get_caractere();
j["adresse"] = billy.get_adresse(); [[nodiscard]] std::uint32_t get_glory() const { return glory; }
j["endurance"] = billy.get_endurance();
j["chance"] = billy.get_chance(); [[nodiscard]] std::uint32_t get_money() const { return money; }
j["habilete"] = billy.get_habilete();
j["classe"] = billy.get_current_class(); friend void from_json(const json &j, CharacterSheet &billy) {
j["health_point"] = billy.get_health_point(); j.at("caractere").get_to(billy.caractere);
j["armor"] = billy.get_armor(); j.at("adresse").get_to(billy.adresse);
j["damage"] = billy.get_damage(); j.at("endurance").get_to(billy.endurance);
j["glory"] = billy.get_glory(); j.at("chance").get_to(billy.chance);
j["money"] = billy.get_money(); j.at("habilete").get_to(billy.habilete);
} j.at("classe").get_to(billy.current_class);
j.at("health_point").get_to(billy.health_point);
j.at("armor").get_to(billy.armor);
j.at("damage").get_to(billy.damage);
j.at("glory").get_to(billy.glory);
j.at("money").get_to(billy.money);
}
};
static void to_json(json &j, const CharacterSheet &billy) {
j["caractere"] = billy.get_caractere();
j["adresse"] = billy.get_adresse();
j["endurance"] = billy.get_endurance();
j["chance"] = billy.get_chance();
j["habilete"] = billy.get_habilete();
j["classe"] = billy.get_current_class();
j["health_point"] = billy.get_health_point();
j["armor"] = billy.get_armor();
j["damage"] = billy.get_damage();
j["glory"] = billy.get_glory();
j["money"] = billy.get_money();
}
} }

View File

@ -7,20 +7,20 @@
using json = nlohmann::json; using json = nlohmann::json;
namespace character::characteristic { namespace character::characteristic {
class Adresse final : public Characteristic { class Adresse final : public Characteristic {
public: public:
Adresse() noexcept: Characteristic(1, 0, 0, 0) {} Adresse() noexcept: Characteristic(1, 0, 0, 0) {}
~Adresse() noexcept final = default; ~Adresse() noexcept final = default;
friend void from_json(const json &j, Adresse &adresse) { friend void from_json(const json &j, Adresse &adresse) {
nlohmann::from_json(j, static_cast<Characteristic &>(adresse)); nlohmann::from_json(j, static_cast<Characteristic &>(adresse));
} }
}; };
static void to_json(json &j, const Adresse &adresse) { static void to_json(json &j, const Adresse &adresse) {
to_json(j, static_cast<Characteristic>(adresse)); to_json(j, static_cast<Characteristic>(adresse));
} }
} }

View File

@ -4,20 +4,20 @@
#include "characteristic.hpp" #include "characteristic.hpp"
namespace character::characteristic { namespace character::characteristic {
class Chance final : public Characteristic { class Chance final : public Characteristic {
public: public:
Chance() noexcept: Characteristic(3, 0, 0, 0) {} Chance() noexcept: Characteristic(3, 0, 0, 0) {}
~Chance() noexcept final = default; ~Chance() noexcept final = default;
friend void from_json(const json &j, Chance &chance) { friend void from_json(const json &j, Chance &chance) {
nlohmann::from_json(j, static_cast<Characteristic &>(chance)); nlohmann::from_json(j, static_cast<Characteristic &>(chance));
} }
}; };
static void to_json(json &j, const Chance &chance) { static void to_json(json &j, const Chance &chance) {
to_json(j, static_cast<Characteristic>(chance)); to_json(j, static_cast<Characteristic>(chance));
} }
} }

View File

@ -7,53 +7,56 @@
using json = nlohmann::json; using json = nlohmann::json;
namespace character::characteristic { namespace character::characteristic {
class Characteristic { class Characteristic {
protected: protected:
const std::uint32_t base{ 0 }; const std::uint32_t base{ 0 };
std::uint32_t carac{ 0 }; std::uint32_t carac{ 0 };
std::uint32_t materiel{ 0 }; std::uint32_t materiel{ 0 };
std::uint32_t additional{ 0 }; std::uint32_t additional{ 0 };
public: public:
Characteristic() noexcept = default; Characteristic() noexcept = default;
Characteristic(const std::uint32_t base, const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) noexcept: Characteristic(const std::uint32_t base,
base(base), carac(carac), materiel(materiel), additional(additional) {} const std::uint32_t carac,
const std::uint32_t materiel,
const std::uint32_t additional) noexcept:
base(base), carac(carac), materiel(materiel), additional(additional) {}
Characteristic(const Characteristic &charac) noexcept = default; Characteristic(const Characteristic &charac) noexcept = default;
Characteristic &operator=(const Characteristic &charac) noexcept { Characteristic &operator=(const Characteristic &charac) noexcept {
const_cast<std::uint32_t &>(base) = charac.base; const_cast<std::uint32_t &>(base) = charac.base;
carac = charac.carac; carac = charac.carac;
materiel = charac.materiel; materiel = charac.materiel;
additional = charac.additional; additional = charac.additional;
return *this; return *this;
} }
virtual ~Characteristic() noexcept = default; virtual ~Characteristic() noexcept = default;
[[nodiscard]] std::uint32_t get_base() const { return base; } [[nodiscard]] std::uint32_t get_base() const { return base; }
[[nodiscard]] std::uint32_t get_carac() const { return carac; } [[nodiscard]] std::uint32_t get_carac() const { return carac; }
[[nodiscard]] std::uint32_t get_materiel() const { return materiel; } [[nodiscard]] std::uint32_t get_materiel() const { return materiel; }
[[nodiscard]] std::uint32_t get_additional() const { return additional; } [[nodiscard]] std::uint32_t get_additional() const { return additional; }
friend void from_json(const json &j, Characteristic &charac) { 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<std::uint32_t &>(charac.base) = j.at("base").get<std::uint32_t>();
charac.carac = j.at("carac").get<std::uint32_t>(); charac.carac = j.at("carac").get<std::uint32_t>();
charac.materiel = j.at("materiel").get<std::uint32_t>(); charac.materiel = j.at("materiel").get<std::uint32_t>();
charac.additional = j.at("additional").get<std::uint32_t>(); charac.additional = j.at("additional").get<std::uint32_t>();
} }
}; };
static void to_json(json &j, const Characteristic &charac) { static void to_json(json &j, const Characteristic &charac) {
j["base"] = charac.get_base(); j["base"] = charac.get_base();
j["carac"] = charac.get_carac(); j["carac"] = charac.get_carac();
j["materiel"] = charac.get_materiel(); j["materiel"] = charac.get_materiel();
j["additional"] = charac.get_additional(); j["additional"] = charac.get_additional();
} }
} }

View File

@ -7,22 +7,22 @@
using json = nlohmann::json; using json = nlohmann::json;
namespace character::characteristic { namespace character::characteristic {
class Endurance final : public Characteristic { class Endurance final : public Characteristic {
public: public:
Endurance() noexcept: Characteristic(2, 0, 0, 0) {}; Endurance() noexcept: Characteristic(2, 0, 0, 0) {};
~Endurance() noexcept final = default; ~Endurance() noexcept final = default;
[[nodiscard]] std::uint32_t get_max_lp() const noexcept; [[nodiscard]] std::uint32_t get_max_lp() const noexcept;
friend void from_json(const json &j, Endurance &endurance) { friend void from_json(const json &j, Endurance &endurance) {
nlohmann::from_json(j, static_cast<Characteristic &>(endurance)); nlohmann::from_json(j, static_cast<Characteristic &>(endurance));
} }
}; };
static void to_json(json &j, const Endurance &endurance) { static void to_json(json &j, const Endurance &endurance) {
to_json(j, static_cast<Characteristic>(endurance)); to_json(j, static_cast<Characteristic>(endurance));
} }
} }

View File

@ -5,20 +5,20 @@
#include "characteristic.hpp" #include "characteristic.hpp"
namespace character::characteristic { namespace character::characteristic {
class Habilete final : public Characteristic { class Habilete final : public Characteristic {
public: public:
Habilete() noexcept: Characteristic(2, 0, 0, 0) {}; Habilete() noexcept: Characteristic(2, 0, 0, 0) {};
~Habilete() noexcept final = default; ~Habilete() noexcept final = default;
friend void from_json(const json &j, Habilete &habilete) { friend void from_json(const json &j, Habilete &habilete) {
nlohmann::from_json(j, static_cast<Characteristic &>(habilete)); nlohmann::from_json(j, static_cast<Characteristic &>(habilete));
} }
}; };
static void to_json(json &j, const Habilete &habilete) { static void to_json(json &j, const Habilete &habilete) {
to_json(j, static_cast<Characteristic>(habilete)); to_json(j, static_cast<Characteristic>(habilete));
} }
} }

View File

@ -2,28 +2,29 @@
#define BILLYSHEET_CONTROLLER_HPP #define BILLYSHEET_CONTROLLER_HPP
namespace character { namespace character {
class CharacterSheet; class CharacterSheet;
} }
namespace gui::menu { namespace gui::menu {
class MenuData; class MenuData;
} }
class Controller final { class Controller final {
private: private:
character::CharacterSheet &sheet; character::CharacterSheet &sheet;
gui::menu::MenuData &menu_data; gui::menu::MenuData &menu_data;
public: public:
Controller() = delete; Controller() = delete;
explicit Controller(character::CharacterSheet &sheet, gui::menu::MenuData &menuData) : sheet(sheet), menu_data(menuData) {} explicit Controller(character::CharacterSheet &sheet, gui::menu::MenuData &menuData) :
sheet(sheet), menu_data(menuData) {}
~Controller() noexcept = default; ~Controller() noexcept = default;
void control_menu() const noexcept; void control_menu() const noexcept;
void control_sheet()const noexcept; void control_sheet() const noexcept;
}; };

View File

@ -10,49 +10,49 @@ class Controller;
namespace gui { namespace gui {
class GuiData; class GuiData;
class Window; class Window;
namespace menu { class MenuData; } namespace menu { class MenuData; }
class Gui final { class Gui final {
private: private:
GuiData &data; GuiData &data;
menu::Menu menu; menu::Menu menu;
const fs::path font; const fs::path font;
bool initialized{ false }; bool initialized{ false };
void habilete_menu() noexcept; void habilete_menu() noexcept;
void adresse_menu() noexcept; void adresse_menu() noexcept;
void endurance_menu() noexcept; void endurance_menu() noexcept;
void chance_menu() noexcept; void chance_menu() noexcept;
void stat_second_menu() noexcept; void stat_second_menu() noexcept;
void materiel_menu() noexcept; void materiel_menu() noexcept;
void gloire_menu() noexcept; void gloire_menu() noexcept;
void richesse_menu() noexcept; void richesse_menu() noexcept;
public: public:
Gui() = delete; Gui() = delete;
explicit Gui(Window &window, GuiData &data, menu::MenuData &menuData); explicit Gui(Window &window, GuiData &data, menu::MenuData &menuData);
~Gui() noexcept; ~Gui() noexcept;
void render_gui(const Controller &controller); void render_gui(const Controller &controller);
void render_gpu() const; void render_gpu() const;
}; };
} }
#endif //BILLYSHEET_GUI_HPP #endif //BILLYSHEET_GUI_HPP

View File

@ -5,57 +5,57 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
namespace character { namespace character {
class CharacterSheet; class CharacterSheet;
} }
using namespace std::string_view_literals; using namespace std::string_view_literals;
namespace gui { namespace gui {
enum class characChanged { enum class characChanged {
None, None,
Adresse, Adresse,
Endurance, Endurance,
Chance, Chance,
Habilete Habilete
}; };
class GuiData final { class GuiData final {
private: private:
friend class Gui; friend class Gui;
character::CharacterSheet &billy; character::CharacterSheet &billy;
std::pair<characChanged, std::uint32_t> base{ characChanged::None, 0 }; std::pair<characChanged, std::uint32_t> base{ characChanged::None, 0 };
std::pair<characChanged, std::uint32_t> carac{ characChanged::None, 0 }; std::pair<characChanged, std::uint32_t> carac{ characChanged::None, 0 };
std::pair<characChanged, std::uint32_t> materiel{ characChanged::None, 0 }; std::pair<characChanged, std::uint32_t> materiel{ characChanged::None, 0 };
std::pair<characChanged, std::uint32_t> additional{ characChanged::None, 0 }; std::pair<characChanged, std::uint32_t> additional{ characChanged::None, 0 };
public: public:
static constexpr std::array classes{ static constexpr std::array classes{
"Guerrier"sv, "Guerrier"sv,
"Prudent"sv, "Prudent"sv,
"Paysan"sv, "Paysan"sv,
"Débrouillard"sv "Débrouillard"sv
}; };
GuiData() = delete; GuiData() = delete;
explicit GuiData(character::CharacterSheet &billy) noexcept: billy(billy) { SPDLOG_DEBUG("Creating GUI Data"); } explicit GuiData(character::CharacterSheet &billy) noexcept: billy(billy) { SPDLOG_DEBUG("Creating GUI Data"); }
~GuiData() noexcept = default; ~GuiData() noexcept = default;
[[nodiscard]] const std::pair<characChanged, std::uint32_t> &get_base() const { return base; } [[nodiscard]] const std::pair<characChanged, std::uint32_t> &get_base() const { return base; }
[[nodiscard]] const std::pair<characChanged, std::uint32_t> &get_carac() const { return carac; } [[nodiscard]] const std::pair<characChanged, std::uint32_t> &get_carac() const { return carac; }
[[nodiscard]] const std::pair<characChanged, std::uint32_t> &get_materiel() const { return materiel; } [[nodiscard]] const std::pair<characChanged, std::uint32_t> &get_materiel() const { return materiel; }
[[nodiscard]] const std::pair<characChanged, std::uint32_t> &get_additional() const { return additional; } [[nodiscard]] const std::pair<characChanged, std::uint32_t> &get_additional() const { return additional; }
}; };
} }

View File

@ -4,26 +4,26 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
namespace gui { namespace gui {
class GuiData; class GuiData;
namespace menu { namespace menu {
class MenuData; class MenuData;
class Menu final { class Menu final {
private: private:
MenuData &data; MenuData &data;
public: public:
Menu() noexcept = delete; Menu() noexcept = delete;
explicit Menu(MenuData &data) noexcept; explicit Menu(MenuData &data) noexcept;
~Menu() noexcept = default; ~Menu() noexcept = default;
void gui() const noexcept; void gui() const noexcept;
[[nodiscard]] const MenuData &get_data() const { return data; } [[nodiscard]] const MenuData &get_data() const { return data; }
}; };
} }
} }

View File

@ -8,38 +8,40 @@ namespace fs = std::filesystem;
class Controller; class Controller;
namespace character { namespace character {
class CharacterSheet; class CharacterSheet;
} }
namespace gui::menu { namespace gui::menu {
class MenuData final { class MenuData final {
public: public:
const std::string open_character_key{ "CharacterSheetOpen" }; const std::string open_character_key{ "CharacterSheetOpen" };
const std::string save_character_key{ "CharacterSheetSaveAs" }; const std::string save_character_key{ "CharacterSheetSaveAs" };
private: private:
friend class Menu; friend class Menu;
const character::CharacterSheet &character_sheet; const character::CharacterSheet &character_sheet;
mutable fs::path save_path{ "./" }; mutable fs::path save_path{ "./" };
mutable std::string filename{ "character_sheet.json" }; mutable std::string filename{ "character_sheet.json" };
bool edit_mode{ true }; bool edit_mode{ true };
public: public:
MenuData() noexcept = delete; MenuData() noexcept = delete;
explicit MenuData(const character::CharacterSheet &characterSheet) noexcept: character_sheet(characterSheet) {} explicit MenuData(const character::CharacterSheet &characterSheet) noexcept: character_sheet(characterSheet) {}
~MenuData() noexcept = default; ~MenuData() noexcept = default;
[[nodiscard]] bool is_edit_mode() const { return edit_mode; } [[nodiscard]] bool is_edit_mode() const { return edit_mode; }
void set_save_path([[maybe_unused]] const Controller &controller, const fs::path &savePath) const { save_path = savePath; } void set_save_path([[maybe_unused]] const Controller &controller,
const fs::path &savePath) const { save_path = savePath; }
void set_filename([[maybe_unused]] const Controller &controller, const std::string &fileName) const { filename = fileName; } void set_filename([[maybe_unused]] const Controller &controller,
}; const std::string &fileName) const { filename = fileName; }
};
} }

View File

@ -7,28 +7,29 @@
#include <memory> #include <memory>
namespace gui { namespace gui {
class Window final { class Window final {
private: private:
static void delete_glfw_window(GLFWwindow *glfWwindow) { static void delete_glfw_window(GLFWwindow *glfWwindow) {
glfwDestroyWindow(glfWwindow); glfwDestroyWindow(glfWwindow);
glfwTerminate(); glfwTerminate();
} }
std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)> wwindow{ nullptr, delete_glfw_window }; std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)> wwindow{ nullptr, delete_glfw_window };
public: public:
Window(); Window();
Window(Window &&window) noexcept: wwindow(std::move(window.wwindow)) {} Window(Window &&window) noexcept: wwindow(std::move(window.wwindow)) {}
~Window() noexcept = default; ~Window() noexcept = default;
[[nodiscard]] const std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)> &get_window() const { return wwindow; } [[nodiscard]] const std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)> &
get_window() const { return wwindow; }
[[nodiscard]] bool should_close() const noexcept; [[nodiscard]] bool should_close() const noexcept;
void swap_buffers() const noexcept; void swap_buffers() const noexcept;
}; };
} }

View File

@ -4,48 +4,48 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
namespace gui { namespace gui {
class GuiDataInterface { class GuiDataInterface {
public: public:
GuiDataInterface() noexcept = default; GuiDataInterface() noexcept = default;
virtual ~GuiDataInterface() noexcept = default; virtual ~GuiDataInterface() noexcept = default;
virtual void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) = 0; virtual void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) = 0;
virtual void character_callback(GLFWwindow *window, unsigned int codepoint) = 0; virtual void character_callback(GLFWwindow *window, unsigned int codepoint) = 0;
virtual void cursor_position_callback(GLFWwindow *window, double xpos, double ypos) = 0; virtual void cursor_position_callback(GLFWwindow *window, double xpos, double ypos) = 0;
virtual void cursor_enter_callback(GLFWwindow *window, int entered) = 0; virtual void cursor_enter_callback(GLFWwindow *window, int entered) = 0;
virtual void mouse_button_callback(GLFWwindow *window, int button, int action, int mods) = 0; virtual void mouse_button_callback(GLFWwindow *window, int button, int action, int mods) = 0;
virtual void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) = 0; virtual void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) = 0;
virtual void joystick_callback(int jid, int event) = 0; virtual void joystick_callback(int jid, int event) = 0;
virtual void drop_callback(GLFWwindow *window, int count, const char **paths) = 0; virtual void drop_callback(GLFWwindow *window, int count, const char **paths) = 0;
virtual void window_close_callback(GLFWwindow *window) = 0; virtual void window_close_callback(GLFWwindow *window) = 0;
virtual void window_size_callback(GLFWwindow *window, int width, int height) = 0; virtual void window_size_callback(GLFWwindow *window, int width, int height) = 0;
virtual void framebuffer_size_callback(GLFWwindow *window, int width, int height) = 0; virtual void framebuffer_size_callback(GLFWwindow *window, int width, int height) = 0;
virtual void window_content_scale_callback(GLFWwindow *window, float xscale, float yscale) = 0; virtual void window_content_scale_callback(GLFWwindow *window, float xscale, float yscale) = 0;
virtual void window_pos_callback(GLFWwindow *window, int xpos, int ypos) = 0; virtual void window_pos_callback(GLFWwindow *window, int xpos, int ypos) = 0;
virtual void window_iconify_callback(GLFWwindow *window, int iconified) = 0; virtual void window_iconify_callback(GLFWwindow *window, int iconified) = 0;
virtual void window_maximize_callback(GLFWwindow *window, int maximized) = 0; virtual void window_maximize_callback(GLFWwindow *window, int maximized) = 0;
virtual void window_focus_callback(GLFWwindow *window, int focused) = 0; virtual void window_focus_callback(GLFWwindow *window, int focused) = 0;
virtual void window_refresh_callback(GLFWwindow *window) = 0; virtual void window_refresh_callback(GLFWwindow *window) = 0;
virtual void error_callback(int error, const char *message) = 0; virtual void error_callback(int error, const char *message) = 0;
}; };
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
#include "characteristic/endurance.hpp" #include "characteristic/endurance.hpp"
std::uint32_t character::characteristic::Endurance::get_max_lp() const noexcept { std::uint32_t character::characteristic::Endurance::get_max_lp() const noexcept {
return (base + carac + materiel + additional) * 3; return (base + carac + materiel + additional) * 3;
} }

View File

@ -7,56 +7,56 @@
#include "character_sheet.hpp" #include "character_sheet.hpp"
void Controller::control_menu() const noexcept { void Controller::control_menu() const noexcept {
if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) { if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) {
if (ifd::FileDialog::Instance().HasResult()) { if (ifd::FileDialog::Instance().HasResult()) {
fs::path str = ifd::FileDialog::Instance().GetResult(); fs::path str = ifd::FileDialog::Instance().GetResult();
SPDLOG_DEBUG("path opening: {}", str.string()); SPDLOG_DEBUG("path opening: {}", str.string());
const auto filename = str.filename(); const auto filename = str.filename();
const auto save_path = str.remove_filename(); const auto save_path = str.remove_filename();
menu_data.set_filename(*this, filename); menu_data.set_filename(*this, filename);
menu_data.set_save_path(*this, save_path); menu_data.set_save_path(*this, save_path);
std::ifstream file{ save_path / filename }; std::ifstream file{ save_path / filename };
json j = json::parse(file); json j = json::parse(file);
file.close(); file.close();
sheet = j.at("character_sheet").get<character::CharacterSheet>(); sheet = j.at("character_sheet").get<character::CharacterSheet>();
} }
ifd::FileDialog::Instance().Close(); ifd::FileDialog::Instance().Close();
} }
if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) { if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) {
if (ifd::FileDialog::Instance().HasResult()) { if (ifd::FileDialog::Instance().HasResult()) {
fs::path str = ifd::FileDialog::Instance().GetResult(); fs::path str = ifd::FileDialog::Instance().GetResult();
SPDLOG_DEBUG("path saving: {}", str.string()); SPDLOG_DEBUG("path saving: {}", str.string());
const auto filename = str.filename(); const auto filename = str.filename();
const auto save_path = str.remove_filename(); const auto save_path = str.remove_filename();
menu_data.set_filename(*this, filename); menu_data.set_filename(*this, filename);
menu_data.set_save_path(*this, save_path); menu_data.set_save_path(*this, save_path);
std::ofstream file{ save_path / filename }; std::ofstream file{ save_path / filename };
json j; json j;
j.emplace("character_sheet", sheet); j.emplace("character_sheet", sheet);
file << j.dump(4); file << j.dump(4);
} }
ifd::FileDialog::Instance().Close(); ifd::FileDialog::Instance().Close();
} }
} }
void Controller::control_sheet() const noexcept { void Controller::control_sheet() const noexcept {
if (menu_data.is_edit_mode()) { if (menu_data.is_edit_mode()) {
// TODO // TODO
switch (sheet.get_current_class()) { switch (sheet.get_current_class()) {
case character::classe::Prudent: case character::classe::Prudent:
// TODO // TODO
break; break;
case character::classe::Guerrier: case character::classe::Guerrier:
// TODO // TODO
break; break;
case character::classe::Paysan: case character::classe::Paysan:
// TODO // TODO
break; break;
case character::classe::Debrouillard: case character::classe::Debrouillard:
// TODO // TODO
break; break;
} }
} else { } else {
// TODO // TODO
} }
} }

View File

@ -8,209 +8,221 @@
#include "character_sheet.hpp" #include "character_sheet.hpp"
#include "controller.hpp" #include "controller.hpp"
gui::Gui::Gui(Window &window, GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") { gui::Gui::Gui(Window &window, GuiData &data, menu::MenuData &menuData) :
SPDLOG_DEBUG("Creating GUI"); data(data), menu(menuData), font("font/DejaVuSans.ttf") {
(void) ImGui::CreateContext(); SPDLOG_DEBUG("Creating GUI");
ImGui::StyleColorsDark(); (void) ImGui::CreateContext();
(void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f); ImGui::StyleColorsDark();
(void) ImGui_ImplGlfw_InitForOpenGL(window.get_window().get(), true); (void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f);
initialized = ImGui_ImplOpenGL3_Init("#version 130"); (void) ImGui_ImplGlfw_InitForOpenGL(window.get_window().get(), true);
SPDLOG_DEBUG("Initialized: {}", initialized); initialized = ImGui_ImplOpenGL3_Init("#version 130");
SPDLOG_DEBUG("Initialized: {}", initialized);
} }
gui::Gui::~Gui() noexcept { gui::Gui::~Gui() noexcept {
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
} }
void gui::Gui::render_gui(const Controller &controller) { void gui::Gui::render_gui(const Controller &controller) {
if (initialized) { if (initialized) {
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar | constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoTitleBar; ImGuiWindowFlags_NoTitleBar;
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
//TODO GUI //TODO GUI
{ {
const ImGuiViewport &viewport = *ImGui::GetMainViewport(); const ImGuiViewport &viewport = *ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport.Pos); ImGui::SetNextWindowPos(viewport.Pos);
ImGui::SetNextWindowSize(viewport.Size); ImGui::SetNextWindowSize(viewport.Size);
} }
// Never collapsed. // Never collapsed.
(void) ImGui::Begin("Billy", nullptr, flags); (void) ImGui::Begin("Billy", nullptr, flags);
menu.gui(); menu.gui();
if (ImGui::BeginCombo("Classe", if (ImGui::BeginCombo("Classe",
GuiData::classes[static_cast<std::uint32_t>(data.billy.get_current_class())].data(), GuiData::classes[static_cast<std::uint32_t>(data.billy.get_current_class())].data(),
ImGuiComboFlags_PopupAlignLeft)) { ImGuiComboFlags_PopupAlignLeft)) {
for (std::size_t i = 0; i < GuiData::classes.size(); ++i) { for (std::size_t i = 0; i < GuiData::classes.size(); ++i) {
const bool is_selected = (data.billy.get_current_class() == static_cast<character::classe>(i)); const bool is_selected = (data.billy.get_current_class() == static_cast<character::classe>(i));
if (ImGui::Selectable(GuiData::classes[i].data(), is_selected)) if (ImGui::Selectable(GuiData::classes[i].data(), is_selected))
data.billy.current_class = static_cast<character::classe>(i); data.billy.current_class = static_cast<character::classe>(i);
if (is_selected) if (is_selected)
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
{ {
ImGui::BeginChild("carac", ImVec2(0, ImGui::GetWindowHeight() * 0.2f), true); ImGui::BeginChild("carac", ImVec2(0, ImGui::GetWindowHeight() * 0.2f), true);
ImGui::Text("Caractère"); ImGui::Text("Caractère");
// Remove label // Remove label
ImGui::PushItemWidth(-1); ImGui::PushItemWidth(-1);
ImGui::InputTextMultiline("Caractère", &data.billy.caractere); ImGui::InputTextMultiline("Caractère", &data.billy.caractere);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::EndChild(); ImGui::EndChild();
} }
ImGui::BeginGroup(); ImGui::BeginGroup();
habilete_menu(); habilete_menu();
ImGui::SameLine(); ImGui::SameLine();
adresse_menu(); adresse_menu();
endurance_menu(); endurance_menu();
ImGui::SameLine(); ImGui::SameLine();
chance_menu(); chance_menu();
ImGui::EndGroup(); ImGui::EndGroup();
ImGui::SameLine(); ImGui::SameLine();
stat_second_menu(); stat_second_menu();
materiel_menu(); materiel_menu();
ImGui::SameLine(); ImGui::SameLine();
ImGui::BeginGroup(); ImGui::BeginGroup();
gloire_menu(); gloire_menu();
richesse_menu(); richesse_menu();
ImGui::EndGroup(); ImGui::EndGroup();
ImGui::End(); ImGui::End();
controller.control_menu(); controller.control_menu();
ImGui::Render(); ImGui::Render();
} }
} }
void gui::Gui::render_gpu() const { void gui::Gui::render_gpu() const {
if (initialized) { if (initialized) {
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
} }
} }
void gui::Gui::habilete_menu() noexcept { void gui::Gui::habilete_menu() noexcept {
ImGui::BeginChild("habilete", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::BeginChild("habilete", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
ImGui::Text("Habileté"); ImGui::Text("Habileté");
data.base.second = data.billy.get_habilete().get_base(); data.base.second = data.billy.get_habilete().get_base();
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Habilete : characChanged::None; data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Habilete
: characChanged::None;
data.carac.second = data.billy.get_habilete().get_carac(); data.carac.second = data.billy.get_habilete().get_carac();
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Habilete : characChanged::None; data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Habilete
: characChanged::None;
data.materiel.second = data.billy.get_habilete().get_materiel(); data.materiel.second = data.billy.get_habilete().get_materiel();
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ? characChanged::Habilete : characChanged::None; data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second))
? characChanged::Habilete : characChanged::None;
data.additional.second = data.billy.get_habilete().get_additional(); data.additional.second = data.billy.get_habilete().get_additional();
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ? data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
characChanged::Habilete : characChanged::Habilete :
characChanged::None; characChanged::None;
ImGui::EndChild(); ImGui::EndChild();
} }
void gui::Gui::adresse_menu() noexcept { void gui::Gui::adresse_menu() noexcept {
ImGui::BeginChild("adresse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::BeginChild("adresse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
ImGui::Text("Adresse"); ImGui::Text("Adresse");
data.base.second = data.billy.get_adresse().get_base(); data.base.second = data.billy.get_adresse().get_base();
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Adresse : characChanged::None; data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Adresse
: characChanged::None;
data.carac.second = data.billy.get_adresse().get_carac(); data.carac.second = data.billy.get_adresse().get_carac();
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Adresse : characChanged::None; data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Adresse
: characChanged::None;
data.materiel.second = data.billy.get_adresse().get_materiel(); data.materiel.second = data.billy.get_adresse().get_materiel();
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ? characChanged::Adresse : characChanged::None; data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second))
? characChanged::Adresse : characChanged::None;
data.additional.second = data.billy.get_adresse().get_additional(); data.additional.second = data.billy.get_adresse().get_additional();
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ? data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
characChanged::Adresse : characChanged::Adresse :
characChanged::None; characChanged::None;
ImGui::EndChild(); ImGui::EndChild();
} }
void gui::Gui::endurance_menu() noexcept { void gui::Gui::endurance_menu() noexcept {
ImGui::BeginChild("endurance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::BeginChild("endurance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
ImGui::Text("Endurance"); ImGui::Text("Endurance");
data.base.second = data.billy.get_endurance().get_base(); data.base.second = data.billy.get_endurance().get_base();
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Endurance : characChanged::None; data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Endurance
: characChanged::None;
data.carac.second = data.billy.get_endurance().get_carac(); data.carac.second = data.billy.get_endurance().get_carac();
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Endurance : characChanged::None; data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Endurance
: characChanged::None;
data.materiel.second = data.billy.get_endurance().get_materiel(); data.materiel.second = data.billy.get_endurance().get_materiel();
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ? data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ?
characChanged::Endurance : characChanged::Endurance :
characChanged::None; characChanged::None;
data.additional.second = data.billy.get_endurance().get_additional(); data.additional.second = data.billy.get_endurance().get_additional();
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ? data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
characChanged::Endurance : characChanged::Endurance :
characChanged::None; characChanged::None;
ImGui::EndChild(); ImGui::EndChild();
} }
void gui::Gui::chance_menu() noexcept { void gui::Gui::chance_menu() noexcept {
ImGui::BeginChild("chance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::BeginChild("chance", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
ImGui::Text("Chance"); ImGui::Text("Chance");
data.base.second = data.billy.get_chance().get_base(); data.base.second = data.billy.get_chance().get_base();
data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Chance : characChanged::None; data.base.first = ImGui::InputInt("Base", reinterpret_cast<int *>(&data.base.second)) ? characChanged::Chance
: characChanged::None;
data.carac.second = data.billy.get_chance().get_carac(); data.carac.second = data.billy.get_chance().get_carac();
data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Chance : characChanged::None; data.carac.first = ImGui::InputInt("Carac", reinterpret_cast<int *>(&data.carac.second)) ? characChanged::Chance
: characChanged::None;
data.materiel.second = data.billy.get_chance().get_materiel(); data.materiel.second = data.billy.get_chance().get_materiel();
data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second)) ? characChanged::Chance : characChanged::None; data.materiel.first = ImGui::InputInt("Matériel", reinterpret_cast<int *>(&data.materiel.second))
? characChanged::Chance : characChanged::None;
data.additional.second = data.billy.get_chance().get_additional(); data.additional.second = data.billy.get_chance().get_additional();
data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ? data.additional.first = ImGui::InputInt("Additionnel", reinterpret_cast<int *>(&data.additional.second)) ?
characChanged::Chance : characChanged::Chance :
characChanged::None; characChanged::None;
ImGui::EndChild(); ImGui::EndChild();
} }
void gui::Gui::stat_second_menu() noexcept { void gui::Gui::stat_second_menu() noexcept {
ImGui::BeginChild("stats secondaire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.4f), true); ImGui::BeginChild("stats secondaire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.4f), true);
ImGui::Text("STAT. SECONDAIRES"); ImGui::Text("STAT. SECONDAIRES");
ImGui::EndChild(); ImGui::EndChild();
} }
void gui::Gui::materiel_menu() noexcept { void gui::Gui::materiel_menu() noexcept {
ImGui::BeginChild("materiel", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true); ImGui::BeginChild("materiel", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.2f), true);
ImGui::Text("Matériel"); ImGui::Text("Matériel");
ImGui::EndChild(); ImGui::EndChild();
} }
void gui::Gui::gloire_menu() noexcept { void gui::Gui::gloire_menu() noexcept {
ImGui::BeginChild("gloire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true); ImGui::BeginChild("gloire", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true);
ImGui::Text("Gloire"); ImGui::Text("Gloire");
ImGui::EndChild(); ImGui::EndChild();
} }
void gui::Gui::richesse_menu() noexcept { void gui::Gui::richesse_menu() noexcept {
ImGui::BeginChild("richesse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true); ImGui::BeginChild("richesse", ImVec2(ImGui::GetWindowWidth() / 3, ImGui::GetWindowHeight() * 0.1f), true);
ImGui::Text("Richesse"); ImGui::Text("Richesse");
ImGui::EndChild(); ImGui::EndChild();
} }

View File

@ -9,61 +9,65 @@
#include "ImFileDialog.h" #include "ImFileDialog.h"
gui::menu::Menu::Menu(gui::menu::MenuData &data) noexcept: data(data) { gui::menu::Menu::Menu(gui::menu::MenuData &data) noexcept: data(data) {
SPDLOG_DEBUG("Creating Menu"); SPDLOG_DEBUG("Creating Menu");
ifd::FileDialog::Instance().CreateTexture = [](uint8_t *data, int w, int h, char fmt) -> void * { ifd::FileDialog::Instance().CreateTexture = [](uint8_t *data, int w, int h, char fmt) -> void * {
GLuint tex; GLuint tex;
SPDLOG_DEBUG("Inside CreateTexture for file dialog."); SPDLOG_DEBUG("Inside CreateTexture for file dialog.");
glGenTextures(1, &tex); glGenTextures(1, &tex);
SPDLOG_DEBUG("texture generated"); SPDLOG_DEBUG("texture generated");
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
SPDLOG_DEBUG("Texture binded"); SPDLOG_DEBUG("Texture binded");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, (fmt == 0) ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, data); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, (fmt == 0) ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, data);
SPDLOG_DEBUG("Before mipmap"); SPDLOG_DEBUG("Before mipmap");
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
return (void *) tex; return (void *) tex;
}; };
ifd::FileDialog::Instance().DeleteTexture = [](void *tex) -> void { ifd::FileDialog::Instance().DeleteTexture = [](void *tex) -> void {
auto texID = (GLuint) ((std::uintptr_t) tex); auto texID = (GLuint) ((std::uintptr_t) tex);
glDeleteTextures(1, &texID); glDeleteTextures(1, &texID);
}; };
} }
void gui::menu::Menu::gui() const noexcept { void gui::menu::Menu::gui() const noexcept {
if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("File")) { if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Open file")) { if (ImGui::MenuItem("Open file")) {
SPDLOG_DEBUG("Opening file"); SPDLOG_DEBUG("Opening file");
ifd::FileDialog::Instance().Open(data.open_character_key, "Open a character sheet", "Character sheet (*.json){.json},.*"); ifd::FileDialog::Instance().Open(data.open_character_key,
SPDLOG_DEBUG("File opened"); "Open a character sheet",
} "Character sheet (*.json){.json},.*");
SPDLOG_DEBUG("File opened");
}
if (ImGui::MenuItem("Save")) { if (ImGui::MenuItem("Save")) {
SPDLOG_DEBUG("Saving file with know path"); SPDLOG_DEBUG("Saving file with know path");
std::ofstream file{ data.save_path / data.filename }; std::ofstream file{ data.save_path / data.filename };
nlohmann::json j; nlohmann::json j;
j.emplace("character_sheet", data.character_sheet); j.emplace("character_sheet", data.character_sheet);
file << j.dump(4); file << j.dump(4);
} }
if (ImGui::MenuItem("Save as...")) { if (ImGui::MenuItem("Save as...")) {
SPDLOG_DEBUG("Saving with file dialog"); SPDLOG_DEBUG("Saving with file dialog");
ifd::FileDialog::Instance().Save(data.save_character_key, "Save character sheet as...", "*.json {.json}"); ifd::FileDialog::Instance().Save(data.save_character_key,
SPDLOG_DEBUG("File saved with dialog"); "Save character sheet as...",
} "*.json {.json}");
SPDLOG_DEBUG("File saved with dialog");
}
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("Editor")) { if (ImGui::BeginMenu("Editor")) {
ImGui::MenuItem("Edit mode", nullptr, &data.edit_mode); ImGui::MenuItem("Edit mode", nullptr, &data.edit_mode);
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
} }

View File

@ -3,47 +3,51 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
static void glfwErrorCallback(int error, const char *message) { static void glfwErrorCallback(int error, const char *message) {
SPDLOG_CRITICAL("Error code{}: {}", error, message); SPDLOG_CRITICAL("Error code{}: {}", error, message);
} }
static void framebufferCallback([[maybe_unused]] GLFWwindow *glfWwindow, int width, int height) { static void framebufferCallback([[maybe_unused]] GLFWwindow *glfWwindow, int width, int height) {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
} }
gui::Window::Window() { gui::Window::Window() {
SPDLOG_DEBUG("Creating Window"); SPDLOG_DEBUG("Creating Window");
glfwSetErrorCallback(glfwErrorCallback); glfwSetErrorCallback(glfwErrorCallback);
if (glfwInit() == GLFW_FALSE) { if (glfwInit() == GLFW_FALSE) {
SPDLOG_CRITICAL("GLFW init failed."); SPDLOG_CRITICAL("GLFW init failed.");
throw std::runtime_error("GLFW init failed."); throw std::runtime_error("GLFW init failed.");
} }
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
wwindow = std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)>(glfwCreateWindow(720, 1280, "Billy Sheet tracker", nullptr, nullptr), wwindow = std::unique_ptr<GLFWwindow, decltype(&delete_glfw_window)>(glfwCreateWindow(720,
delete_glfw_window); 1280,
if (!wwindow) { "Billy Sheet tracker",
glfwTerminate(); nullptr,
SPDLOG_CRITICAL("No GLFW window created, nullptr."); nullptr),
throw std::runtime_error("GLFW failed. See log."); delete_glfw_window);
} if (!wwindow) {
glfwMakeContextCurrent(wwindow.get()); glfwTerminate();
glewExperimental = true; SPDLOG_CRITICAL("No GLFW window created, nullptr.");
if (glewInit() != GLEW_OK) { throw std::runtime_error("GLFW failed. See log.");
wwindow.reset(nullptr); }
glfwTerminate(); glfwMakeContextCurrent(wwindow.get());
SPDLOG_CRITICAL("GLEW loader failed."); glewExperimental = true;
throw std::runtime_error("GLEW failed. See log."); if (glewInit() != GLEW_OK) {
} wwindow.reset(nullptr);
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback); glfwTerminate();
SPDLOG_CRITICAL("GLEW loader failed.");
throw std::runtime_error("GLEW failed. See log.");
}
glfwSetFramebufferSizeCallback(wwindow.get(), framebufferCallback);
glfwSwapInterval(1); // VSync on glfwSwapInterval(1); // VSync on
} }
bool gui::Window::should_close() const noexcept { bool gui::Window::should_close() const noexcept {
return glfwWindowShouldClose(wwindow.get()); return glfwWindowShouldClose(wwindow.get());
} }
void gui::Window::swap_buffers() const noexcept { void gui::Window::swap_buffers() const noexcept {
glfwSwapBuffers(wwindow.get()); glfwSwapBuffers(wwindow.get());
} }

View File

@ -8,29 +8,29 @@
#include "character_sheet.hpp" #include "character_sheet.hpp"
int main() { int main() {
std::ios::sync_with_stdio(false); std::ios::sync_with_stdio(false);
spdlog::set_default_logger(spdlog::stdout_color_st("BillySheet")); spdlog::set_default_logger(spdlog::stdout_color_st("BillySheet"));
try { try {
gui::Window window; gui::Window window;
character::CharacterSheet billy; character::CharacterSheet billy;
gui::GuiData gui_data(billy); gui::GuiData gui_data(billy);
gui::menu::MenuData menu_data(billy); gui::menu::MenuData menu_data(billy);
Controller controller(billy, menu_data); Controller controller(billy, menu_data);
gui::Gui gui(window, gui_data, menu_data); gui::Gui gui(window, gui_data, menu_data);
while (!window.should_close()) { while (!window.should_close()) {
glfwPollEvents(); glfwPollEvents();
controller.control_sheet(); controller.control_sheet();
gui.render_gui(controller); gui.render_gui(controller);
gui.render_gpu(); gui.render_gpu();
window.swap_buffers(); window.swap_buffers();
} }
} catch (const std::exception &e) { } catch (const std::exception &e) {
SPDLOG_CRITICAL(e.what()); SPDLOG_CRITICAL(e.what());
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }