Files
o3de/Gems/GraphCanvas/Code/StaticLib/GraphCanvas/Components/PersistentIdBus.h
T
Steve Pham 38261d0800 Shorten copyright headers by splitting into 2 lines (#2213)
* Updated all copyright headers to split the longer original copyright line into 2 shorter lines

Signed-off-by: Steve Pham <spham@amazon.com>
2021-07-16 15:25:48 -07:00

87 lines
2.9 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/EBus/EBus.h>
#include <AzCore/std/containers/unordered_map.h>
#include <GraphCanvas/Editor/EditorTypes.h>
#include <GraphCanvas/Types/SceneMemberComponentSaveData.h>
namespace GraphCanvas
{
class PersistentIdRequests : public AZ::EBusTraits
{
public:
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = PersistentGraphMemberId;
virtual AZ::EntityId MapToEntityId() const = 0;
};
using PersistentIdRequestBus = AZ::EBus<PersistentIdRequests>;
class PersistentIdNotifications : public AZ::EBusTraits
{
public:
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = EditorId;
virtual void OnPersistentIdsRemapped(const AZStd::unordered_map< PersistentGraphMemberId, PersistentGraphMemberId >& persistentIdRemapping) = 0;
};
using PersistentIdNotificationBus = AZ::EBus<PersistentIdNotifications>;
class PersistentMemberRequests
: public AZ::EBusTraits
{
public:
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = AZ::EntityId;
//! If the persistent graph member was remapped(such as during a copy). This will return the original
//! value.
virtual PersistentGraphMemberId GetPreviousGraphMemberId() const = 0;
virtual PersistentGraphMemberId GetPersistentGraphMemberId() const = 0;
};
using PersistentMemberRequestBus = AZ::EBus<PersistentMemberRequests>;
class PersistentIdComponentSaveData
: public SceneMemberComponentSaveData<PersistentIdComponentSaveData>
{
friend class PersistentIdComponent;
public:
AZ_RTTI(PersistentIdComponentSaveData, "{B1F49A35-8408-40DA-B79E-F1E3B64322CE}", SceneMemberComponentSaveData<PersistentIdComponentSaveData>);
AZ_CLASS_ALLOCATOR(PersistentIdComponentSaveData, AZ::SystemAllocator, 0);
PersistentIdComponentSaveData()
: m_persistentId(PersistentGraphMemberId::CreateRandom())
{
}
bool RequiresSave() const override
{
return true;
}
PersistentGraphMemberId m_persistentId;
private:
void RemapId()
{
m_persistentId = PersistentGraphMemberId::CreateRandom();
SignalDirty();
}
};
}