Loading Projects now
This commit is contained in:
parent
3b91516d6e
commit
7343300dcb
@ -9,19 +9,18 @@
|
|||||||
void Project::SaveProject(std::filesystem::path path, Project& project)
|
void Project::SaveProject(std::filesystem::path path, Project& project)
|
||||||
{
|
{
|
||||||
YAML::Emitter projectYAML;
|
YAML::Emitter projectYAML;
|
||||||
projectYAML << YAML::Key << "Project" << YAML::Value << "new";
|
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;
|
std::ofstream projectFile;
|
||||||
|
|
||||||
path.append(project.Name.append(".yproj"));
|
|
||||||
|
|
||||||
std::cout << path.u8string() << std::endl;
|
|
||||||
|
|
||||||
projectFile.open(path.u8string());
|
projectFile.open(path.u8string());
|
||||||
projectFile << projectYAML.c_str();
|
projectFile << projectYAML.c_str();
|
||||||
projectFile.close();
|
projectFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::LoadProject(std::filesystem::path path, Project& project)
|
void Project::LoadProject(std::filesystem::path path, std::shared_ptr<Project>& project)
|
||||||
{
|
{
|
||||||
std::string YAMLProject;
|
std::string YAMLProject;
|
||||||
std::stringstream sstream;
|
std::stringstream sstream;
|
||||||
@ -34,7 +33,33 @@ void Project::LoadProject(std::filesystem::path path, Project& project)
|
|||||||
projectFile.close();
|
projectFile.close();
|
||||||
|
|
||||||
|
|
||||||
std::cout << YAMLProject << std::endl;
|
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>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <iostream>
|
||||||
class Project {
|
class Project {
|
||||||
public:
|
public:
|
||||||
|
Project() = default;
|
||||||
Project(const std::string& name): Name(name){}
|
Project(const std::string& name): Name(name){}
|
||||||
|
~Project() { std::cout << "Unloading project..." << Name << std::endl; }
|
||||||
|
|
||||||
|
void setName(std::string& name) { Name = name; }
|
||||||
|
const std::string& GetName()const { return Name; }
|
||||||
|
|
||||||
|
void setProjectDirectory(std::string& path) { ProjectDirectory = std::filesystem::path(path); }
|
||||||
|
const std::filesystem::path GetProjectDirectory() { return ProjectDirectory; }
|
||||||
|
|
||||||
static void SaveProject(std::filesystem::path path, Project& project);
|
static void SaveProject(std::filesystem::path path, Project& project);
|
||||||
static void LoadProject(std::filesystem::path path, Project& project);
|
static void LoadProject(std::filesystem::path path, std::shared_ptr<Project>& project);
|
||||||
private:
|
private:
|
||||||
std::string Name;
|
std::string Name;
|
||||||
|
std::filesystem::path ProjectDirectory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "../../YoggieEngine/src/Graphics/Memory/Framebuffer.h"
|
#include "../../YoggieEngine/src/Graphics/Memory/Framebuffer.h"
|
||||||
#include "../../YoggieEngine/src/PerfCounter.cpp"
|
#include "../../YoggieEngine/src/PerfCounter.cpp"
|
||||||
#include "../../YoggieEngine/src/Scene/Entity.h"
|
#include "../../YoggieEngine/src/Scene/Entity.h"
|
||||||
#include "Widgets.h"
|
#include "UI/Widgets.h"
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
#include "SceneSerializer.h"
|
#include "SceneSerializer.h"
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ struct EditorContext {
|
|||||||
~EditorContext() = default;
|
~EditorContext() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
Project CurrentProject ("test");
|
std::shared_ptr<Project> CurrentProject;
|
||||||
Scene MainScene;
|
Scene MainScene;
|
||||||
|
|
||||||
Framebuffer* framebuffer;
|
Framebuffer* framebuffer;
|
||||||
@ -46,6 +46,7 @@ entt::entity Selected;
|
|||||||
*/
|
*/
|
||||||
void Start() {
|
void Start() {
|
||||||
|
|
||||||
|
CurrentProject = std::make_shared<Project>("Random");
|
||||||
auto io = ImGui::GetIO();
|
auto io = ImGui::GetIO();
|
||||||
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18);
|
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18);
|
||||||
|
|
||||||
@ -96,7 +97,6 @@ void ImmediateGraphicsDraw()
|
|||||||
|
|
||||||
ImGui::BeginMainMenuBar();
|
ImGui::BeginMainMenuBar();
|
||||||
|
|
||||||
ImGui::PushItemFlag(ImGuiItemFlags_SelectableDontClosePopup, true);
|
|
||||||
if (ImGui::BeginMenu("Application")) {
|
if (ImGui::BeginMenu("Application")) {
|
||||||
|
|
||||||
if (ImGui::MenuItem("Load Project"))
|
if (ImGui::MenuItem("Load Project"))
|
||||||
@ -120,7 +120,7 @@ void ImmediateGraphicsDraw()
|
|||||||
switch (result) {
|
switch (result) {
|
||||||
case(NFD_OKAY):
|
case(NFD_OKAY):
|
||||||
std::cout << "Save as: " << savePath << std::endl;
|
std::cout << "Save as: " << savePath << std::endl;
|
||||||
Project::SaveProject(savePath, CurrentProject);
|
Project::SaveProject(savePath, *CurrentProject.get());
|
||||||
break;
|
break;
|
||||||
case(NFD_CANCEL):
|
case(NFD_CANCEL):
|
||||||
break;
|
break;
|
||||||
@ -144,7 +144,6 @@ void ImmediateGraphicsDraw()
|
|||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
ImGui::PopItemFlag();
|
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::BeginMenu("Scene")) {
|
if (ImGui::BeginMenu("Scene")) {
|
||||||
@ -191,6 +190,11 @@ void ImmediateGraphicsDraw()
|
|||||||
|
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
|
|
||||||
|
ImGui::Begin("ProjectInfo");
|
||||||
|
ImGui::Text("Project: %s", CurrentProject.get()->GetName().c_str());
|
||||||
|
ImGui::Text("Directory: %s", CurrentProject.get()->GetProjectDirectory().u8string().c_str());
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
//ShowStats();
|
//ShowStats();
|
||||||
Viewport(*framebuffer, MainScene);
|
Viewport(*framebuffer, MainScene);
|
||||||
@ -202,7 +206,7 @@ void ImmediateGraphicsDraw()
|
|||||||
Console();
|
Console();
|
||||||
|
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
ImGui::ShowMetricsWindow();
|
ImGui::ShowMetricsWindow();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user