#pragma once #include "Scene/EditorSceneBackend.h" #include "Scene/SceneToolState.h" #include "State/EditorSelectionService.h" #include #include #include #include #include #include #include namespace XCEngine::Math { struct Quaternion; struct Vector3; } // namespace XCEngine::Math namespace XCEngine::Components { class Scene; } // namespace XCEngine::Components namespace XCEngine::UI::Editor::App { class EditorSceneRuntime { public: EditorSceneRuntime() = default; EditorSceneRuntime(const EditorSceneRuntime&) = delete; EditorSceneRuntime& operator=(const EditorSceneRuntime&) = delete; EditorSceneRuntime(EditorSceneRuntime&&) = delete; EditorSceneRuntime& operator=(EditorSceneRuntime&&) = delete; void Reset(); void SetBackend(std::unique_ptr backend); EditorStartupSceneResult Initialize(const std::filesystem::path& projectRoot); void BindSelectionService(EditorSelectionService* selectionService); void RefreshScene(); void EnsureSceneSelection(); EditorSceneHierarchySnapshot BuildHierarchySnapshot() const; std::vector BuildSceneViewportIconSnapshots() const; std::optional BuildSceneViewportSelectionSnapshot() const; std::vector BuildSelectedViewportHelperSnapshots() const; bool HasSceneSelection() const; std::optional GetSelectedObjectId() const; std::string GetSelectedItemId() const; std::string GetSelectedDisplayName() const; std::optional GetSelectedObjectSnapshot() const; std::vector GetSelectedComponents() const; std::uint64_t GetSelectionStamp() const; std::uint64_t GetInspectorRevision() const; std::uint64_t GetSceneContentRevision() const; bool SetSelection(std::string_view itemId); bool SetSelection(EditorSceneObjectId id); void ClearSelection(); bool NewScene(std::string_view sceneName); bool OpenSceneAsset(const std::filesystem::path& scenePath); bool SaveScene(const std::filesystem::path& scenePath); ::XCEngine::Components::Scene* GetActiveScene() const; std::string GetActiveSceneName() const; std::unique_ptr BeginPlaySession(); bool RenameGameObject( std::string_view itemId, std::string_view newName); bool DeleteGameObject(std::string_view itemId); std::string DuplicateGameObject(std::string_view itemId); bool ReparentGameObject( std::string_view itemId, std::string_view parentItemId); bool MoveGameObjectBefore( std::string_view itemId, std::string_view targetItemId); bool MoveGameObjectAfter( std::string_view itemId, std::string_view targetItemId); bool MoveGameObjectToRoot(std::string_view itemId); bool AddComponentToSelectedGameObject(std::string_view componentTypeName); bool CanRemoveSelectedComponent(std::string_view componentId) const; bool RemoveSelectedComponent(std::string_view componentId); bool SetSelectedTransformLocalPosition( std::string_view componentId, const ::XCEngine::Math::Vector3& position); bool SetSelectedTransformLocalEulerAngles( std::string_view componentId, const ::XCEngine::Math::Vector3& eulerAngles); bool SetSelectedTransformLocalScale( std::string_view componentId, const ::XCEngine::Math::Vector3& scale); bool ApplySelectedComponentMutation( const EditorSceneComponentMutation& mutation); bool CaptureSelectedTransformSnapshot(SceneTransformSnapshot& outSnapshot) const; bool ApplyTransformToolWorldPreview( EditorSceneObjectId targetId, const ::XCEngine::Math::Vector3& position, const ::XCEngine::Math::Quaternion& rotation); bool ApplyTransformToolLocalScalePreview( EditorSceneObjectId targetId, const ::XCEngine::Math::Vector3& localScale); bool BeginSceneEditTransaction(std::string_view label); bool HasPendingSceneEditTransaction() const; bool CommitSceneEditTransaction(); bool CancelSceneEditTransaction(); bool CanUndoSceneEdit() const; bool CanRedoSceneEdit() const; bool UndoSceneEdit(); bool RedoSceneEdit(); void NotifyExternalInspectorStateChanged(); private: struct SceneEditStateSnapshot { std::string sceneSnapshot = {}; EditorSelectionState selection = {}; }; struct SceneEditTransaction { std::string label = {}; SceneEditStateSnapshot before = {}; SceneEditStateSnapshot after = {}; }; struct PendingSceneEditTransaction { std::string label = {}; SceneEditStateSnapshot before = {}; }; EditorSelectionService& SelectionService(); const EditorSelectionService& SelectionService() const; bool HasHierarchySelection() const; void RevalidateSelection(); bool HasValidSelection() const; std::optional GetObjectSnapshot( std::string_view itemId) const; EditorSceneComponentDescriptor ResolveSelectedComponentDescriptor( std::string_view componentId) const; bool SelectFirstAvailableGameObject(); bool CaptureSceneEditState(SceneEditStateSnapshot& outSnapshot) const; bool RestoreSceneEditState(const SceneEditStateSnapshot& snapshot); void ResetSceneEditHistory(); void ClearPendingSceneEditTransaction(); bool FinalizePendingSceneEditTransaction(bool& outChanged); void IncrementInspectorRevision(); void IncrementSceneContentRevision(); std::filesystem::path m_projectRoot = {}; std::unique_ptr m_backend = {}; EditorSelectionService m_ownedSelectionService = {}; EditorSelectionService* m_selectionService = &m_ownedSelectionService; std::vector m_sceneUndoStack = {}; std::vector m_sceneRedoStack = {}; std::optional m_pendingSceneEditTransaction = {}; std::uint64_t m_inspectorRevision = 0u; std::uint64_t m_sceneContentRevision = 0u; }; } // namespace XCEngine::UI::Editor::App