diff --git a/include/characteristic/characteristic.hpp b/include/characteristic/characteristic.hpp index 8e854db..2567303 100644 --- a/include/characteristic/characteristic.hpp +++ b/include/characteristic/characteristic.hpp @@ -17,9 +17,19 @@ namespace character::characteristic { 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) : + 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 &operator=(const Characteristic &charac) noexcept { + const_cast(base) = charac.base; + carac = charac.carac; + materiel = charac.materiel; + additional = charac.additional; + return *this; + } + virtual ~Characteristic() noexcept = default; [[nodiscard]] std::uint32_t get_base() const { return base; } diff --git a/include/controller.hpp b/include/controller.hpp index 7df617d..fdc2696 100644 --- a/include/controller.hpp +++ b/include/controller.hpp @@ -12,12 +12,12 @@ namespace gui::menu { class Controller final { private: character::CharacterSheet &sheet; - const gui::menu::MenuData &menu_data; + gui::menu::MenuData &menu_data; public: Controller() = delete; - explicit Controller(character::CharacterSheet &sheet, const 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; diff --git a/include/gui/gui.hpp b/include/gui/gui.hpp index 999fb27..0273aad 100644 --- a/include/gui/gui.hpp +++ b/include/gui/gui.hpp @@ -3,10 +3,11 @@ #include #include "gui/menu/menu.hpp" -#include "controller.hpp" namespace fs = std::filesystem; +class Controller; + namespace gui { class GuiData; diff --git a/include/gui/menu/menu_data.hpp b/include/gui/menu/menu_data.hpp index e46bd7e..19a1efd 100644 --- a/include/gui/menu/menu_data.hpp +++ b/include/gui/menu/menu_data.hpp @@ -36,9 +36,9 @@ namespace gui::menu { [[nodiscard]] bool is_edit_mode() const { return edit_mode; } - void set_save_path(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(const std::string &fileName) const { filename = fileName; } + void set_filename([[maybe_unused]] const Controller &controller, const std::string &fileName) const { filename = fileName; } }; } diff --git a/src/controller.cpp b/src/controller.cpp index fad716b..4949b90 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -1,7 +1,10 @@ #include "controller.hpp" -#include "gui/menu/menu_data.hpp" -#include "ImFileDialog.h" +#include #include +#include +#include "ImFileDialog.h" +#include "gui/menu/menu_data.hpp" +#include "character_sheet.hpp" void Controller::control_menu() const noexcept { if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) { @@ -13,8 +16,16 @@ void Controller::control_menu() const noexcept { } if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) { if (ifd::FileDialog::Instance().HasResult()) { - const fs::path str = ifd::FileDialog::Instance().GetResult(); + 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(); }