Writing is working.
This commit is contained in:
parent
3c1ce804a0
commit
2023360149
@ -17,9 +17,19 @@ namespace character::characteristic {
|
|||||||
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) :
|
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) {}
|
base(base), carac(carac), materiel(materiel), additional(additional) {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
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; }
|
||||||
|
@ -12,12 +12,12 @@ namespace gui::menu {
|
|||||||
class Controller final {
|
class Controller final {
|
||||||
private:
|
private:
|
||||||
character::CharacterSheet &sheet;
|
character::CharacterSheet &sheet;
|
||||||
const gui::menu::MenuData &menu_data;
|
gui::menu::MenuData &menu_data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Controller() = delete;
|
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;
|
~Controller() noexcept = default;
|
||||||
|
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "gui/menu/menu.hpp"
|
#include "gui/menu/menu.hpp"
|
||||||
#include "controller.hpp"
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
class Controller;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
class GuiData;
|
class GuiData;
|
||||||
|
@ -36,9 +36,9 @@ namespace gui::menu {
|
|||||||
|
|
||||||
[[nodiscard]] bool is_edit_mode() const { return edit_mode; }
|
[[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; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
#include "controller.hpp"
|
#include "controller.hpp"
|
||||||
#include "gui/menu/menu_data.hpp"
|
#include <fstream>
|
||||||
#include "ImFileDialog.h"
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include "ImFileDialog.h"
|
||||||
|
#include "gui/menu/menu_data.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)) {
|
||||||
@ -13,8 +16,16 @@ void Controller::control_menu() const noexcept {
|
|||||||
}
|
}
|
||||||
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()) {
|
||||||
const 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 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();
|
ifd::FileDialog::Instance().Close();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user