Loading Projects now
This commit is contained in:
		| @ -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>& 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<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 | ||||
| #include <filesystem> | ||||
| #include <iostream> | ||||
| 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>& project); | ||||
| private: | ||||
| 	std::string Name; | ||||
|  | ||||
| 	std::filesystem::path ProjectDirectory; | ||||
| }; | ||||
|  | ||||
|  | ||||
| @ -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<Project> CurrentProject; | ||||
| Scene MainScene; | ||||
|  | ||||
| Framebuffer* framebuffer; | ||||
| @ -46,6 +46,7 @@ entt::entity  Selected; | ||||
| */ | ||||
| void Start() { | ||||
|  | ||||
|     CurrentProject = std::make_shared<Project>("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(); | ||||
|     | ||||
|  | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user