Files
o3de/Gems/ScriptCanvas/Code/Include/ScriptCanvas/AutoGen/ScriptCanvasGrammar_Source.jinja
T
2021-04-07 14:03:29 -07:00

277 lines
13 KiB
Django/Jinja

{#
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
its licensors.
For complete copyright and license terms please see the LICENSE at the root of this
distribution (the "License"). All use of this software is governed by the License,
or, if provided, by the license below or the license accompanying this file. Do not
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#}
{% 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') %}
void {{ Class.attrib['QualifiedName'] }}::ConfigureSlots()
{
{% if Class.attrib['Base'] is defined %}
{{ Class.attrib['Base'] }}::ConfigureSlots();
{% endif %}
{% 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 %}true{% else %}false{% endif %};
}
{% set deprecationUuid = Class.attrib['DeprecationUUID'] %}
{% if deprecationUuid is defined %}
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 %}
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 %}
{% if Class.attrib['Base'] is defined %}
static_assert((std::is_base_of<ScriptCanvas::Node, {{ Class.attrib['Base'] }}>::value), "Script Canvas nodes require the first base class to be derived from ScriptCanvas::Node");
{% endif %}
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<{{ Class.attrib['QualifiedName'] }}{% if Class.attrib['Base'] is defined %}, {{ Class.attrib['Base'] }}{% endif %}>()
{% if Class.attrib['EventHandler'] is defined %}
->EventHandler<{{ Class.attrib['EventHandler'] }}>()
{% 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 %}
->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 %}
{% endfor %}
{% endfor %}