From 7343300dcbdb7dc89be02fad9cfa3c402cc2c152 Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Sat, 5 Nov 2022 13:47:37 +0100 Subject: [PATCH] Loading Projects now --- Editor/src/Project.cpp | 39 ++++++++++++++++++++++++++++++++------- Editor/src/Project.h | 13 +++++++++++-- Editor/src/main.cpp | 16 ++++++++++------ 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/Editor/src/Project.cpp b/Editor/src/Project.cpp index 72e9f52..b42d850 100644 --- a/Editor/src/Project.cpp +++ b/Editor/src/Project.cpp @@ -9,19 +9,18 @@ void Project::SaveProject(std::filesystem::path path, Project& project) { 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; - path.append(project.Name.append(".yproj")); - - std::cout << path.u8string() << std::endl; - projectFile.open(path.u8string()); projectFile << projectYAML.c_str(); projectFile.close(); } -void Project::LoadProject(std::filesystem::path path, Project& project) +void Project::LoadProject(std::filesystem::path path, std::shared_ptr& project) { std::string YAMLProject; std::stringstream sstream; @@ -34,7 +33,33 @@ void Project::LoadProject(std::filesystem::path path, Project& project) 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(node.as()); + + std::cout << "loading..." << project.get()->Name << std::endl; + +} + + +namespace YAML { + + template<> + class convert { + public: + static bool decode(const Node& node , Project& rhs) + { + if (!node.IsMap()) + return false; + rhs.setName(node["Project"].as()); + rhs.setProjectDirectory(node["Directory"].as()); + } + + + }; + } \ No newline at end of file diff --git a/Editor/src/Project.h b/Editor/src/Project.h index 7ddb511..609c78f 100644 --- a/Editor/src/Project.h +++ b/Editor/src/Project.h @@ -1,13 +1,22 @@ #pragma once #include +#include class Project { public: + Project() = default; 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 LoadProject(std::filesystem::path path, Project& project); + static void LoadProject(std::filesystem::path path, std::shared_ptr& project); private: std::string Name; - + std::filesystem::path ProjectDirectory; }; diff --git a/Editor/src/main.cpp b/Editor/src/main.cpp index 625ca42..b1689b6 100644 --- a/Editor/src/main.cpp +++ b/Editor/src/main.cpp @@ -10,7 +10,7 @@ #include "../../YoggieEngine/src/Graphics/Memory/Framebuffer.h" #include "../../YoggieEngine/src/PerfCounter.cpp" #include "../../YoggieEngine/src/Scene/Entity.h" -#include "Widgets.h" +#include "UI/Widgets.h" #include "Project.h" #include "SceneSerializer.h" @@ -30,7 +30,7 @@ struct EditorContext { ~EditorContext() = default; }; -Project CurrentProject ("test"); +std::shared_ptr CurrentProject; Scene MainScene; Framebuffer* framebuffer; @@ -46,6 +46,7 @@ entt::entity Selected; */ void Start() { + CurrentProject = std::make_shared("Random"); auto io = ImGui::GetIO(); io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18); @@ -96,7 +97,6 @@ void ImmediateGraphicsDraw() ImGui::BeginMainMenuBar(); - ImGui::PushItemFlag(ImGuiItemFlags_SelectableDontClosePopup, true); if (ImGui::BeginMenu("Application")) { if (ImGui::MenuItem("Load Project")) @@ -120,7 +120,7 @@ void ImmediateGraphicsDraw() switch (result) { case(NFD_OKAY): std::cout << "Save as: " << savePath << std::endl; - Project::SaveProject(savePath, CurrentProject); + Project::SaveProject(savePath, *CurrentProject.get()); break; case(NFD_CANCEL): break; @@ -144,7 +144,6 @@ void ImmediateGraphicsDraw() ImGui::EndMenu(); } - ImGui::PopItemFlag(); if (ImGui::BeginMenu("Scene")) { @@ -191,6 +190,11 @@ void ImmediateGraphicsDraw() 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(); Viewport(*framebuffer, MainScene); @@ -202,7 +206,7 @@ void ImmediateGraphicsDraw() Console(); ImGui::ShowDemoWindow(); - ImGui::ShowMetricsWindow(); + ImGui::ShowMetricsWindow(); }