2021-03-16 00:47:44 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
2021-03-16 00:22:37 -04:00
# include "MetasoundNodeRegistrationMacro.h"
2021-03-30 15:49:01 -04:00
# include "MetasoundStandardNodesCategories.h"
2021-04-01 17:28:48 -04:00
# include "MetasoundFacade.h"
2022-02-08 12:12:15 -05:00
# include "MetasoundSourceInterface.h"
2021-04-01 17:28:48 -04:00
# include "MetasoundStandardNodesNames.h"
# include "MetasoundTrigger.h"
# include "MetasoundPrimitives.h"
2021-03-16 00:22:37 -04:00
2021-04-07 02:57:54 -04:00
# define LOCTEXT_NAMESPACE "MetasoundStandardNodes_DebugLogNode"
2021-03-16 00:22:37 -04:00
namespace Metasound
{
2021-04-01 17:28:48 -04:00
namespace MetasoundPrintLogNodePrivate
2021-03-16 00:22:37 -04:00
{
2021-04-01 17:28:48 -04:00
//Creates Metadata for the Print Log Node
2021-03-16 00:22:37 -04:00
FNodeClassMetadata CreateNodeClassMetadata ( const FName & InDataTypeName , const FName & InOperatorName , const FText & InDisplayName , const FText & InDescription , const FVertexInterface & InDefaultInterface )
{
FNodeClassMetadata Metadata
{
2021-08-09 15:08:37 -04:00
FNodeClassName { " Print Log " , InOperatorName , InDataTypeName } ,
2021-03-16 00:22:37 -04:00
1 , // Major Version
0 , // Minor Version
InDisplayName ,
InDescription ,
PluginAuthor ,
PluginNodeMissingPrompt ,
InDefaultInterface ,
2021-08-09 15:08:37 -04:00
{ NodeCategories : : Debug } ,
{ } ,
FNodeDisplayStyle ( )
2021-03-16 00:22:37 -04:00
} ;
return Metadata ;
}
}
2021-04-01 17:28:48 -04:00
//Getters for the name of each parameter used in Print Log
namespace PrintLogVertexNames
2021-03-16 00:22:37 -04:00
{
2021-09-13 14:13:39 -04:00
const FVertexName & GetInputTriggerName ( )
2021-03-16 00:22:37 -04:00
{
2021-09-13 14:13:39 -04:00
static const FVertexName Name = TEXT ( " Trigger " ) ;
2021-03-16 00:22:37 -04:00
return Name ;
}
2021-09-13 14:13:39 -04:00
const FVertexName & GetLabelPrintLogName ( )
2021-03-16 00:22:37 -04:00
{
2021-09-13 14:13:39 -04:00
static const FVertexName Name = TEXT ( " Label " ) ;
2021-03-16 00:22:37 -04:00
return Name ;
}
2021-09-13 14:13:39 -04:00
const FVertexName & GetToLogPrintLogName ( )
2021-03-16 00:22:37 -04:00
{
2021-09-13 14:13:39 -04:00
static const FVertexName Name = TEXT ( " Value To Log " ) ;
2021-03-16 00:22:37 -04:00
return Name ;
}
2021-09-13 14:13:39 -04:00
const FVertexName & GetOutputPrintLogName ( )
2021-03-16 00:22:37 -04:00
{
2021-09-13 14:13:39 -04:00
static const FVertexName Name = TEXT ( " Was Successful " ) ;
2021-03-16 00:22:37 -04:00
return Name ;
}
}
2021-04-01 17:28:48 -04:00
template < typename PrintLogType >
class TPrintLogOperator : public TExecutableOperator < TPrintLogOperator < PrintLogType > >
{
public :
using FArrayDataReadReference = TDataReadReference < PrintLogType > ;
2021-03-16 00:22:37 -04:00
2021-04-01 17:28:48 -04:00
static const FVertexInterface & GetDefaultInterface ( )
{
static const FVertexInterface DefaultInterface (
FInputVertexInterface (
2021-03-16 00:22:37 -04:00
2022-02-10 18:36:47 -05:00
TInputDataVertexModel < FTrigger > ( PrintLogVertexNames : : GetInputTriggerName ( ) , METASOUND_LOCTEXT ( " PrintLogTrigger " , " Trigger to write the set value to the log. " ) ) ,
TInputDataVertexModel < FString > ( PrintLogVertexNames : : GetLabelPrintLogName ( ) , METASOUND_LOCTEXT ( " PrintLogLabel " , " The label to attach to the value that will be logged " ) ) ,
TInputDataVertexModel < PrintLogType > ( PrintLogVertexNames : : GetToLogPrintLogName ( ) , METASOUND_LOCTEXT ( " PrintLogValueToLog " , " The value to record to the log when triggered " ) )
2021-04-01 17:28:48 -04:00
) ,
FOutputVertexInterface (
)
) ;
return DefaultInterface ;
}
static const FNodeClassMetadata & GetNodeInfo ( )
{
auto CreateNodeClassMetadata = [ ] ( ) - > FNodeClassMetadata
{
FName DataTypeName = GetMetasoundDataTypeName < PrintLogType > ( ) ;
FName OperatorName = TEXT ( " Print Log " ) ;
2022-02-10 18:36:47 -05:00
FText NodeDisplayName = METASOUND_LOCTEXT_FORMAT ( " PrintLogDisplayNamePattern " , " Print Log ({0}) " , GetMetasoundDataTypeDisplayText < PrintLogType > ( ) ) ;
const FText NodeDescription = METASOUND_LOCTEXT ( " PrintLogOpDescription " , " Used to record values to the log, on trigger " ) ;
2021-04-01 17:28:48 -04:00
FVertexInterface NodeInterface = GetDefaultInterface ( ) ;
return MetasoundPrintLogNodePrivate : : CreateNodeClassMetadata ( DataTypeName , OperatorName , NodeDisplayName , NodeDescription , NodeInterface ) ;
} ;
static const FNodeClassMetadata Metadata = CreateNodeClassMetadata ( ) ;
return Metadata ;
}
static TUniquePtr < IOperator > CreateOperator ( const FCreateOperatorParams & InParams , TArray < TUniquePtr < IOperatorBuildError > > & OutErrors )
{
const FInputVertexInterface & InputInterface = InParams . Node . GetVertexInterface ( ) . GetInputInterface ( ) ;
const FDataReferenceCollection & InputCollection = InParams . InputDataReferences ;
FTriggerReadRef Trigger = InputCollection . GetDataReadReferenceOrConstruct < FTrigger > ( PrintLogVertexNames : : GetInputTriggerName ( ) , InParams . OperatorSettings ) ;
TDataReadReference < FString > Label = InputCollection . GetDataReadReferenceOrConstructWithVertexDefault < FString > ( InputInterface , PrintLogVertexNames : : GetLabelPrintLogName ( ) , InParams . OperatorSettings ) ;
TDataReadReference < PrintLogType > ValueToLog = InputCollection . GetDataReadReferenceOrConstructWithVertexDefault < PrintLogType > ( InputInterface , PrintLogVertexNames : : GetToLogPrintLogName ( ) , InParams . OperatorSettings ) ;
2022-02-08 12:12:15 -05:00
FString GraphNameFull = InParams . Environment . GetValue < FString > ( Frontend : : SourceInterface : : Environment : : GraphName ) ;
TArray < FString > ParsedString ;
GraphNameFull . ParseIntoArray ( ParsedString , TEXT ( " . " ) , true ) ;
const FString & GraphName = ParsedString . Last ( ) ;
return MakeUnique < TPrintLogOperator < PrintLogType > > ( InParams . OperatorSettings , Trigger , Label , ValueToLog , GraphName ) ;
2021-04-01 17:28:48 -04:00
}
2022-02-08 12:12:15 -05:00
TPrintLogOperator ( const FOperatorSettings & InSettings , TDataReadReference < FTrigger > InTrigger , TDataReadReference < FString > InLabelPrintLog , TDataReadReference < PrintLogType > InValueToLogPrintLog , const FString & InGraphName )
2021-04-01 17:28:48 -04:00
: Trigger ( InTrigger )
, Label ( InLabelPrintLog )
, ValueToLog ( InValueToLogPrintLog )
2022-02-08 12:12:15 -05:00
, GraphName ( InGraphName )
2021-04-01 17:28:48 -04:00
{
}
virtual ~ TPrintLogOperator ( ) = default ;
virtual FDataReferenceCollection GetInputs ( ) const override
{
FDataReferenceCollection Inputs ;
Inputs . AddDataReadReference ( PrintLogVertexNames : : GetInputTriggerName ( ) , Trigger ) ;
Inputs . AddDataReadReference ( PrintLogVertexNames : : GetLabelPrintLogName ( ) , Label ) ;
Inputs . AddDataReadReference ( PrintLogVertexNames : : GetToLogPrintLogName ( ) , ValueToLog ) ;
return Inputs ;
}
virtual FDataReferenceCollection GetOutputs ( ) const override
{
FDataReferenceCollection Outputs ;
return Outputs ;
}
void Execute ( )
{
if ( * Trigger )
{
2022-02-08 12:12:15 -05:00
UE_LOG ( LogMetaSound , Display , TEXT ( " [%s]: %s %s " ) , * GraphName , * ( * Label ) , * LexToString ( * ValueToLog ) ) ;
2021-04-01 17:28:48 -04:00
}
}
private :
TDataReadReference < FTrigger > Trigger ;
TDataReadReference < FString > Label ;
TDataReadReference < PrintLogType > ValueToLog ;
2022-02-08 12:12:15 -05:00
FString GraphName ;
2021-04-01 17:28:48 -04:00
} ;
/** TPrintLogNode
*
* Records a value to the log when triggered
*/
template < typename PrintLogType >
class METASOUNDSTANDARDNODES_API TPrintLogNode : public FNodeFacade
{
public :
/**
* Constructor used by the Metasound Frontend .
*/
TPrintLogNode ( const FNodeInitData & InInitData )
: FNodeFacade ( InInitData . InstanceName , InInitData . InstanceID , TFacadeOperatorClass < TPrintLogOperator < PrintLogType > > ( ) )
{ }
virtual ~ TPrintLogNode ( ) = default ;
} ;
using FPrintLogNodeInt32 = TPrintLogNode < int32 > ;
METASOUND_REGISTER_NODE ( FPrintLogNodeInt32 )
using FPrintLogNodeFloat = TPrintLogNode < float > ;
METASOUND_REGISTER_NODE ( FPrintLogNodeFloat )
using FPrintLogNodeBool = TPrintLogNode < bool > ;
METASOUND_REGISTER_NODE ( FPrintLogNodeBool )
using FPrintLogNodeString = TPrintLogNode < FString > ;
METASOUND_REGISTER_NODE ( FPrintLogNodeString )
2021-03-16 00:22:37 -04:00
}
# undef LOCTEXT_NAMESPACE