Load the previously loaded project and scene on startup

(read from an ini file)
This commit is contained in:
2023-01-14 21:44:48 +01:00
parent 145338d666
commit 282844b905
11 changed files with 85 additions and 49 deletions

View File

@ -1,14 +1,10 @@
#include "../../YoggieEngine/src/EntryPoint.h"
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
#include "../../YoggieEngine/src/Physics/Physics.h"
#include <nfd.h>
#include <mini/ini.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#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>();
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>();
render3DComponent.mesh = *(model->renderable->mesh);
cube.GetComponent<TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f);
auto cube2 = scene.AddEntity("Cube2");
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
rendercube2.mesh = *(model->renderable->mesh);
auto& relationcube = cube.AddComponent<RelationComponent>(cube2);
auto& rigidbodycomp = cube.AddComponent<RigidBody>();
auto& rigidbodycomp2 = cube2.AddComponent<RigidBody>();
auto Grass = scene.AddEntity("Grass/Window-Pane");
//auto& renderGrass = Grass.AddComponent<Render3DComponent>();
}
else
{
spdlog::debug("Starting without a project. Please create one.");
}
}
private: