Import / Export Meshes
This commit is contained in:
66
Editor/src/Project/Project.cpp
Normal file
66
Editor/src/Project/Project.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include "Project.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
|
||||
void Project::SaveProject(std::filesystem::path path, Project& project)
|
||||
{
|
||||
YAML::Emitter projectYAML;
|
||||
projectYAML << YAML::BeginMap;
|
||||
projectYAML << YAML::Key << "Project" << YAML::Value << project.Name;
|
||||
projectYAML << YAML::Key << "Directory" << YAML::Value << path.parent_path().u8string();
|
||||
projectYAML << YAML::EndMap;
|
||||
std::ofstream projectFile;
|
||||
|
||||
projectFile.open(path.u8string());
|
||||
projectFile << projectYAML.c_str();
|
||||
projectFile.close();
|
||||
}
|
||||
|
||||
void Project::LoadProject(std::filesystem::path path, std::shared_ptr<Project>& project)
|
||||
{
|
||||
std::string YAMLProject;
|
||||
std::stringstream sstream;
|
||||
std::ifstream projectFile;
|
||||
projectFile.open(path.u8string());
|
||||
|
||||
sstream << projectFile.rdbuf();
|
||||
YAMLProject = sstream.str();
|
||||
|
||||
projectFile.close();
|
||||
|
||||
|
||||
YAML::Node node = YAML::Load(YAMLProject);
|
||||
|
||||
// this is probably not perfect but it seems to work for now
|
||||
project.reset();
|
||||
project = std::make_shared<Project>(node.as<Project>());
|
||||
|
||||
std::cout << "loading..." << project.get()->Name << std::endl;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace YAML {
|
||||
|
||||
template<>
|
||||
class convert<Project> {
|
||||
public:
|
||||
static bool decode(const Node& node , Project& rhs)
|
||||
{
|
||||
if (!node.IsMap())
|
||||
return false;
|
||||
rhs.setName(node["Project"].as<std::string>());
|
||||
rhs.setProjectDirectory(node["Directory"].as<std::string>());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user