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_data.hpp
include/gui/window.hpp
)
)
set(SOURCE_HEADERS
include/imgui/imconfig.h
@ -42,7 +42,7 @@ set(SOURCE_HEADERS
include/characteristic/characteristic.hpp
include/controller.hpp
include/gui_data_interface.hpp
)
)
set(SOURCE_FILES
src/imgui/imgui.cpp
@ -63,7 +63,7 @@ set(SOURCE_FILES
src/characteristic/chance.cpp
src/gui/menu/menu.cpp
src/controller.cpp
)
)
set(SOURCES
${SOURCE_HEADERS}
@ -123,16 +123,16 @@ set(COMPILE_FLAGS
-funroll-loops
-fdevirtualize-at-ltrans
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
)
)
set(LINKER_OPTIONS
-Wl,--sort-common,--as-needed,--gc-sections,--strip-all
-fuse-ld=gold
-fdevirtualize-at-ltrans
)
)
set(LINKER_FLAGS
jemalloc
)
)
option(ENABLE_COVERAGE "Enabling coverage" OFF)
@ -155,7 +155,7 @@ set_target_properties(BillySheet spdlog PROPERTIES
CXX_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON
# UNITY_BUILD ON
)
)
set_target_properties(spdlog PROPERTIES UNITY_BUILD ON)
@ -165,7 +165,7 @@ set_target_properties(glfw PROPERTIES
C_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON
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)
set_target_properties(Catch2 UnitTest PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON
# UNITY_BUILD ON
)
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON
# UNITY_BUILD ON
)
target_include_directories(UnitTest PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_compile_definitions(UnitTest PRIVATE ${DEF_COMP})
target_compile_options(UnitTest PRIVATE ${COMPILE_FLAGS})

View File

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

View File

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

View File

@ -8,101 +8,109 @@
#include <random>
namespace gui {
class Gui;
class Gui;
}
namespace character {
enum class classe : std::uint32_t {
Guerrier = 0,
Prudent = 1,
Paysan = 2,
Debrouillard = 3,
};
enum class classe : std::uint8_t {
Guerrier = 0,
Prudent = 1,
Paysan = 2,
Debrouillard = 3,
};
class CharacterSheet final {
private:
friend gui::Gui;
class CharacterSheet final {
private:
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 };
public:
CharacterSheet() = default;
std::uint32_t money{ 0 };
public:
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) {
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);
}
};
[[nodiscard]] std::uint32_t get_armor() const { return armor; }
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();
}
[[nodiscard]] std::uint32_t get_damage() const { return damage; }
[[nodiscard]] std::uint32_t get_glory() const { return glory; }
[[nodiscard]] std::uint32_t get_money() const { return money; }
friend void from_json(const json &j, CharacterSheet &billy) {
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) {
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;
namespace character::characteristic {
class Adresse final : public Characteristic {
public:
Adresse() noexcept: Characteristic(1, 0, 0, 0) {}
class Adresse final : public Characteristic {
public:
Adresse() noexcept: Characteristic(1, 0, 0, 0) {}
~Adresse() noexcept final = default;
~Adresse() noexcept final = default;
friend void from_json(const json &j, Adresse &adresse) {
nlohmann::from_json(j, static_cast<Characteristic &>(adresse));
}
};
friend void from_json(const json &j, Adresse &adresse) {
nlohmann::from_json(j, static_cast<Characteristic &>(adresse));
}
};
static void to_json(json &j, const Adresse &adresse) {
to_json(j, static_cast<Characteristic>(adresse));
}
static void to_json(json &j, const Adresse &adresse) {
to_json(j, static_cast<Characteristic>(adresse));
}
}

View File

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

View File

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

View File

@ -7,22 +7,22 @@
using json = nlohmann::json;
namespace character::characteristic {
class Endurance final : public Characteristic {
public:
Endurance() noexcept: Characteristic(2, 0, 0, 0) {};
class Endurance final : public Characteristic {
public:
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) {
nlohmann::from_json(j, static_cast<Characteristic &>(endurance));
}
};
friend void from_json(const json &j, Endurance &endurance) {
nlohmann::from_json(j, static_cast<Characteristic &>(endurance));
}
};
static void to_json(json &j, const Endurance &endurance) {
to_json(j, static_cast<Characteristic>(endurance));
}
static void to_json(json &j, const Endurance &endurance) {
to_json(j, static_cast<Characteristic>(endurance));
}
}

View File

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

View File

@ -2,28 +2,29 @@
#define BILLYSHEET_CONTROLLER_HPP
namespace character {
class CharacterSheet;
class CharacterSheet;
}
namespace gui::menu {
class MenuData;
class MenuData;
}
class Controller final {
private:
character::CharacterSheet &sheet;
gui::menu::MenuData &menu_data;
character::CharacterSheet &sheet;
gui::menu::MenuData &menu_data;
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 {
class GuiData;
class GuiData;
class Window;
class Window;
namespace menu { class MenuData; }
namespace menu { class MenuData; }
class Gui final {
private:
GuiData &data;
class Gui final {
private:
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:
Gui() = delete;
public:
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

View File

@ -5,57 +5,57 @@
#include <spdlog/spdlog.h>
namespace character {
class CharacterSheet;
class CharacterSheet;
}
using namespace std::string_view_literals;
namespace gui {
enum class characChanged {
None,
Adresse,
Endurance,
Chance,
Habilete
};
enum class characChanged {
None,
Adresse,
Endurance,
Chance,
Habilete
};
class GuiData final {
private:
friend class Gui;
class GuiData final {
private:
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:
static constexpr std::array classes{
"Guerrier"sv,
"Prudent"sv,
"Paysan"sv,
"Débrouillard"sv
};
public:
static constexpr std::array classes{
"Guerrier"sv,
"Prudent"sv,
"Paysan"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>
namespace gui {
class GuiData;
class GuiData;
namespace menu {
class MenuData;
namespace menu {
class MenuData;
class Menu final {
private:
MenuData &data;
public:
Menu() noexcept = delete;
class Menu final {
private:
MenuData &data;
public:
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;
namespace character {
class CharacterSheet;
class CharacterSheet;
}
namespace gui::menu {
class MenuData final {
public:
const std::string open_character_key{ "CharacterSheetOpen" };
class MenuData final {
public:
const std::string open_character_key{ "CharacterSheetOpen" };
const std::string save_character_key{ "CharacterSheetSaveAs" };
private:
friend class Menu;
const std::string save_character_key{ "CharacterSheetSaveAs" };
private:
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 };
public:
MenuData() noexcept = delete;
bool edit_mode{ true };
public:
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>
namespace gui {
class Window final {
private:
static void delete_glfw_window(GLFWwindow *glfWwindow) {
glfwDestroyWindow(glfWwindow);
glfwTerminate();
}
class Window final {
private:
static void delete_glfw_window(GLFWwindow *glfWwindow) {
glfwDestroyWindow(glfWwindow);
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:
Window();
public:
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>
namespace gui {
class GuiDataInterface {
public:
GuiDataInterface() noexcept = default;
class GuiDataInterface {
public:
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"
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"
void Controller::control_menu() const noexcept {
if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) {
if (ifd::FileDialog::Instance().HasResult()) {
fs::path str = ifd::FileDialog::Instance().GetResult();
SPDLOG_DEBUG("path opening: {}", str.string());
const auto filename = str.filename();
const auto save_path = str.remove_filename();
menu_data.set_filename(*this, filename);
menu_data.set_save_path(*this, save_path);
std::ifstream file{ save_path / filename };
json j = json::parse(file);
file.close();
sheet = j.at("character_sheet").get<character::CharacterSheet>();
}
ifd::FileDialog::Instance().Close();
}
if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) {
if (ifd::FileDialog::Instance().HasResult()) {
fs::path str = ifd::FileDialog::Instance().GetResult();
SPDLOG_DEBUG("path saving: {}", str.string());
const auto filename = str.filename();
const auto save_path = str.remove_filename();
menu_data.set_filename(*this, filename);
menu_data.set_save_path(*this, save_path);
std::ofstream file{ save_path / filename };
json j;
j.emplace("character_sheet", sheet);
file << j.dump(4);
}
ifd::FileDialog::Instance().Close();
}
if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) {
if (ifd::FileDialog::Instance().HasResult()) {
fs::path str = ifd::FileDialog::Instance().GetResult();
SPDLOG_DEBUG("path opening: {}", str.string());
const auto filename = str.filename();
const auto save_path = str.remove_filename();
menu_data.set_filename(*this, filename);
menu_data.set_save_path(*this, save_path);
std::ifstream file{ save_path / filename };
json j = json::parse(file);
file.close();
sheet = j.at("character_sheet").get<character::CharacterSheet>();
}
ifd::FileDialog::Instance().Close();
}
if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) {
if (ifd::FileDialog::Instance().HasResult()) {
fs::path str = ifd::FileDialog::Instance().GetResult();
SPDLOG_DEBUG("path saving: {}", str.string());
const auto filename = str.filename();
const auto save_path = str.remove_filename();
menu_data.set_filename(*this, filename);
menu_data.set_save_path(*this, save_path);
std::ofstream file{ save_path / filename };
json j;
j.emplace("character_sheet", sheet);
file << j.dump(4);
}
ifd::FileDialog::Instance().Close();
}
}
void Controller::control_sheet() const noexcept {
if (menu_data.is_edit_mode()) {
// TODO
switch (sheet.get_current_class()) {
case character::classe::Prudent:
// TODO
break;
case character::classe::Guerrier:
// TODO
break;
case character::classe::Paysan:
// TODO
break;
case character::classe::Debrouillard:
// TODO
break;
}
} else {
// TODO
}
if (menu_data.is_edit_mode()) {
// TODO
switch (sheet.get_current_class()) {
case character::classe::Prudent:
// TODO
break;
case character::classe::Guerrier:
// TODO
break;
case character::classe::Paysan:
// TODO
break;
case character::classe::Debrouillard:
// TODO
break;
}
} else {
// TODO
}
}

View File

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

View File

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

View File

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

View File

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