Writing is working.

This commit is contained in:
Pcornat 2022-01-20 23:16:51 +01:00
parent 3c1ce804a0
commit 2023360149
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
5 changed files with 31 additions and 9 deletions

View File

@ -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<std::uint32_t &>(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; }

View File

@ -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;

View File

@ -3,10 +3,11 @@
#include <filesystem>
#include "gui/menu/menu.hpp"
#include "controller.hpp"
namespace fs = std::filesystem;
class Controller;
namespace gui {
class GuiData;

View File

@ -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; }
};
}

View File

@ -1,7 +1,10 @@
#include "controller.hpp"
#include "gui/menu/menu_data.hpp"
#include "ImFileDialog.h"
#include <fstream>
#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 {
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();
}