102 lines
4.0 KiB
C++
102 lines
4.0 KiB
C++
#pragma once
|
|
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
#include <XCEngine/Core/Event.h>
|
|
#include <XCEngine/Core/Math/Vector3.h>
|
|
#include <XCEngine/Core/Math/Quaternion.h>
|
|
#include <XCEngine/Components/GameObject.h>
|
|
#include <XCEngine/Scene/Scene.h>
|
|
|
|
#include "Core/SceneSnapshot.h"
|
|
#include "Core/ISceneManager.h"
|
|
|
|
namespace XCEngine {
|
|
namespace Editor {
|
|
|
|
class EventBus;
|
|
|
|
class SceneManager : public ISceneManager {
|
|
public:
|
|
explicit SceneManager(EventBus* eventBus = nullptr);
|
|
|
|
::XCEngine::Components::GameObject* CreateEntity(const std::string& name, ::XCEngine::Components::GameObject* parent = nullptr);
|
|
|
|
::XCEngine::Components::GameObject* GetEntity(::XCEngine::Components::GameObject::ID id) {
|
|
return m_scene ? m_scene->FindByID(id) : nullptr;
|
|
}
|
|
|
|
const ::XCEngine::Components::GameObject* GetEntity(::XCEngine::Components::GameObject::ID id) const {
|
|
return m_scene ? m_scene->FindByID(id) : nullptr;
|
|
}
|
|
|
|
const std::vector<::XCEngine::Components::GameObject*>& GetRootEntities() const {
|
|
return m_rootEntities;
|
|
}
|
|
|
|
void DeleteEntity(::XCEngine::Components::GameObject::ID id);
|
|
|
|
void RenameEntity(::XCEngine::Components::GameObject::ID id, const std::string& newName);
|
|
|
|
void CopyEntity(::XCEngine::Components::GameObject::ID id);
|
|
::XCEngine::Components::GameObject::ID PasteEntity(::XCEngine::Components::GameObject::ID parent = 0);
|
|
::XCEngine::Components::GameObject::ID DuplicateEntity(::XCEngine::Components::GameObject::ID id);
|
|
void MoveEntity(::XCEngine::Components::GameObject::ID id, ::XCEngine::Components::GameObject::ID newParent);
|
|
|
|
void NewScene(const std::string& name = "Untitled Scene") override;
|
|
bool LoadScene(const std::string& filePath) override;
|
|
bool SaveScene() override;
|
|
bool SaveSceneAs(const std::string& filePath) override;
|
|
bool LoadStartupScene(const std::string& projectPath) override;
|
|
bool HasActiveScene() const override { return m_scene != nullptr; }
|
|
bool IsSceneDirty() const override { return m_isSceneDirty; }
|
|
void MarkSceneDirty() override;
|
|
const std::string& GetCurrentScenePath() const override { return m_currentScenePath; }
|
|
const std::string& GetCurrentSceneName() const override { return m_currentSceneName; }
|
|
void CreateDemoScene() override;
|
|
|
|
bool HasClipboardData() const { return m_clipboard.has_value(); }
|
|
SceneSnapshot CaptureSceneSnapshot() const;
|
|
bool RestoreSceneSnapshot(const SceneSnapshot& snapshot);
|
|
|
|
::XCEngine::Core::Event<::XCEngine::Components::GameObject::ID> OnEntityCreated;
|
|
::XCEngine::Core::Event<::XCEngine::Components::GameObject::ID> OnEntityDeleted;
|
|
::XCEngine::Core::Event<::XCEngine::Components::GameObject::ID> OnEntityChanged;
|
|
::XCEngine::Core::Event<> OnSceneChanged;
|
|
|
|
private:
|
|
struct ClipboardData {
|
|
std::string name;
|
|
Math::Vector3 localPosition = Math::Vector3::Zero();
|
|
Math::Quaternion localRotation = Math::Quaternion::Identity();
|
|
Math::Vector3 localScale = Math::Vector3::One();
|
|
std::vector<std::pair<std::string, std::string>> components;
|
|
std::vector<ClipboardData> children;
|
|
};
|
|
|
|
ClipboardData CopyEntityRecursive(const ::XCEngine::Components::GameObject* entity);
|
|
::XCEngine::Components::GameObject::ID PasteEntityRecursive(const ClipboardData& data, ::XCEngine::Components::GameObject::ID parent);
|
|
void SetSceneDirty(bool dirty);
|
|
void SyncRootEntities();
|
|
static std::string GetScenesDirectory(const std::string& projectPath);
|
|
static std::string ResolveDefaultScenePath(const std::string& projectPath);
|
|
static bool IsSceneFileUsable(const std::string& filePath);
|
|
|
|
std::unique_ptr<::XCEngine::Components::Scene> m_scene;
|
|
std::vector<::XCEngine::Components::GameObject*> m_rootEntities;
|
|
std::optional<ClipboardData> m_clipboard;
|
|
EventBus* m_eventBus = nullptr;
|
|
std::string m_currentScenePath;
|
|
std::string m_currentSceneName = "Untitled Scene";
|
|
bool m_isSceneDirty = false;
|
|
};
|
|
|
|
}
|
|
}
|