public virtual IVariableModel CreateVariableModelForDeclaration(IGraphModel graphModel, IVariableDeclarationModel declarationModel, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
        {
            if (declarationModel == null)
            {
                return(graphModel.CreateNode <ThisNodeModel>("this", position, spawnFlags, guid: guid));
            }

            return(graphModel.CreateNode <VariableNodeModel>(declarationModel.Title, position, spawnFlags, v => v.DeclarationModel = declarationModel, guid));
        }
        public static FunctionModel CreateFunction(this IGraphModel graphModel, string methodName, Vector2 position,
                                                   SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
        {
            graphModel.Stencil.GetSearcherDatabaseProvider().ClearReferenceItemsSearcherDatabases();
            var uniqueMethodName = graphModel.GetUniqueName(methodName);

            return(graphModel.CreateNode <FunctionModel>(uniqueMethodName, position, spawnFlags, guid: guid));
        }
        public static InlineExpressionNodeModel CreateInlineExpressionNode(this IGraphModel graphModel,
                                                                           string expression, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
        {
            const string nodeName = "inline";

            void Setup(InlineExpressionNodeModel m) => m.Expression = expression;

            return(graphModel.CreateNode <InlineExpressionNodeModel>(nodeName, position, spawnFlags, Setup, guid));
        }
        public static EventFunctionModel CreateEventFunction(this IGraphModel graphModel, MethodInfo methodInfo,
                                                             Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
        {
            graphModel.Stencil.GetSearcherDatabaseProvider().ClearReferenceItemsSearcherDatabases();

            void Setup(EventFunctionModel e) => e.EventType = methodInfo.DeclaringType.GenerateTypeHandle(graphModel.Stencil);

            return(graphModel.CreateNode <EventFunctionModel>(methodInfo.Name, position, spawnFlags, Setup, guid));
        }
 public override IVariableModel CreateVariableModelForDeclaration(IGraphModel graphModel, IVariableDeclarationModel declarationModel, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
 {
     // Custom smart object reference node
     if (declarationModel.IsSmartObject())
     {
         return(graphModel.CreateNode <SmartObjectReferenceNodeModel>(declarationModel.Title, position, spawnFlags, n => n.DeclarationModel = declarationModel));
     }
     // For Object references and inputs/outputs, keep the base VariableNodeModel
     if (declarationModel.IsObjectReference() || (declarationModel.IsInputOrOutput() && !declarationModel.IsDataOutput()))
     {
         return(base.CreateVariableModelForDeclaration(graphModel, declarationModel, position, spawnFlags, guid));
     }
     // Graph Variables: custom SetVariableNodeModel
     return(graphModel.CreateNode <SetVariableNodeModel>(declarationModel.Title, position, spawnFlags, v =>
     {
         v.DeclarationModel = declarationModel;
     }, guid));
 }
        public static StackBaseModel CreateStack(this IGraphModel graphModel, string name, Vector2 position,
                                                 SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
        {
            var stackTypeToCreate = graphModel.Stencil.GetDefaultStackModelType();

            if (!typeof(StackModel).IsAssignableFrom(stackTypeToCreate))
            {
                stackTypeToCreate = typeof(StackModel);
            }

            return((StackBaseModel)graphModel.CreateNode(stackTypeToCreate, name, position, spawnFlags, guid: guid));
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new node in a graph.
        /// </summary>
        /// <param name="self">The graph to add a node to.</param>
        /// <param name="nodeName">The name of the node to create.</param>
        /// <param name="position">The position of the node to create.</param>
        /// <param name="guid">The SerializableGUID to assign to the newly created item.</param>
        /// <param name="initializationCallback">An initialization method to be called right after the node is created.</param>
        /// <param name="spawnFlags">The flags specifying how the node is to be spawned.</param>
        /// <typeparam name="TNodeType">The type of the new node to create.</typeparam>
        /// <returns>The newly created node.</returns>
        public static TNodeType CreateNode <TNodeType>(this IGraphModel self, string nodeName = "", Vector2 position = default,
                                                       SerializableGUID guid = default, Action <TNodeType> initializationCallback = null, SpawnFlags spawnFlags = SpawnFlags.Default)
            where TNodeType : class, INodeModel
        {
            Action <INodeModel> setupWrapper = null;

            if (initializationCallback != null)
            {
                setupWrapper = n => initializationCallback.Invoke(n as TNodeType);
            }

            return((TNodeType)self.CreateNode(typeof(TNodeType), nodeName, position, guid, setupWrapper, spawnFlags));
        }
        public static IConstantNodeModel CreateConstantNode(this IGraphModel graphModel, string constantName,
                                                            TypeHandle constantTypeHandle, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
        {
            var nodeType = graphModel.Stencil.GetConstantNodeModelType(constantTypeHandle);

            void PreDefineSetup(NodeModel model)
            {
                if (model is ConstantNodeModel constantModel)
                {
                    constantModel.PredefineSetup(constantTypeHandle);
                }
            }

            return((ConstantNodeModel)graphModel.CreateNode(nodeType, constantName, position, spawnFlags, PreDefineSetup, guid));
        }
 public static BinaryOperatorNodeModel CreateBinaryOperatorNode(this IGraphModel graphModel,
                                                                BinaryOperatorKind kind, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
 {
     return(graphModel.CreateNode <BinaryOperatorNodeModel>(kind.ToString(), position, spawnFlags, n => n.Kind = kind, guid));
 }
 public static FunctionCallNodeModel CreateFunctionCallNode(this IGraphModel graphModel, MethodBase methodInfo,
                                                            Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
 {
     return(graphModel.CreateNode <FunctionCallNodeModel>(methodInfo.Name, position, spawnFlags, n => n.MethodInfo = methodInfo, guid));
 }
 public static LoopStackModel CreateLoopStack(this IGraphModel graphModel, Type loopStackType, Vector2 position,
                                              SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
 {
     return((LoopStackModel)graphModel.CreateNode(loopStackType, "loopStack", position, spawnFlags, node => ((LoopStackModel)node).CreateLoopVariables(null), guid));
 }
 public static T CreateLoopStack <T>(this IGraphModel graphModel, Vector2 position,
                                     SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null) where T : LoopStackModel
 {
     return(graphModel.CreateNode <T>("loopStack", position, spawnFlags, node => node.CreateLoopVariables(null), guid));
 }
 public static MacroRefNodeModel CreateMacroRefNode(this IGraphModel graphModel, GraphModel macroGraphModel,
                                                    Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
 {
     return(graphModel.CreateNode <MacroRefNodeModel>(graphModel.AssetModel.Name, position, spawnFlags, n => n.GraphAssetModel = (GraphAssetModel)macroGraphModel.AssetModel, guid));
 }
 public static GetPropertyGroupNodeModel CreateGetPropertyGroupNode(this IGraphModel graphModel,
                                                                    Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null)
 {
     return(graphModel.CreateNode <GetPropertyGroupNodeModel>(GetPropertyGroupNodeModel.k_Title, position, spawnFlags, guid: guid));
 }