Files
o3de/Gems/ScriptCanvas/Code/Include/ScriptCanvas/AutoGen/ScriptCanvasGrammar_Source.jinja
T
2021-08-23 16:02:58 -07:00

295 lines
14 KiB
Django/Jinja

{#
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
#}
{% import 'ScriptCanvas_Macros.jinja' as macros %}
{% macro add_attribute(attribute, tags) %}
{% set value = tags[attribute] %}
{% if value is defined %}
->Attribute(AZ::Edit::Attributes::{{ attribute }}, {{ value }})
{% endif %}
{% endmacro %}
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/RTTI/TypeInfo.h>
#include <ScriptCanvas/Core/Slot.h>
#include <ScriptCanvas/Core/Datum.h>
#include <ScriptCanvas/Core/Attributes.h>
#include <ScriptCanvas/Core/Contracts.h>
#include <ScriptCanvas/Core/DatumBus.h>
#include <ScriptCanvas/Utils/VersionConverters.h>
{% for xml in dataFiles %}
#include "{{ xml.attrib['Include'] }}"
{% for Class in xml.iter('Class') %}
{% set baseClass = Class.attrib['Base'].split(';')[0] if Class.attrib['Base'] is string else "ScriptCanvas::Node" %}
{% set attribute_Namespace = undefined %}
{%- if Class.attrib['Namespace'] is defined %}
{% if Class.attrib['Namespace'] != "None" %}
{% set attribute_Namespace = Class.attrib['Namespace'] %}
{% endif %}
{% endif %}
{% if attribute_Namespace is defined %}
namespace {{attribute_Namespace}}
{
{% endif %}
void {{ Class.attrib['QualifiedName'] }}::ConfigureSlots()
{
{{ baseClass }}::ConfigureSlots();
{% for Property in Class.iter('Property') %}
{% if Property.attrib['IsInput'] | booleanTrue %}
// {{ Property.attrib['Name'] }}
{
{% if Property.attrib['Overloaded'] is defined %}
ScriptCanvas::DynamicDataSlotConfiguration slotConfiguration;
slotConfiguration.m_dynamicDataType = ScriptCanvas::DynamicDataType::Any;
{% else %}
ScriptCanvas::DataSlotConfiguration slotConfiguration;
slotConfiguration.SetAZType<{{ Property.attrib['Type'] }}>();
{% if Property.attrib['DefaultValue'] is defined %}
slotConfiguration.SetDefaultValue({{ Property.attrib['Type'] }}({{ Property.attrib['DefaultValue'] }}));
{% endif %}
{% endif %}
slotConfiguration.m_name = "{{ Property.attrib['Name'] }}";
slotConfiguration.m_toolTip = "{{ Property.attrib['Description'] }}";
{% if Property.attrib['DisplayGroup'] is defined %}
slotConfiguration.m_displayGroup = "{{ Property.attrib['DisplayGroup'] }}";
{% endif %}
{% set slotContracts = Property.attrib['Contracts'].split(';') if Property.attrib['Contracts'] is string else Property.attrib['Contracts']|default([]) %}
{% for slotContract in slotContracts %}
slotConfiguration.m_contractDescs.emplace_back([]() { return aznew {{ slotContract|e }}; });
{% endfor %}
slotConfiguration.SetConnectionType(ScriptCanvas::ConnectionType::Input);
AddSlot(slotConfiguration);
}
{% endif %}
{% if Property.attrib['IsOutput'] | booleanTrue %}
// {{ Property.attrib['Name'] }}
{
ScriptCanvas::DataSlotConfiguration slotConfiguration;
slotConfiguration.SetAZType<{{ Property.attrib['Type'] }}>();
slotConfiguration.m_name = "{{ Property.attrib['Name'] }}";
slotConfiguration.m_toolTip = "{{ Property.attrib['Description'] }}";
slotConfiguration.SetConnectionType(ScriptCanvas::ConnectionType::Output);
{% if Property.attrib['DisplayGroup'] is defined %}
slotConfiguration.m_displayGroup = "{{ Property.attrib['DisplayGroup'] }}";
{% endif %}
{% set slotContracts = Property.attrib['Contracts'].split(';') if Property.attrib['Contracts'] is string else Property.attrib['Contracts']|default([]) %}
{% for slotContract in slotContracts %}
slotConfiguration.m_contractDescs.emplace_back([]() { return aznew {{ slotContract|e }}; });
{% endfor %}
AddSlot(slotConfiguration);
}
{% endif %}
{% endfor %}
{% for Property in Class.iter('In') %}
// {{ Property.attrib['Name'] }}
{
ScriptCanvas::ExecutionSlotConfiguration slotConfiguration;
slotConfiguration.m_name = "{{ Property.attrib['Name'] }}";
slotConfiguration.m_toolTip = "{{ Property.attrib['Description'] }}";
{% if Property.attrib['DisplayGroup'] is defined %}
slotConfiguration.m_displayGroup = "{{ Property.attrib['DisplayGroup'] }}";
{% endif %}
{% set slotContracts = Property.attrib['Contracts'].split(';') if Property.attrib['Contracts'] is string else Property.attrib['Contracts']|default([]) %}
{% for slotContract in slotContracts %}
slotConfiguration.m_contractDescs.emplace_back([]() { return aznew {{ slotContract|e }}; });
{% endfor %}
slotConfiguration.SetConnectionType(ScriptCanvas::ConnectionType::Input);
AddSlot(slotConfiguration);
}
{% endfor %}
{% for Property in Class.iter('Out') %}
// {{ Property.attrib['Name'] }}
{
ScriptCanvas::ExecutionSlotConfiguration slotConfiguration;
slotConfiguration.m_name = "{{ Property.attrib['Name'] }}";
slotConfiguration.m_toolTip = "{{ Property.attrib['Description'] }}";
{% if Property.attrib['DisplayGroup'] is defined %}
slotConfiguration.m_displayGroup = "{{ Property.attrib['DisplayGroup'] }}";
{% endif %}
{% set slotContracts = Property.attrib['Contracts'].split(';') if Property.attrib['Contracts'] is string else Property.attrib['Contracts']|default([]) %}
{% for slotContract in slotContracts %}
slotConfiguration.m_contractDescs.emplace_back([]() { return aznew {{ slotContract|e }}; });
{% endfor %}
slotConfiguration.SetConnectionType(ScriptCanvas::ConnectionType::Output);
AddSlot(slotConfiguration);
}
{% endfor %}
{% for Property in Class.iter('OutLatent') %}
// {{ Property.attrib['Name'] }}
{
ScriptCanvas::ExecutionSlotConfiguration slotConfiguration;
slotConfiguration.m_name = "{{ Property.attrib['Name'] }}";
slotConfiguration.m_toolTip = "{{ Property.attrib['Description'] }}";
{% if Property.attrib['DisplayGroup'] is defined %}
slotConfiguration.m_displayGroup = "{{ Property.attrib['DisplayGroup'] }}";
{% endif %}
{% set slotContracts = Property.attrib['Contracts'].split(';') if Property.attrib['Contracts'] is string else Property.attrib['Contracts']|default([]) %}
{% for slotContract in slotContracts %}
slotConfiguration.m_contractDescs.emplace_back([]() { return aznew {{ slotContract|e }}; });
{% endfor %}
slotConfiguration.SetConnectionType(ScriptCanvas::ConnectionType::Output);
slotConfiguration.m_isLatent = true;
AddSlot(slotConfiguration);
}
{% endfor %}
{% for Property in Class.iter('DynamicDataSlot') %}
// {{ Property.attrib['Name'] }}
{
ScriptCanvas::DynamicDataSlotConfiguration slotConfiguration;
slotConfiguration.m_name = "{{ Property.attrib['Name'] }}";
slotConfiguration.m_toolTip = "{{ Property.attrib['Description'] }}";
{% if Property.attrib['DisplayGroup'] is defined %}
slotConfiguration.m_displayGroup = "{{ Property.attrib['DisplayGroup'] }}";
{% endif %}
slotConfiguration.SetConnectionType({{ Property.attrib['ConnectionType'] }});
slotConfiguration.m_dynamicDataType = {{ Property.attrib['DynamicType'] }};
{% if Property.attrib['DynamicGroup'] is defined %}
slotConfiguration.m_dynamicGroup = AZ::Crc32("{{ Property.attrib['DynamicGroup'] }}");
{% endif %}
{% if Property.attrib['RestrictedTypes'] is defined %}
{% set typeContractList = Property.attrib['RestrictedTypes'].split(';') | join("(), ") %}
// Restricted Type Contract
slotConfiguration.m_contractDescs = AZStd::vector<ScriptCanvas::ContractDescriptor>{ { []() { return aznew ScriptCanvas::RestrictedTypeContract({ {{ typeContractList }}() }); } } };
{% endif %}
{% set slotContracts = Property.attrib['Contracts'].split(';') if Property.attrib['Contracts'] is string else Property.attrib['Contracts']|default([]) %}
{% for slotContract in slotContracts %}
slotConfiguration.m_contractDescs.emplace_back([]() { return aznew {{ slotContract|e }}; });
{% endfor %}
AddSlot(slotConfiguration);
}
{% endfor %}
}
bool {{ Class.attrib['QualifiedName'] }}::RequiresDynamicSlotOrdering() const
{
return {% if Class.attrib['DynamicSlotOrdering'] is defined and Class.attrib['DynamicSlotOrdering'] == "true" %}true{% else %}false{% endif %};
}
bool {{ Class.attrib['QualifiedName'] }}::IsDeprecated() const
{
return {% if Class.attrib['Deprecated'] is defined or Class.attrib['DeprecationUUID'] is defined %}true{% else %}false{% endif %};
}
{% set deprecationUuid = Class.attrib['DeprecationUUID'] %}
{% if deprecationUuid is defined %}
ScriptCanvas::NodeConfiguration {{ Class.attrib['QualifiedName'] }}::GetReplacementNodeConfiguration() const
{
ScriptCanvas::NodeConfiguration nodeConfig{};
nodeConfig.m_type = AZ::Uuid("{{ deprecationUuid }}");
{% if Class.attrib['ReplacementMethodName'] is defined %}
nodeConfig.m_methodName = "{{Class.attrib['ReplacementMethodName']}}";
{% endif %}
{% if Class.attrib['ReplacementClassName'] is defined %}
nodeConfig.m_className = "{{Class.attrib['ReplacementClassName']}}";
{% endif %}
return nodeConfig;
}
{% endif %}
void {{ Class.attrib['QualifiedName'] }}::Reflect(AZ::ReflectContext* context)
{
{% if Class.attrib['DependentReflections'] is defined %}
{% for dependentClass in Class.attrib['DependentReflections'].split(';') %}
{{ dependentClass }}::Reflect(context);
{% endfor %}
{% endif %}
static_assert((std::is_base_of<ScriptCanvas::Node, {{ baseClass }}>::value), "Script Canvas nodes require the first base class to be derived from ScriptCanvas::Node");
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<{{ Class.attrib['QualifiedName'] }}, {{ baseClass }}>()
{% if Class.attrib['EventHandler'] is defined %}
#if defined(OBJECT_STREAM_EDITOR_ASSET_LOADING_SUPPORT_ENABLED)////
->EventHandler<{{ Class.attrib['EventHandler'] }}>()
#endif//defined(OBJECT_STREAM_EDITOR_ASSET_LOADING_SUPPORT_ENABLED)
{% endif %}
{% if Class.attrib['Version'] is defined %}
->Version({{ Class.attrib['Version'] }}{% if Class.attrib['VersionConverter'] is defined %}, &{{ Class.attrib['VersionConverter'] }}{% endif %})
{% endif %}
{% for Property in Class.iter('SerializedProperty') %}
->Field("{{ Property.attrib['Name'] }}", &{{ Class.attrib['Name'] }}::{{ Property.attrib['Name'] | replace(' ','') }})
{% endfor %}
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<{{ Class.attrib['QualifiedName'] }}>("{{ Class.attrib['PreferredClassName'] }}", "{{ Class.attrib['Description'] }}")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
{% if Class.attrib['Category'] is defined %}
->Attribute(AZ::Edit::Attributes::Category, "{{ Class.attrib['Category'] }}")
{% endif %}
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
{% if Class.attrib['Icon'] is defined %}
->Attribute(AZ::Edit::Attributes::Icon, "{{ Class.attrib['Icon'] }}")
{% endif %}
{% if Class.attrib['Deprecated'] is defined or Class.attrib['DeprecationUUID'] is defined %}
->Attribute(ScriptCanvas::Attributes::Node::TitlePaletteOverride, "DeprecatedNodeTitlePalette")
->Attribute(AZ::Script::Attributes::Deprecated, true)
{% else %}
{% if Class.attrib['EditAttributes'] is defined %}
{% for editAttributePair in Class.attrib['EditAttributes'].split(';') %}
{% set editAttributeKey, editAttributeValue = editAttributePair.split('@') %}
{% if editAttributeKey == "AZ::Script::Attributes::ExcludeFrom" %}
->Attribute({{ editAttributeKey }}, {{ editAttributeValue }})
{% else %}
->Attribute({{ editAttributeKey }}, "{{ editAttributeValue }}")
{% endif %}
{% endfor %}
{% endif %}
{% for Property in Class.iter('EditProperty') %}
{% if Property.attrib['SerializeProperty'] is defined %}
->DataElement({{ Property.attrib['UiHandler'] }}, &{{ Class.attrib['Name'] }}::{{ Property.attrib['SerializeProperty'] }}, "{{ Property.attrib['SerializeProperty'] }}", "")
{% else %}
->DataElement({{ Property.attrib['UiHandler'] }}, &{{ Class.attrib['Name'] }}::{{ Property.attrib['FieldName'] }}, "{{ Property.attrib['Name'] | replace(' ','') }}", {% if Property.attrib['Description'] is defined %}"{{ Property.attrib['Description'] }}" {% else %}""{% endif %})
{% endif %}
{% for EditAttribute in Property.iter('EditAttribute') %}
->Attribute({{ EditAttribute.attrib['Key'] }}, {{ EditAttribute.attrib['Value'] }})
{% endfor %}
{% endfor %}
{% endif %}
;
}
}
}
{# Property Getters #}
{% for Property in Class.iter('Property') %}
{{ Property.attrib['Type'] }} {{ Class.attrib['Name'] }}Property::Get{{ Property.attrib['Name'] | replace(' ','') }}(ScriptCanvas::Node* owner)
{
ScriptCanvas::SlotId slotId = Get{{ Property.attrib['Name'] | replace(' ','') }}SlotId(owner);
const ScriptCanvas::Datum* datum = owner->FindDatum(slotId);
if (!datum)
{
AZ_Error("Script Canvas", false, "Cannot find generated code gen slot with name {{ Property.attrib['Name'] | replace(' ','') }}. Has the ScriptCanvas_Property::Name changed without writing a version converter");
}
const {{ Property.attrib['Type'] }}* datumValue = datum ? datum->GetAs<{{ Property.attrib['Type'] }}>() : nullptr;
return datumValue ? *datumValue : {{ Property.attrib['Type'] }}();
}
{% endfor %}
{% if attribute_Namespace is defined %}
}
{% endif %}
{% endfor %}
{% endfor %}