Initialization changes to pass unit tests. Some interfaces are now retrieved on demand and there's clearer failure paths that don't involve asserts to better handle test/headless initializations.
Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
This commit is contained in:
+2
-6
@@ -31,22 +31,18 @@ namespace AzToolsFramework
|
||||
return IsInFocusSubTree(parentId, focusRootId);
|
||||
}
|
||||
|
||||
FocusModeSystemComponent::~FocusModeSystemComponent()
|
||||
{
|
||||
AZ::Interface<FocusModeInterface>::Unregister(this);
|
||||
}
|
||||
|
||||
void FocusModeSystemComponent::Init()
|
||||
{
|
||||
AZ::Interface<FocusModeInterface>::Register(this);
|
||||
}
|
||||
|
||||
void FocusModeSystemComponent::Activate()
|
||||
{
|
||||
AZ::Interface<FocusModeInterface>::Register(this);
|
||||
}
|
||||
|
||||
void FocusModeSystemComponent::Deactivate()
|
||||
{
|
||||
AZ::Interface<FocusModeInterface>::Unregister(this);
|
||||
}
|
||||
|
||||
void FocusModeSystemComponent::Reflect([[maybe_unused]] AZ::ReflectContext* context)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ namespace AzToolsFramework
|
||||
AZ_COMPONENT(FocusModeSystemComponent, "{6CE522FE-2057-4794-BD05-61E04BD8EA30}");
|
||||
|
||||
FocusModeSystemComponent() = default;
|
||||
virtual ~FocusModeSystemComponent();
|
||||
virtual ~FocusModeSystemComponent() = default;
|
||||
|
||||
// AZ::Component overrides ...
|
||||
void Init() override;
|
||||
|
||||
@@ -14,15 +14,8 @@
|
||||
|
||||
namespace AzToolsFramework::Prefab
|
||||
{
|
||||
PrefabFocusHandler::~PrefabFocusHandler()
|
||||
PrefabFocusHandler::PrefabFocusHandler()
|
||||
{
|
||||
AZ::Interface<PrefabFocusInterface>::Unregister(this);
|
||||
}
|
||||
|
||||
void PrefabFocusHandler::Initialize()
|
||||
{
|
||||
m_focusModeInterface = AZ::Interface<FocusModeInterface>::Get();
|
||||
|
||||
m_instanceEntityMapperInterface = AZ::Interface<InstanceEntityMapperInterface>::Get();
|
||||
AZ_Assert(
|
||||
m_instanceEntityMapperInterface,
|
||||
@@ -30,21 +23,35 @@ namespace AzToolsFramework::Prefab
|
||||
"Instance Entity Mapper Interface could not be found. "
|
||||
"Check that it is being correctly initialized.");
|
||||
|
||||
m_prefabEditorEntityOwnershipInterface = AZ::Interface<PrefabEditorEntityOwnershipInterface>::Get();
|
||||
AZ_Assert(
|
||||
m_prefabEditorEntityOwnershipInterface,
|
||||
"Prefab - PrefabFocusHandler - "
|
||||
"Prefab Editor Entity Ownership Interface could not be found. "
|
||||
"Check that it is being correctly initialized.");
|
||||
|
||||
AZ::Interface<PrefabFocusInterface>::Register(this);
|
||||
}
|
||||
|
||||
PrefabFocusHandler::~PrefabFocusHandler()
|
||||
{
|
||||
AZ::Interface<PrefabFocusInterface>::Unregister(this);
|
||||
}
|
||||
|
||||
PrefabFocusOperationResult PrefabFocusHandler::FocusOnOwningPrefab(AZ::EntityId entityId)
|
||||
{
|
||||
InstanceOptionalReference focusedInstance = (entityId == AZ::EntityId())
|
||||
? m_prefabEditorEntityOwnershipInterface->GetRootPrefabInstance()
|
||||
: m_instanceEntityMapperInterface->FindOwningInstance(entityId);
|
||||
InstanceOptionalReference focusedInstance;
|
||||
|
||||
if (entityId == AZ::EntityId())
|
||||
{
|
||||
PrefabEditorEntityOwnershipInterface* prefabEditorEntityOwnershipInterface =
|
||||
AZ::Interface<PrefabEditorEntityOwnershipInterface>::Get();
|
||||
|
||||
if(!prefabEditorEntityOwnershipInterface)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Could not focus on root prefab instance - internal error "
|
||||
"(PrefabEditorEntityOwnershipInterface unavailable)."));
|
||||
}
|
||||
|
||||
focusedInstance = prefabEditorEntityOwnershipInterface->GetRootPrefabInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
focusedInstance = m_instanceEntityMapperInterface->FindOwningInstance(entityId);
|
||||
}
|
||||
|
||||
if (!focusedInstance.has_value())
|
||||
{
|
||||
@@ -54,9 +61,11 @@ namespace AzToolsFramework::Prefab
|
||||
|
||||
m_focusedInstance = focusedInstance;
|
||||
m_focusedTemplateId = focusedInstance->get().GetTemplateId();
|
||||
if (m_focusModeInterface)
|
||||
|
||||
FocusModeInterface* focusModeInterface = AZ::Interface<FocusModeInterface>::Get();
|
||||
if (focusModeInterface)
|
||||
{
|
||||
m_focusModeInterface->SetFocusRoot(focusedInstance->get().GetContainerEntityId());
|
||||
focusModeInterface->SetFocusRoot(focusedInstance->get().GetContainerEntityId());
|
||||
}
|
||||
|
||||
return AZ::Success();
|
||||
|
||||
@@ -14,12 +14,6 @@
|
||||
#include <AzToolsFramework/Prefab/PrefabFocusInterface.h>
|
||||
#include <AzToolsFramework/Prefab/Template/Template.h>
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
class FocusModeInterface;
|
||||
class PrefabEditorEntityOwnershipInterface;
|
||||
}
|
||||
|
||||
namespace AzToolsFramework::Prefab
|
||||
{
|
||||
class InstanceEntityMapperInterface;
|
||||
@@ -31,10 +25,9 @@ namespace AzToolsFramework::Prefab
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR(PrefabFocusHandler, AZ::SystemAllocator, 0);
|
||||
|
||||
PrefabFocusHandler();
|
||||
~PrefabFocusHandler();
|
||||
|
||||
void Initialize();
|
||||
|
||||
// PrefabFocusInterface override ...
|
||||
PrefabFocusOperationResult FocusOnOwningPrefab(AZ::EntityId entityId) override;
|
||||
TemplateId GetFocusedPrefabTemplateId() override;
|
||||
@@ -45,9 +38,7 @@ namespace AzToolsFramework::Prefab
|
||||
InstanceOptionalReference m_focusedInstance;
|
||||
TemplateId m_focusedTemplateId;
|
||||
|
||||
FocusModeInterface* m_focusModeInterface;
|
||||
InstanceEntityMapperInterface* m_instanceEntityMapperInterface;
|
||||
PrefabEditorEntityOwnershipInterface* m_prefabEditorEntityOwnershipInterface;
|
||||
};
|
||||
|
||||
} // namespace AzToolsFramework::Prefab
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <AzCore/std/string/string_view.h>
|
||||
|
||||
#include <AzToolsFramework/Prefab/Instance/Instance.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabFocusHandler.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabPublicInterface.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabSystemComponentInterface.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabUndoCache.h>
|
||||
@@ -189,6 +190,9 @@ namespace AzToolsFramework
|
||||
PrefabLoaderInterface* m_prefabLoaderInterface = nullptr;
|
||||
PrefabSystemComponentInterface* m_prefabSystemComponentInterface = nullptr;
|
||||
|
||||
// Handles the Prefab Focus API that determines what prefab is being edited.
|
||||
PrefabFocusHandler m_prefabFocusHandler;
|
||||
|
||||
// Caches entity states for undo/redo purposes
|
||||
PrefabUndoCache m_prefabUndoCache;
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace AzToolsFramework
|
||||
m_prefabLoader.RegisterPrefabLoaderInterface();
|
||||
m_instanceUpdateExecutor.RegisterInstanceUpdateExecutorInterface();
|
||||
m_instanceToTemplatePropagator.RegisterInstanceToTemplateInterface();
|
||||
m_prefabFocusHandler.Initialize();
|
||||
m_prefabPublicHandler.RegisterPrefabPublicHandlerInterface();
|
||||
m_prefabPublicRequestHandler.Connect();
|
||||
AZ::SystemTickBus::Handler::BusConnect();
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <AzToolsFramework/Prefab/Instance/InstanceToTemplatePropagator.h>
|
||||
#include <AzToolsFramework/Prefab/Instance/TemplateInstanceMapper.h>
|
||||
#include <AzToolsFramework/Prefab/Link/Link.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabFocusHandler.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabIdTypes.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabLoader.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabPublicHandler.h>
|
||||
@@ -379,9 +378,6 @@ namespace AzToolsFramework
|
||||
// Used for loading/saving Prefab Template files.
|
||||
PrefabLoader m_prefabLoader;
|
||||
|
||||
// Handles the Prefab Focus API that determines what prefab is being edited.
|
||||
PrefabFocusHandler m_prefabFocusHandler;
|
||||
|
||||
// Handles the public Prefab API used by UI and scripting.
|
||||
PrefabPublicHandler m_prefabPublicHandler;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user