diff --git a/.gitmodules b/.gitmodules index 5f05e41..2d108a0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -36,3 +36,6 @@ [submodule "libs/nativefiledialog"] path = libs/nativefiledialog url = https://git.barink.dev/Nigel/nativefiledialog.git +[submodule "libs/mINI"] + path = libs/mINI + url = https://github.com/pulzed/mINI.git diff --git a/Editor/Assets/Cube.mesh b/Editor/Assets/Cube.mesh deleted file mode 100644 index 939f1b1..0000000 Binary files a/Editor/Assets/Cube.mesh and /dev/null differ diff --git a/Editor/premake5.lua b/Editor/premake5.lua index de713ef..3716f50 100644 --- a/Editor/premake5.lua +++ b/Editor/premake5.lua @@ -30,6 +30,7 @@ includedirs{ incfolder["entt"], incfolder["yamlcpp"], incfolder["nativefiledialog"], + incfolder["mINI"] } diff --git a/Editor/src/MainMenuBar.cpp b/Editor/src/MainMenuBar.cpp index 1f73a22..f6a734a 100644 --- a/Editor/src/MainMenuBar.cpp +++ b/Editor/src/MainMenuBar.cpp @@ -47,6 +47,9 @@ void MainMenuBar::ApplicationMenu(Project& project) { } + + + if (ImGui::MenuItem("Preferences")) { @@ -72,6 +75,9 @@ void MainMenuBar::SceneMenu(Project& project, YoggieEngine::Scene& scene) { switch (result) { case(NFD_OKAY): SaveScene(path, scene); + + project.AddScene(scene); + break; case(NFD_CANCEL): break; diff --git a/Editor/src/Project/Project.cpp b/Editor/src/Project/Project.cpp index 9cbcf71..0dc025e 100644 --- a/Editor/src/Project/Project.cpp +++ b/Editor/src/Project/Project.cpp @@ -13,6 +13,15 @@ void Project::SaveProject(std::filesystem::path path, Project& project) 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()); @@ -56,10 +65,12 @@ namespace YAML { return false; rhs.setName(node["Project"].as()); rhs.setProjectDirectory(node["Directory"].as()); + + + return true; } - }; } \ No newline at end of file diff --git a/Editor/src/Project/Project.h b/Editor/src/Project/Project.h index 836ce0b..35dff87 100644 --- a/Editor/src/Project/Project.h +++ b/Editor/src/Project/Project.h @@ -1,6 +1,10 @@ #pragma once #include #include +#include "../../YoggieEngine/src/YoggieEngine.h" +#include + + class Project { public: Project() = default; @@ -13,10 +17,21 @@ public: void setProjectDirectory(std::string& path) { ProjectDirectory = std::filesystem::path(path); } const std::filesystem::path GetProjectDirectory() { return ProjectDirectory; } + + void AddScene(YoggieEngine::Scene& scene) + { + Scenes.push_back(&scene); + } + static void SaveProject(std::filesystem::path path, Project& project); static void LoadProject(std::filesystem::path path, Project& project); private: std::string Name; std::filesystem::path ProjectDirectory; + + std::vector Scenes; + + friend class YAML::convert; + }; diff --git a/Editor/src/app.cpp b/Editor/src/app.cpp index 471e267..0a59ff9 100644 --- a/Editor/src/app.cpp +++ b/Editor/src/app.cpp @@ -1,14 +1,10 @@ #include "../../YoggieEngine/src/EntryPoint.h" -#include "../../YoggieEngine/src/AssetManager/ModelImporter.h" -#include "../../YoggieEngine/src/Physics/Physics.h" - -#include +#include #include #include #include -#include "Project/Project.h" #include "AssetManagement/SceneSerializer.h" #include "AssetManagement/AssetManager.h" @@ -31,9 +27,15 @@ public: void Run() override { + std::string path = (std::filesystem::current_path()).string(); + project.setProjectDirectory(path); + + AssetManager::Init(); + AssetManager::setAssetPath(project.GetProjectDirectory()); + AssetManager::BuildAssetView(); + LoadLastOrEmptyProject(); - MainMenuBar menuBar = MainMenuBar(); ProjectInfo projectInfo(project); Viewport sceneview = Viewport(scene); RuntimeControls rc = RuntimeControls(); @@ -114,14 +116,18 @@ public: } GuiBegin(); + { + MainMenuBar menuBar = MainMenuBar(); - // Show a menu bar - menuBar.ApplicationMenu(project); - menuBar.SceneMenu(project, scene); - menuBar.SelectMenu(); - menuBar.WindowMenu(); - menuBar.DebugMenu(); - menuBar.Help(); + // Show a menu bar + menuBar.ApplicationMenu(project); + menuBar.SceneMenu(project, scene); + menuBar.SelectMenu(); + menuBar.WindowMenu(); + menuBar.DebugMenu(); + menuBar.Help(); + + } if (scene.getReg().valid(Selected)) { @@ -156,43 +162,29 @@ public: // Otherwise load no project.. // OR // Load an empty project. + mINI::INIStructure ini; + - std::string path = (std::filesystem::current_path()).string(); - project.setProjectDirectory(path); + if (std::filesystem::exists("build\\Debug\\Editor.ini")) + { + mINI::INIFile file("build\\Debug\\Editor.ini"); + file.read(ini); + } + else + { + spdlog::debug("Could not find an `Editor.ini` file."); + } - AssetManager::Init(); - AssetManager::setAssetPath(project.GetProjectDirectory()); - AssetManager::BuildAssetView(); + if (ini["editor"]["openlastproject"] == "TRUE") + { + Project::LoadProject(ini["cache"]["project"], project); + LoadScene(ini["cache"]["scene"], scene); - // Create a level and load it as the current level - auto importer = ModelImporter(); - - - // create an ambient light source - auto light = scene.AddEntity("Light"); - auto& lightComponent = light.AddComponent(); - lightComponent.Color = glm::vec3(1.0f); - - - // Create a cube - auto model = importer.Import("build/Debug/Models/Cube.obj"); - - auto cube = scene.AddEntity("Cube"); - auto& render3DComponent = cube.AddComponent(); - render3DComponent.mesh = *(model->renderable->mesh); - - cube.GetComponent().Position = glm::vec3(1.0f, 0.0f, 5.0f); - - auto cube2 = scene.AddEntity("Cube2"); - auto& rendercube2 = cube2.AddComponent(); - rendercube2.mesh = *(model->renderable->mesh); - auto& relationcube = cube.AddComponent(cube2); - auto& rigidbodycomp = cube.AddComponent(); - auto& rigidbodycomp2 = cube2.AddComponent(); - - - auto Grass = scene.AddEntity("Grass/Window-Pane"); - //auto& renderGrass = Grass.AddComponent(); + } + else + { + spdlog::debug("Starting without a project. Please create one."); + } } private: diff --git a/YoggieEngine/src/Scene/Scene.cpp b/YoggieEngine/src/Scene/Scene.cpp index 3e26f0a..09ba79b 100644 --- a/YoggieEngine/src/Scene/Scene.cpp +++ b/YoggieEngine/src/Scene/Scene.cpp @@ -4,6 +4,11 @@ using namespace entt; namespace YoggieEngine{ + + Scene::Scene(const std::string& name): name(name) + { + } + Scene::Scene() { } diff --git a/YoggieEngine/src/Scene/Scene.h b/YoggieEngine/src/Scene/Scene.h index b001f4f..54c7b34 100644 --- a/YoggieEngine/src/Scene/Scene.h +++ b/YoggieEngine/src/Scene/Scene.h @@ -4,6 +4,7 @@ namespace YoggieEngine { class Scene { public: + Scene(const std::string& name ); Scene(); ~Scene(); @@ -15,6 +16,7 @@ namespace YoggieEngine { void Stop(); entt::registry& getReg() { return m_registry; } + std::string name; private: entt::registry m_registry; diff --git a/libraries.lua b/libraries.lua index af99809..421039f 100644 --- a/libraries.lua +++ b/libraries.lua @@ -6,7 +6,7 @@ incfolder["assimp"] = "%{wks.location}/libs/assimp/include" incfolder["glm"] = "%{wks.location}/libs/glm" incfolder["entt"] = "%{wks.location}/libs/entt/src" incfolder["yamlcpp"] = "%{wks.location}/libs/yaml-cpp/include" - +incfolder["mINI"] = "%{wks.location}/libs/mINI/src" -- Graphics incfolder["glad"] = "%{wks.location}/libs/glad/include" incfolder["glfw"] = "%{wks.location}/libs/glfw/include" diff --git a/libs/mINI b/libs/mINI new file mode 160000 index 0000000..a1ff72e --- /dev/null +++ b/libs/mINI @@ -0,0 +1 @@ +Subproject commit a1ff72e8898db8b53282e9eb7c7ec5973519787e