refactor(editor): isolate engine service boundaries
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "Inspector/Components/IInspectorComponentEditor.h"
|
||||
#include "Inspector/Components/InspectorComponentEditorRegistry.h"
|
||||
#include "Inspector/InspectorFieldValueApplier.h"
|
||||
#include "Inspector/InspectorPresentationModel.h"
|
||||
#include "Inspector/InspectorSubject.h"
|
||||
#include "Scene/EditorSceneRuntime.h"
|
||||
@@ -118,6 +119,20 @@ const UIEditorPropertyGridField* FindField(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const UIEditorPropertyGridField* FindFieldById(
|
||||
const InspectorPresentationModel& model,
|
||||
std::string_view fieldId) {
|
||||
for (const UIEditorPropertyGridSection& section : model.sections) {
|
||||
for (const UIEditorPropertyGridField& field : section.fields) {
|
||||
if (field.fieldId == fieldId) {
|
||||
return &field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const InspectorPresentationComponentBinding* FindBinding(
|
||||
const InspectorPresentationModel& model,
|
||||
std::string_view typeName) {
|
||||
@@ -201,7 +216,7 @@ TEST(InspectorPresentationModelTests, SceneObjectSubjectBuildsRegisteredComponen
|
||||
EditorSceneRuntime runtime = {};
|
||||
BindEngineSceneBackend(runtime);
|
||||
ASSERT_TRUE(runtime.Initialize(projectRoot.Root()));
|
||||
Scene* scene = runtime.GetActiveScene();
|
||||
Scene* scene = SceneManager::Get().GetActiveScene();
|
||||
ASSERT_NE(scene, nullptr);
|
||||
GameObject* parent = scene->Find("Parent");
|
||||
ASSERT_NE(parent, nullptr);
|
||||
@@ -273,7 +288,7 @@ TEST(InspectorPresentationModelTests, CameraSkyboxMaterialBuildsAssetField) {
|
||||
EditorSceneRuntime runtime = {};
|
||||
BindEngineSceneBackend(runtime);
|
||||
ASSERT_TRUE(runtime.Initialize(projectRoot.Root()));
|
||||
Scene* scene = runtime.GetActiveScene();
|
||||
Scene* scene = SceneManager::Get().GetActiveScene();
|
||||
ASSERT_NE(scene, nullptr);
|
||||
GameObject* parent = scene->Find("Parent");
|
||||
ASSERT_NE(parent, nullptr);
|
||||
@@ -302,5 +317,57 @@ TEST(InspectorPresentationModelTests, CameraSkyboxMaterialBuildsAssetField) {
|
||||
"Skybox.mat");
|
||||
}
|
||||
|
||||
TEST(InspectorPresentationModelTests, BoundFieldValueApplierKeepsComponentViewAliveDuringApply) {
|
||||
ScopedSceneManagerReset reset = {};
|
||||
TemporaryProjectRoot projectRoot = {};
|
||||
SaveMainScene(projectRoot);
|
||||
|
||||
EditorSceneRuntime runtime = {};
|
||||
BindEngineSceneBackend(runtime);
|
||||
ASSERT_TRUE(runtime.Initialize(projectRoot.Root()));
|
||||
Scene* scene = SceneManager::Get().GetActiveScene();
|
||||
ASSERT_NE(scene, nullptr);
|
||||
GameObject* parent = scene->Find("Parent");
|
||||
ASSERT_NE(parent, nullptr);
|
||||
ASSERT_TRUE(runtime.SetSelection(parent->GetID()));
|
||||
|
||||
const InspectorSubject subject =
|
||||
BuildInspectorSubject(EditorSession{}, runtime);
|
||||
ASSERT_EQ(subject.kind, InspectorSubjectKind::SceneObject);
|
||||
|
||||
const InspectorPresentationModel model =
|
||||
BuildInspectorPresentationModel(
|
||||
subject,
|
||||
runtime,
|
||||
InspectorComponentEditorRegistry::Get());
|
||||
const auto* transformBinding = FindBinding(model, "Transform");
|
||||
ASSERT_NE(transformBinding, nullptr);
|
||||
ASSERT_FALSE(transformBinding->fieldIds.empty());
|
||||
|
||||
const UIEditorPropertyGridField* originalField =
|
||||
FindFieldById(model, transformBinding->fieldIds.front());
|
||||
ASSERT_NE(originalField, nullptr);
|
||||
ASSERT_EQ(originalField->kind, Widgets::UIEditorPropertyGridFieldKind::Vector3);
|
||||
|
||||
UIEditorPropertyGridField editedField = *originalField;
|
||||
editedField.vector3Value.values = { 8.0, 9.0, 10.0 };
|
||||
|
||||
bool applied = false;
|
||||
EXPECT_NO_THROW(
|
||||
applied = ApplyInspectorComponentBoundFieldValue(
|
||||
runtime,
|
||||
subject.sceneObject,
|
||||
*transformBinding,
|
||||
editedField));
|
||||
ASSERT_TRUE(applied);
|
||||
|
||||
const auto* transform = parent->GetTransform();
|
||||
ASSERT_NE(transform, nullptr);
|
||||
const auto position = transform->GetLocalPosition();
|
||||
EXPECT_FLOAT_EQ(position.x, 8.0f);
|
||||
EXPECT_FLOAT_EQ(position.y, 9.0f);
|
||||
EXPECT_FLOAT_EQ(position.z, 10.0f);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
Reference in New Issue
Block a user