63 lines
2.2 KiB
C++
63 lines
2.2 KiB
C++
#include "controller.hpp"
|
|
#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)) {
|
|
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
|
|
}
|
|
}
|