8571e71d93
Signed-off-by: chcurran <82187351+carlitosan@users.noreply.github.com>
131 lines
4.3 KiB
C++
131 lines
4.3 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
|
|
*
|
|
*/
|
|
|
|
#include "VersionedProperty.h"
|
|
|
|
#include <AzCore/Script/ScriptContext.h>
|
|
#include <AzCore/RTTI/BehaviorContext.h>
|
|
#include <AzCore/Serialization/EditContext.h>
|
|
#include <AzCore/Script/ScriptProperty.h>
|
|
|
|
namespace ScriptEventData
|
|
{
|
|
namespace Internal
|
|
{
|
|
void VersionedPropertyConstructor(VersionedProperty* self, AZ::ScriptDataContext& dc)
|
|
{
|
|
if (dc.GetNumArguments() == 0)
|
|
{
|
|
AZ_Warning("VersionedProperty", false, "Not enough arguments specified to construct VersionedProperty");
|
|
return;
|
|
}
|
|
|
|
if (dc.IsString(0))
|
|
{
|
|
AZStd::string data;
|
|
if (dc.ReadArg(0, data))
|
|
{
|
|
*self = VersionedProperty();
|
|
self->Set(data.c_str());
|
|
}
|
|
}
|
|
else
|
|
if (dc.IsRegisteredClass(0))
|
|
{
|
|
AZStd::any data;
|
|
if (dc.ReadArg(0, data))
|
|
{
|
|
*self = VersionedProperty();
|
|
self->Set(data);
|
|
}
|
|
}
|
|
else
|
|
if (dc.IsNumber(0))
|
|
{
|
|
double value;
|
|
if (dc.ReadArg(0, value))
|
|
{
|
|
*self = VersionedProperty();
|
|
self->Set(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Set(VersionedProperty* self, AZ::ScriptDataContext& dc)
|
|
{
|
|
self->Set(dc);
|
|
}
|
|
|
|
void Get(VersionedProperty* self, AZ::ScriptDataContext& dc)
|
|
{
|
|
self->Get(dc);
|
|
}
|
|
}
|
|
|
|
VersionedProperty::VersionedProperty(AZ::ScriptDataContext& dc)
|
|
{
|
|
Internal::VersionedPropertyConstructor(this, dc);
|
|
}
|
|
|
|
void VersionedProperty::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
VoidType::Reflect(context);
|
|
|
|
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
|
{
|
|
serializeContext->Class<VersionedProperty>()
|
|
->Version(4)
|
|
->Field("m_id", &VersionedProperty::m_id)
|
|
->Field("m_label", &VersionedProperty::m_label)
|
|
->Field("m_version", &VersionedProperty::m_version)
|
|
->Field("m_versions", &VersionedProperty::m_versions)
|
|
->Field("m_data", &VersionedProperty::m_data)
|
|
;
|
|
|
|
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
|
{
|
|
editContext->Class<VersionedProperty>("VersionedProperty", "")
|
|
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
|
->Attribute(AZ::Edit::Attributes::ChildNameLabelOverride, &VersionedProperty::GetLabel)
|
|
//->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
|
->DataElement(0, &VersionedProperty::m_data, "", "")
|
|
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
|
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
|
;
|
|
}
|
|
}
|
|
|
|
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
|
{
|
|
behaviorContext->Class<ScriptEventData::VersionedProperty>()
|
|
->Constructor<AZ::ScriptDataContext&>()
|
|
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
|
|
->Method("Set", &Internal::Set)
|
|
->Method("Get", &Internal::Get)
|
|
;
|
|
}
|
|
}
|
|
|
|
void VersionedProperty::PreSave()
|
|
{
|
|
NewVersion();
|
|
}
|
|
|
|
void VersionedProperty::Set(AZ::ScriptDataContext& dc)
|
|
{
|
|
VersionedProperty& newVersion = NewVersion();
|
|
Internal::VersionedPropertyConstructor(&newVersion, dc);
|
|
}
|
|
|
|
void VersionedProperty::Get(AZ::ScriptDataContext& dc)
|
|
{
|
|
AZ::ScriptValue<AZStd::any>::StackPush(dc.GetScriptContext()->NativeContext(), m_data);
|
|
dc.PushResult(m_data);
|
|
}
|
|
}
|