Changed FocusOnOwningPrefab to return Outcome. Added comments and error checking.

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
This commit is contained in:
Danilo Aimini
2021-09-20 12:18:23 -07:00
parent bd6705a06e
commit 71bf614912
4 changed files with 19 additions and 15 deletions
@@ -10,6 +10,7 @@
#include <AzCore/Component/TransformBus.h>
#include <AzToolsFramework/API/ViewportEditorModeTrackerInterface.h>
#include <AzToolsFramework/FocusMode/FocusModeSystemComponent.h>
namespace AzToolsFramework::FocusModeFramework
@@ -53,8 +54,7 @@ namespace AzToolsFramework::FocusModeFramework
{
m_focusRoot = entityId;
// TODO - If m_focusRoot != AZ::EntityId(), register focus mode
// Else, unregister focus mode
// TODO - If m_focusRoot != AZ::EntityId(), activate focus mode via ViewportEditorModeTrackerInterface; else, deactivate focus mode
}
AZ::EntityId FocusModeSystemComponent::GetFocusRoot()
@@ -49,7 +49,7 @@ namespace AzToolsFramework::Prefab
AZ::Interface<PrefabFocusInterface>::Register(this);
}
void PrefabFocusHandler::FocusOnOwningPrefab(AZ::EntityId entityId)
PrefabFocusOperationResult PrefabFocusHandler::FocusOnOwningPrefab(AZ::EntityId entityId)
{
InstanceOptionalReference focusedInstance;
@@ -64,12 +64,15 @@ namespace AzToolsFramework::Prefab
if (!focusedInstance.has_value())
{
// TODO - ERROR
return AZ::Failure(AZStd::string(
"Prefab Focus Handler: Couldn't find owning instance of entityId provided."));
}
m_focusedInstance = focusedInstance;
m_focusedTemplateId = focusedInstance->get().GetTemplateId();
s_focusModeInterface->SetFocusRoot(focusedInstance->get().GetContainerEntityId());
return AZ::Success();
}
TemplateId PrefabFocusHandler::GetFocusedPrefabTemplateId()
@@ -86,16 +89,12 @@ namespace AzToolsFramework::Prefab
{
if (entityId == AZ::EntityId())
{
// TODO - Warn?
return false;
}
InstanceOptionalReference instance = s_instanceEntityMapperInterface->FindOwningInstance(entityId);
if (!instance.has_value())
{
// TODO - ERROR
}
AZ_Assert(instance.has_value(), "PrefabFocusHandler::IsOwningPrefabBeingFocused - Could not find owning Instance of queried entity.");
return (&instance->get() == &m_focusedInstance->get());
}
@@ -39,7 +39,7 @@ namespace AzToolsFramework::Prefab
void Initialize();
// PrefabFocusInterface...
void FocusOnOwningPrefab(AZ::EntityId entityId) override;
PrefabFocusOperationResult FocusOnOwningPrefab(AZ::EntityId entityId) override;
TemplateId GetFocusedPrefabTemplateId() override;
InstanceOptionalReference GetFocusedPrefabInstance() override;
bool IsOwningPrefabBeingFocused(AZ::EntityId entityId) override;
@@ -16,6 +16,8 @@
namespace AzToolsFramework::Prefab
{
typedef AZ::Outcome<void, AZStd::string> PrefabFocusOperationResult;
/*!
* PrefabFocusInterface
*/
@@ -24,16 +26,19 @@ namespace AzToolsFramework::Prefab
public:
AZ_RTTI(PrefabFocusInterface, "{F3CFA37B-5FD8-436A-9C30-60EB54E350E1}");
// TODO - Add comment
virtual void FocusOnOwningPrefab(AZ::EntityId entityId) = 0;
//! Set the focused prefab instance to the owning instance of the entityId provided
//! @param entityId The entityId of the entity whose owning instance we want the prefab system to focus on.
virtual PrefabFocusOperationResult FocusOnOwningPrefab(AZ::EntityId entityId) = 0;
// TODO - Add comment
//! Returns the template id of the instance the prefab system is focusing on.
virtual TemplateId GetFocusedPrefabTemplateId() = 0;
// TODO - Add comment
//! Returns a reference to the instance the prefab system is focusing on.
virtual InstanceOptionalReference GetFocusedPrefabInstance() = 0;
// TODO - Add comment
//! Returns whether the entity belongs to the instance that is being focused on, or one of its descendants.
//! @param entityId The entityId of the queried entity.
//! @return true if the entity belongs to the focused instance or one of its descendants, false otherwise.
virtual bool IsOwningPrefabBeingFocused(AZ::EntityId entityId) = 0;
};