Fixes for internal if-branch node parser bug (LYN-4347) and exposing properties for AZStd::tuple (LYN-3910)

monroegm-disable-blank-issue-2
chcurran 5 years ago
parent dd95d2b02e
commit a766e3af5c

@ -161,7 +161,56 @@ namespace AZ
return "A pair is an fixed size collection of two elements.";
}
};
template<typename T>
void GetTypeNamesFold(AZStd::vector<AZStd::string>& result, AZ::BehaviorContext& context)
{
result.push_back(OnDemandPrettyName<T>::Get(context));
};
template<typename... T>
void GetTypeNames(AZStd::vector<AZStd::string>& result, AZ::BehaviorContext& context)
{
(GetTypeNamesFold<T>(result, context), ...);
};
template<typename T>
void GetTypeNamesFold(AZStd::string& result, AZ::BehaviorContext& context)
{
if (!result.empty())
{
result += ", ";
}
result += OnDemandPrettyName<T>::Get(context);
};
template<typename... T>
void GetTypeNames(AZStd::string& result, AZ::BehaviorContext& context)
{
(GetTypeNamesFold<T>(result, context), ...);
};
template<typename... T>
struct OnDemandPrettyName<AZStd::tuple<T...>>
{
static AZStd::string Get(AZ::BehaviorContext& context)
{
AZStd::string typeNames;
GetTypeNames<T...>(typeNames, context);
return AZStd::string::format("Tuple<%s>", typeNames.c_str());
}
};
template<typename... T>
struct OnDemandToolTip<AZStd::tuple<T...>>
{
static AZStd::string Get(AZ::BehaviorContext&)
{
return "A tuple is an fixed size collection of any number of any type of element.";
}
};
template<class Key, class MappedType, class Hasher, class EqualKey, class Allocator>
struct OnDemandPrettyName< AZStd::unordered_map<Key, MappedType, Hasher, EqualKey, Allocator> >
{

@ -813,20 +813,27 @@ namespace AZ
{
using ContainerType = AZStd::tuple<T...>;
template<size_t Index>
static void ReflectUnpackMethodFold(BehaviorContext::ClassBuilder<ContainerType>& builder)
template<typename t_Arg, size_t Index>
static void ReflectUnpackMethodFold(BehaviorContext::ClassBuilder<ContainerType>& builder, const AZStd::vector<AZStd::string>& typeNames, [[maybe_unused]] size_t inputIndex)
{
const AZStd::string methodName = AZStd::string::format("Get%zu", Index);
builder->Method(methodName.data(), [](ContainerType& value) { return AZStd::get<Index>(value); })
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
builder->Method(methodName.data(), [](ContainerType& thisPointer) { return AZStd::get<Index>(thisPointer); })
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::List)
->Attribute(AZ::ScriptCanvasAttributes::TupleGetFunctionIndex, Index)
;
builder->Property
( AZStd::string::format("element_%zu_%s", Index, typeNames[Index].c_str()).c_str()
, [](ContainerType& thisPointer) { return AZStd::get<Index>(thisPointer); }
, [](ContainerType& thisPointer, const t_Arg& element) { AZStd::get<Index>(thisPointer) = element; });
}
template<size_t... Indices>
template<typename... t_Args, size_t... Indices>
static void ReflectUnpackMethods(BehaviorContext::ClassBuilder<ContainerType>& builder, AZStd::index_sequence<Indices...>)
{
(ReflectUnpackMethodFold<Indices>(builder), ...);
AZStd::vector<AZStd::string> typeNames;
ScriptCanvasOnDemandReflection::GetTypeNames<T...>(typeNames, *builder.m_context);
(ReflectUnpackMethodFold<t_Args, Indices>(builder, typeNames, Indices), ...);
}
static void Reflect(ReflectContext* context)
@ -851,9 +858,10 @@ namespace AZ
->Attribute(AZ::ScriptCanvasAttributes::TupleConstructorFunction, constructorHolder)
;
ReflectUnpackMethods(builder, AZStd::make_index_sequence<sizeof...(T)>{});
ReflectUnpackMethods<T...>(builder, AZStd::make_index_sequence<sizeof...(T)>{});
builder->Method("GetSize", []() { return AZStd::tuple_size<ContainerType>::value; })
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::List)
;
}
}

@ -3356,22 +3356,26 @@ namespace ScriptCanvas
if (executionIf->GetId().m_node->IsIfBranchPrefacedWithBooleanExpression())
{
auto removeChildOutcome = RemoveChild(executionIf->ModParent(), executionIf);
if (!removeChildOutcome.IsSuccess())
{
AddError(executionIf->GetNodeId(), executionIf, ScriptCanvas::ParseErrors::FailedToRemoveChild);
}
ExecutionTreePtr booleanExpression;
if (!IsErrorFree())
{
return;
}
auto removeChildOutcome = RemoveChild(executionIf->ModParent(), executionIf);
if (!removeChildOutcome.IsSuccess())
{
AddError(executionIf->GetNodeId(), executionIf, ScriptCanvas::ParseErrors::FailedToRemoveChild);
}
if (!IsErrorFree())
{
return;
}
const auto indexAndChild = removeChildOutcome.TakeValue();
const auto indexAndChild = removeChildOutcome.TakeValue();
ExecutionTreePtr booleanExpression = CreateChild(executionIf->ModParent(), executionIf->GetId().m_node, executionIf->GetId().m_slot);
executionIf->ModParent()->InsertChild(indexAndChild.first, { indexAndChild.second.m_slot, indexAndChild.second.m_output, booleanExpression });
executionIf->SetParent(booleanExpression);
booleanExpression = CreateChild(executionIf->ModParent(), executionIf->GetId().m_node, executionIf->GetId().m_slot);
executionIf->ModParent()->InsertChild(indexAndChild.first, { indexAndChild.second.m_slot, indexAndChild.second.m_output, booleanExpression });
executionIf->SetParent(booleanExpression);
}
// make a condition here
auto symbol = CheckLogicalExpressionSymbol(booleanExpression);
@ -3402,7 +3406,7 @@ namespace ScriptCanvas
return;
}
const auto indexAndChild2 = removeChildOutcome.TakeValue();
const auto indexAndChild2 = removeChildOutcome2.TakeValue();
// parse if statement internal function
ExecutionTreePtr internalFunction = CreateChild(booleanExpression->ModParent(), booleanExpression->GetId().m_node, booleanExpression->GetId().m_slot);
@ -4782,7 +4786,7 @@ namespace ScriptCanvas
{
PropertyExtractionPtr extraction = AZStd::make_shared<PropertyExtraction>();
extraction->m_slot = slot;
extraction->m_name = propertyField.first;
extraction->m_name = AZ::ReplaceCppArtifacts(propertyField.first);
execution->AddPropertyExtractionSource(slot, extraction);
}
else

@ -90,6 +90,11 @@ public:
}
};
TEST_F(ScriptCanvasTestFixture, ParseFunctionIfBranchWithConnectedInput)
{
RunUnitTestGraph("LY_SC_UnitTest_ParseFunctionIfBranchWithConnectedInput");
}
TEST_F(ScriptCanvasTestFixture, UseRawBehaviorProperties)
{
RunUnitTestGraph("LY_SC_UnitTest_UseRawBehaviorProperties");

Loading…
Cancel
Save