diff --git a/include/NazaraEditor/Core.hpp b/include/NazaraEditor/Core.hpp index 6bee6a2..5082203 100644 --- a/include/NazaraEditor/Core.hpp +++ b/include/NazaraEditor/Core.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/NazaraEditor/Core/Application/BaseApplication.hpp b/include/NazaraEditor/Core/Application/BaseApplication.hpp index 6719b6d..3af712d 100644 --- a/include/NazaraEditor/Core/Application/BaseApplication.hpp +++ b/include/NazaraEditor/Core/Application/BaseApplication.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -17,7 +18,7 @@ namespace Nz : public Nz::Application { public: - NazaraSignal(OnWorldChanged, Nz::EnttWorld*); + NazaraSignal(OnWorldChanged, Nz::Level&); // Entity lifetime events NazaraSignal(OnEntityCreated, entt::handle); @@ -30,8 +31,10 @@ namespace Nz EditorBaseApplication(); - void NewWorld(); - Nz::EnttWorld* GetCurrentWorld(); + Nz::Level& GetLevel(); + bool NewLevel(); + bool CloseLevel(); + bool OpenLevel(const std::filesystem::path& path); entt::handle CreateEntity(); @@ -44,12 +47,10 @@ namespace Nz private: std::unique_ptr m_windowSwapchain; - Nz::EnttWorld* m_world; - std::vector> m_windows; - std::vector> m_actions; static EditorBaseApplication* s_instance; + Nz::Level m_level; }; } \ No newline at end of file diff --git a/include/NazaraEditor/Core/Application/Level.hpp b/include/NazaraEditor/Core/Application/Level.hpp new file mode 100644 index 0000000..dacf70c --- /dev/null +++ b/include/NazaraEditor/Core/Application/Level.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include + +namespace Nz +{ + class EditorBaseApplication; + + class NAZARAEDITOR_CORE_API Level final + { + public: + Level(EditorBaseApplication* app); + + inline bool IsValid() const { return m_world != nullptr; } + + inline Nz::EnttWorld* GetEnttWorld() { return m_world; } + inline const Nz::EnttWorld* GetEnttWorld() const { return m_world; } + + entt::handle CreateEntity(); + bool CreateNewLevel(); + + protected: + EditorBaseApplication* m_application; + + Nz::EnttWorld* m_world; + + std::filesystem::path m_path; + std::string m_name; + }; +} \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/BaseApplication.cpp b/src/NazaraEditor/Core/Application/BaseApplication.cpp index d657cbf..6a55c00 100644 --- a/src/NazaraEditor/Core/Application/BaseApplication.cpp +++ b/src/NazaraEditor/Core/Application/BaseApplication.cpp @@ -2,10 +2,8 @@ namespace Nz { - EditorBaseApplication* EditorBaseApplication::s_instance = nullptr; - EditorBaseApplication::EditorBaseApplication() - : m_world(nullptr) + : m_level(this) { s_instance = this; @@ -28,7 +26,7 @@ namespace Nz Nz::Imgui::Instance()->Init(window); ImGui::EnsureContextOnThisThread(); - NewWorld(); + NewLevel(); AddUpdaterFunc(Interval{ Nz::Time::Milliseconds(16) }, [&](Nz::Time elapsed) { if (!window.IsOpen()) @@ -48,17 +46,14 @@ namespace Nz }); } - Nz::EnttWorld* EditorBaseApplication::GetCurrentWorld() + Nz::Level& EditorBaseApplication::GetLevel() { - return m_world; + return m_level; } entt::handle EditorBaseApplication::CreateEntity() { - if (m_world == nullptr) - return {}; - - entt::handle entity = m_world->CreateEntity(); + entt::handle entity = m_level.CreateEntity(); entity.emplace(); OnEntityCreated(entity); @@ -66,9 +61,8 @@ namespace Nz return entity; } - void EditorBaseApplication::NewWorld() + bool EditorBaseApplication::NewLevel() { - auto& ecs = GetComponent(); - m_world = &ecs.AddWorld(); + return m_level.CreateNewLevel(); } } \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/Level.cpp b/src/NazaraEditor/Core/Application/Level.cpp new file mode 100644 index 0000000..f999f6b --- /dev/null +++ b/src/NazaraEditor/Core/Application/Level.cpp @@ -0,0 +1,23 @@ +#include + +#include + +namespace Nz +{ + Level::Level(EditorBaseApplication* app) + : m_application(app) + , m_world(nullptr) + {} + + entt::handle Level::CreateEntity() + { + return m_world->CreateEntity(); + } + + bool Level::CreateNewLevel() + { + auto& ecs = m_application->GetComponent(); + m_world = &ecs.AddWorld(); + return true; + } +} \ No newline at end of file diff --git a/src/NazaraEditor/Editor/UI/LevelWindow.cpp b/src/NazaraEditor/Editor/UI/LevelWindow.cpp index afdb683..4d7267b 100644 --- a/src/NazaraEditor/Editor/UI/LevelWindow.cpp +++ b/src/NazaraEditor/Editor/UI/LevelWindow.cpp @@ -6,10 +6,10 @@ namespace NzEditor { LevelWindow::LevelWindow(Nz::EditorBaseApplication* app) : Nz::EditorWindow(app, "Level") - , m_currentWorld(app->GetCurrentWorld()) + , m_currentLevel(app->GetLevel()) , m_dirty(true) { - app->OnWorldChanged.Connect([this](Nz::EnttWorld* world) { m_currentWorld = world; m_dirty = true; }); + app->OnWorldChanged.Connect([this](Nz::Level&) { m_dirty = true; }); app->OnEntityCreated.Connect([this](entt::handle) { m_dirty = true; }); app->OnEntityDestroyed.Connect([this](entt::handle) { m_dirty = true; }); app->OnEntityParentChanged.Connect([this](entt::handle) { m_dirty = true; }); @@ -41,7 +41,7 @@ namespace NzEditor m_rootNodes.clear(); m_nodeToEntity.clear(); - if (m_currentWorld == nullptr) + if (!m_currentLevel.IsValid()) return; m_currentWorld->GetRegistry().each([&](const entt::entity entity) {