Fix undo for nested prefab creation by providing link patches to the undo node

This commit is contained in:
srikappa
2021-04-29 17:02:44 -07:00
parent 6947e8fe29
commit d433cd623b
7 changed files with 75 additions and 19 deletions
@@ -96,9 +96,12 @@ namespace AzToolsFramework
// target templates of the other instances.
for (auto& nestedInstance : instances)
{
PrefabUndoHelpers::RemoveLink(
nestedInstance->GetTemplateId(), commonRootEntityOwningInstance->get().GetTemplateId(),
nestedInstance->GetInstanceAlias(), nestedInstance->GetLinkId(), undoBatch.GetUndoBatch());
PrefabOperationResult removeLinkResult = RemoveLink(
nestedInstance, commonRootEntityOwningInstance->get().GetTemplateId(), undoBatch.GetUndoBatch());
if (!removeLinkResult.IsSuccess())
{
return removeLinkResult;
}
}
PrefabUndoHelpers::UpdatePrefabInstance(
@@ -287,6 +290,49 @@ namespace AzToolsFramework
m_prefabUndoCache.Store(containerEntityId, AZStd::move(containerEntityDomAfter));
}
PrefabOperationResult PrefabPublicHandler::RemoveLink(
AZStd::unique_ptr<Instance>& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch)
{
LinkReference nestedInstanceLink = m_prefabSystemComponentInterface->FindLink(sourceInstance->GetLinkId());
if (!nestedInstanceLink.has_value())
{
AZ_Assert(false, "A valid link was not found for one of the instances provided as input for the CreatePrefab operation.");
return AZ::Failure(
AZStd::string("A valid link was not found for one of the instances provided as input for the CreatePrefab operation."));
}
PrefabDomReference nestedInstanceLinkDom = nestedInstanceLink->get().GetLinkDom();
if (!nestedInstanceLinkDom.has_value())
{
AZ_Assert(
false,
"A valid DOM was not found for the link corresponding to one of the instances provided as input for the "
"CreatePrefab operation.");
return AZ::Failure(AZStd::string("A valid DOM was not found for the link corresponding to one of the instances "
"provided as input for the CreatePrefab operation."));
}
PrefabDomValueReference nestedInstanceLinkPatches =
PrefabDomUtils::FindPrefabDomValue(nestedInstanceLinkDom->get(), PrefabDomUtils::PatchesName);
if (!nestedInstanceLinkPatches.has_value())
{
AZ_Assert(
false,
"A valid DOM for patches was not found for the link corresponding to one of the instances provided as input for the "
"CreatePrefab operation.");
return AZ::Failure(AZStd::string("A valid DOM for patcheswas not found for the link corresponding to one of the instances "
"provided as input for the CreatePrefab operation."));
}
PrefabDom patchesCopyForUndoSupport;
patchesCopyForUndoSupport.CopyFrom(nestedInstanceLinkPatches->get(), patchesCopyForUndoSupport.GetAllocator());
PrefabUndoHelpers::RemoveLink(
sourceInstance->GetTemplateId(), targetTemplateId, sourceInstance->GetInstanceAlias(), sourceInstance->GetLinkId(),
patchesCopyForUndoSupport, undoBatch);
return AZ::Success();
}
PrefabOperationResult PrefabPublicHandler::SavePrefab(AZ::IO::Path filePath)
{
auto templateId = m_prefabSystemComponentInterface->GetTemplateIdFromFilePath(filePath.c_str());