* Removing Old EventSystem * Removing Assets from Editor project * Clean up of EditorLayer.h * Moving primitives of renderer out of their subfolder
86 lines
1.7 KiB
C++
86 lines
1.7 KiB
C++
#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;
|
|
projectYAML << YAML::BeginMap;
|
|
|
|
|
|
projectYAML << YAML::Key << "Scenes" << YAML::Value << YAML::BeginSeq;
|
|
for (auto scene : project.Scenes) {
|
|
projectYAML << scene->name;
|
|
}
|
|
projectYAML << YAML::EndSeq;
|
|
|
|
std::ofstream projectFile;
|
|
|
|
projectFile.open(path.u8string());
|
|
projectFile << projectYAML.c_str();
|
|
projectFile.close();
|
|
}
|
|
|
|
void Project::LoadProject(std::filesystem::path path, Project& project)
|
|
{
|
|
|
|
if (!std::filesystem::exists(path)) {
|
|
throw std::runtime_error("Couldn't find project file!");
|
|
}
|
|
|
|
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 = node.as<Project>();
|
|
|
|
spdlog::info("loaded project {0}", project.Name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
namespace YAML {
|
|
|
|
template<>
|
|
class convert<Project> {
|
|
public:
|
|
static bool decode(const Node& node , Project& rhs)
|
|
{
|
|
if (!node.IsMap())
|
|
return false;
|
|
|
|
std::string projectName = node["Project"].as<std::string>();
|
|
rhs.setName(projectName);
|
|
|
|
|
|
std::string projectDirectory = node["Directory"].as<std::string>();
|
|
rhs.setProjectDirectory(projectDirectory);
|
|
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
};
|
|
|
|
} |