test(editor): cover multi-select component mutations
This commit is contained in:
parent
0a6ee85e08
commit
922858b135
@ -4065,6 +4065,62 @@ void MetaCoreTestComponentRegistryOperations() {
|
||||
MetaCoreExpect(cameraDescriptor->ResetComponent(pasteTarget), "应能重置 Camera");
|
||||
MetaCoreExpect(std::abs(pasteTarget.GetComponent<MetaCore::MetaCoreCameraComponent>().FieldOfViewDegrees - 60.0F) <= 0.0001F, "重置后 Camera 应恢复默认值");
|
||||
|
||||
MetaCore::MetaCoreGameObject partialA = scene.CreateGameObject("PartialComponentA");
|
||||
MetaCore::MetaCoreGameObject partialB = scene.CreateGameObject("PartialComponentB");
|
||||
MetaCore::MetaCoreGameObject partialC = scene.CreateGameObject("PartialComponentC");
|
||||
const MetaCore::MetaCoreId partialAId = partialA.GetId();
|
||||
const MetaCore::MetaCoreId partialBId = partialB.GetId();
|
||||
const MetaCore::MetaCoreId partialCId = partialC.GetId();
|
||||
MetaCoreExpect(lightDescriptor->AddComponent(partialA), "应能为部分选中对象预置 Light");
|
||||
MetaCoreExpect(lightDescriptor->AddComponent(partialC), "应能为另一个部分选中对象预置 Light");
|
||||
|
||||
editorContext.SetSelection({partialAId, partialBId, partialCId}, partialAId);
|
||||
const bool addedLightToMissingSelection = editorContext.ExecuteSnapshotCommand("补齐选中对象 Light", [&]() {
|
||||
bool changed = false;
|
||||
for (const MetaCore::MetaCoreId selectedId : editorContext.GetSelectedObjectIds()) {
|
||||
MetaCore::MetaCoreGameObject selectedObject = scene.FindGameObject(selectedId);
|
||||
if (selectedObject) {
|
||||
changed = lightDescriptor->AddComponent(selectedObject) || changed;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
});
|
||||
MetaCoreExpect(addedLightToMissingSelection, "多选部分拥有时应能补齐缺失 Light");
|
||||
MetaCoreExpect(scene.FindGameObject(partialAId).HasComponent<MetaCore::MetaCoreLightComponent>(), "补齐后原拥有对象 A 应保留 Light");
|
||||
MetaCoreExpect(scene.FindGameObject(partialBId).HasComponent<MetaCore::MetaCoreLightComponent>(), "补齐后缺失对象 B 应拥有 Light");
|
||||
MetaCoreExpect(scene.FindGameObject(partialCId).HasComponent<MetaCore::MetaCoreLightComponent>(), "补齐后原拥有对象 C 应保留 Light");
|
||||
|
||||
MetaCoreExpect(editorContext.UndoCommand(), "补齐多选组件后应可 Undo");
|
||||
MetaCoreExpect(scene.FindGameObject(partialAId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Undo 补齐后对象 A 应仍有 Light");
|
||||
MetaCoreExpect(!scene.FindGameObject(partialBId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Undo 补齐后对象 B 应恢复为缺失 Light");
|
||||
MetaCoreExpect(scene.FindGameObject(partialCId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Undo 补齐后对象 C 应仍有 Light");
|
||||
MetaCoreExpect(editorContext.RedoCommand(), "补齐多选组件后应可 Redo");
|
||||
MetaCoreExpect(scene.FindGameObject(partialBId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Redo 补齐后对象 B 应再次拥有 Light");
|
||||
|
||||
const bool removedLightFromPresentSelection = editorContext.ExecuteSnapshotCommand("移除选中对象 Light", [&]() {
|
||||
bool changed = false;
|
||||
for (const MetaCore::MetaCoreId selectedId : editorContext.GetSelectedObjectIds()) {
|
||||
MetaCore::MetaCoreGameObject selectedObject = scene.FindGameObject(selectedId);
|
||||
if (selectedObject) {
|
||||
changed = lightDescriptor->RemoveComponent(selectedObject) || changed;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
});
|
||||
MetaCoreExpect(removedLightFromPresentSelection, "多选部分拥有面板应能移除已有 Light");
|
||||
MetaCoreExpect(!scene.FindGameObject(partialAId).HasComponent<MetaCore::MetaCoreLightComponent>(), "移除后对象 A 不应有 Light");
|
||||
MetaCoreExpect(!scene.FindGameObject(partialBId).HasComponent<MetaCore::MetaCoreLightComponent>(), "移除后对象 B 不应有 Light");
|
||||
MetaCoreExpect(!scene.FindGameObject(partialCId).HasComponent<MetaCore::MetaCoreLightComponent>(), "移除后对象 C 不应有 Light");
|
||||
|
||||
MetaCoreExpect(editorContext.UndoCommand(), "移除多选组件后应可 Undo");
|
||||
MetaCoreExpect(scene.FindGameObject(partialAId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Undo 移除后对象 A 应恢复 Light");
|
||||
MetaCoreExpect(scene.FindGameObject(partialBId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Undo 移除后对象 B 应恢复 Light");
|
||||
MetaCoreExpect(scene.FindGameObject(partialCId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Undo 移除后对象 C 应恢复 Light");
|
||||
MetaCoreExpect(editorContext.RedoCommand(), "移除多选组件后应可 Redo");
|
||||
MetaCoreExpect(!scene.FindGameObject(partialAId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Redo 移除后对象 A 不应有 Light");
|
||||
MetaCoreExpect(!scene.FindGameObject(partialBId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Redo 移除后对象 B 不应有 Light");
|
||||
MetaCoreExpect(!scene.FindGameObject(partialCId).HasComponent<MetaCore::MetaCoreLightComponent>(), "Redo 移除后对象 C 不应有 Light");
|
||||
|
||||
coreServicesModule->Shutdown(moduleRegistry);
|
||||
moduleRegistry.ShutdownServices();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user