e16781e6b6
* Introduce read-only entity interface, handler and unit tests. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Switch from a push paradigm to a pull paradigm - handlers get to implement logic to determine if an entity should be read-only. This allows multiple systems to weigh into whether an entity is read-only. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Fixed to missing call in test Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> * Renaming ReadOnlyEntityQueryNotificationBus to ReadOnlyEntityQueryRequestBus for consistency with engine patterns. Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
79 lines
2.4 KiB
C++
79 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AzCore/Component/TransformBus.h>
|
|
#include <AzCore/UnitTest/TestTypes.h>
|
|
|
|
#include <AzTest/AzTest.h>
|
|
|
|
#include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
|
|
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityBus.h>
|
|
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
|
|
|
|
namespace AzToolsFramework
|
|
{
|
|
class ReadOnlyEntityFixture
|
|
: public UnitTest::ToolsApplicationFixture
|
|
{
|
|
protected:
|
|
void SetUpEditorFixtureImpl() override;
|
|
void TearDownEditorFixtureImpl() override;
|
|
|
|
void GenerateTestHierarchy();
|
|
AZ::EntityId CreateEditorEntity(const char* name, AZ::EntityId parentId);
|
|
|
|
AZStd::unordered_map<AZStd::string, AZ::EntityId> m_entityMap;
|
|
|
|
ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr;
|
|
|
|
public:
|
|
inline static const char* RootEntityName = "Root";
|
|
inline static const char* ChildEntityName = "Child";
|
|
inline static const char* GrandChild1EntityName = "GrandChild1";
|
|
inline static const char* GrandChild2EntityName = "GrandChild2";
|
|
};
|
|
|
|
class ReadOnlyHandlerAlwaysTrue
|
|
: public ReadOnlyEntityQueryRequestBus::Handler
|
|
{
|
|
public:
|
|
ReadOnlyHandlerAlwaysTrue();
|
|
~ReadOnlyHandlerAlwaysTrue();
|
|
|
|
// ReadOnlyEntityQueryNotificationBus overrides ...
|
|
void IsReadOnly(const AZ::EntityId& entityId, bool& isReadOnly) override;
|
|
};
|
|
|
|
class ReadOnlyHandlerAlwaysFalse
|
|
: public ReadOnlyEntityQueryRequestBus::Handler
|
|
{
|
|
public:
|
|
ReadOnlyHandlerAlwaysFalse();
|
|
~ReadOnlyHandlerAlwaysFalse();
|
|
|
|
// ReadOnlyEntityQueryNotificationBus overrides ...
|
|
void IsReadOnly([[maybe_unused]] const AZ::EntityId& entityId, [[maybe_unused]] bool& isReadOnly) override {}
|
|
};
|
|
|
|
class ReadOnlyHandlerEntityId
|
|
: public ReadOnlyEntityQueryRequestBus::Handler
|
|
{
|
|
public:
|
|
ReadOnlyHandlerEntityId(AZ::EntityId entityId);
|
|
~ReadOnlyHandlerEntityId();
|
|
|
|
// ReadOnlyEntityQueryNotificationBus overrides ...
|
|
void IsReadOnly(const AZ::EntityId& entityId, bool& isReadOnly) override;
|
|
|
|
private:
|
|
AZ::EntityId m_entityId;
|
|
};
|
|
}
|