示例#1
0
        public void TestCreateNodeOnEdge_BothPortsConnected([Values] TestingMode mode)
        {
            var constant = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(Stencil), Vector2.zero);
            var unary    = GraphModel.CreateUnaryOperatorNode(UnaryOperatorKind.Minus, Vector2.zero);
            var edge     = GraphModel.CreateEdge(unary.InputPort, constant.OutputPort);

            var db   = new GraphElementSearcherDatabase(Stencil).AddUnaryOperators().Build();
            var item = (GraphNodeModelSearcherItem)db.Search("minus", out _)[0];

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(unary.InputPort, Is.ConnectedTo(constant.OutputPort));
                return(new CreateNodeOnEdgeAction(edge, Vector2.zero, item));
            },
                                    () =>
            {
                var unary2 = GraphModel.NodeModels.OfType <UnaryOperatorNodeModel>().ToList()[1];

                Assert.IsNotNull(unary2);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(2));
                Assert.That(constant.OutputPort, Is.ConnectedTo(unary2.InputPort));
                Assert.That(unary2.OutputPort, Is.ConnectedTo(unary.InputPort));
                Assert.IsFalse(GraphModel.EdgeModels.Contains(edge));
            }
                                    );
        }
示例#2
0
        public void TestCreateNodeOnEdge_OnlyInputPortConnected([Values] TestingMode mode)
        {
            var constant = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(Stencil), Vector2.zero);
            var unary    = GraphModel.CreateUnaryOperatorNode(UnaryOperatorKind.Minus, Vector2.zero);
            var edge     = GraphModel.CreateEdge(unary.InputPort, constant.OutputPort);

            var db   = new GraphElementSearcherDatabase(Stencil).AddBinaryOperators().Build();
            var item = (GraphNodeModelSearcherItem)db.Search("equals", out _)[0];

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                RefreshReference(ref constant);
                RefreshReference(ref unary);
                edge = GetEdge(0);
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(unary.InputPort, Is.ConnectedTo(constant.OutputPort));
                return(new CreateNodeOnEdgeAction(edge, Vector2.zero, item));
            },
                                    () =>
            {
                RefreshReference(ref constant);
                RefreshReference(ref unary);
                var binary = GraphModel.NodeModels.OfType <BinaryOperatorNodeModel>().FirstOrDefault();

                Assert.IsNotNull(binary);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(constant.OutputPort, Is.ConnectedTo(binary.InputPortA));
                Assert.That(constant.OutputPort, Is.Not.ConnectedTo(unary.InputPort));
                Assert.That(binary.OutputPort, Is.Not.ConnectedTo(unary.InputPort));
                Assert.That(unary.InputPort, Is.Not.ConnectedTo(constant.OutputPort));
            }
                                    );
        }
示例#3
0
        void SpawnAllNodeModelsInGraph(VSGraphModel graphModel)
        {
            StackModel    stack;
            FunctionModel funcModel;

            //--Floating Nodes--

            //Stack-Derived NodeModels
            stack     = GraphModel.CreateNode <StackModel>("StackModel");
            funcModel = GraphModel.CreateNode <FunctionModel>("FunctionModel");
            var methodInfo = TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true);

            GraphModel.CreateEventFunction(methodInfo, Vector2.zero);
            GraphModel.CreateNode <OnEndEntitiesNodeModel>("OnEndEntitiesNodeModel");
            GraphModel.CreateNode <OnEventNodeModel>("OnEventNodeModel");
            GraphModel.CreateNode <OnStartEntitiesNodeModel>("OnStartEntitiesNodeModel");
            var onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("OnUpdateEntitiesNodeModel");

            GraphModel.CreateNode <PostUpdate>("PostUpdate");
            GraphModel.CreateNode <PreUpdate>("PreUpdate");
            GraphModel.CreateNode <KeyDownEventModel>("KeyDownEventModel");
            GraphModel.CreateLoopStack(typeof(ForEachHeaderModel), Vector2.zero);
            GraphModel.CreateLoopStack(typeof(WhileHeaderModel), Vector2.zero);
            GraphModel.CreateLoopStack(typeof(ForAllEntitiesStackModel), Vector2.zero);

            //Constant-typed NodeModels
            GraphModel.CreateNode <BooleanConstantNodeModel>("BooleanConstantNodeModel");
            GraphModel.CreateNode <ColorConstantModel>("ColorConstantModel");
            GraphModel.CreateNode <CurveConstantNodeModel>("CurveConstantNodeModel");
            GraphModel.CreateNode <DoubleConstantModel>("DoubleConstantModel");
            GraphModel.CreateNode <EnumConstantNodeModel>("EnumConstantNodeModel");
            GraphModel.CreateNode <FloatConstantModel>("FloatConstantModel");
            GraphModel.CreateNode <GetPropertyGroupNodeModel>("GetPropertyGroupNodeModel");
            GraphModel.CreateNode <InputConstantModel>("InputConstantModel");
            GraphModel.CreateNode <IntConstantModel>("IntConstantModel");
            GraphModel.CreateNode <LayerConstantModel>("LayerConstantModel");
            GraphModel.CreateNode <LayerMaskConstantModel>("LayerMaskConstantModel");
            GraphModel.CreateNode <ObjectConstantModel>("ObjectConstantModel");
            GraphModel.CreateNode <QuaternionConstantModel>("QuaternionConstantModel");
            GraphModel.CreateNode <StringConstantModel>("StringConstantModel");
            GraphModel.CreateNode <TagConstantModel>("TagConstantModel");
            GraphModel.CreateNode <TypeConstantModel>("TypeConstantModel");
            GraphModel.CreateNode <Vector2ConstantModel>("Vector2ConstantModel");
            GraphModel.CreateNode <Vector3ConstantModel>("Vector3ConstantModel");
            GraphModel.CreateNode <Vector4ConstantModel>("Vector4ConstantModel");
            GraphModel.CreateNode <ConstantSceneAssetNodeModel>("ConstantSceneAssetNodeModel");
            GraphModel.CreateNode <Float2ConstantModel>("Float2ConstantModel");
            GraphModel.CreateNode <Float3ConstantModel>("Float3ConstantModel");
            GraphModel.CreateNode <Float4ConstantModel>("Float4ConstantModel");

            //Misc
            void DefineSystemConstant(SystemConstantNodeModel m)
            {
                m.ReturnType    = typeof(float).GenerateTypeHandle(Stencil);
                m.DeclaringType = typeof(Mathf).GenerateTypeHandle(Stencil);
                m.Identifier    = "PI";
            }

            GraphModel.CreateNode <SystemConstantNodeModel>("SystemConstantNodeModel", Vector2.zero, SpawnFlags.Default, DefineSystemConstant);
            GraphModel.CreateNode <GroupNodeModel>("GroupNodeModel");
            GraphModel.CreateNode <GetInputNodeModel>("GetInputNodeModel");
            GraphModel.CreateNode <GetOrCreateComponentNodeModel>("GetOrCreateComponentNodeModel");
            GraphModel.CreateNode <GetSingletonNodeModel>("GetSingletonNodeModel");
            GraphModel.CreateNode <ThisNodeModel>("ThisNodeModel");
            VariableDeclarationModel decl = graphModel.CreateGraphVariableDeclaration("MyVariableName", typeof(int).GenerateTypeHandle(graphModel.Stencil), true);

            GraphModel.CreateVariableNode(decl, Vector2.zero);
            GraphModel.CreateNode <MacroRefNodeModel>("MacroRefNodeModel");
            GraphModel.CreateInlineExpressionNode("2+2", Vector2.zero);
            GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);
            GraphModel.CreateUnaryOperatorNode(UnaryOperatorKind.PostIncrement, Vector2.zero);

            //--Stack-Contained Nodes--
            stack.CreateStackedNode <AddComponentNodeModel>();
            stack.CreateStackedNode <DestroyEntityNodeModel>();
            stack.CreateStackedNode <ForAllEntitiesNodeModel>();
            stack.CreateStackedNode <ForEachNodeModel>();
            stack.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true));
            stack.CreateFunctionRefCallNode(funcModel);
            stack.CreateStackedNode <InstantiateNodeModel>();
            stack.CreateStackedNode <IfConditionNodeModel>();
            stack.CreateStackedNode <LogNodeModel>();
            stack.CreateStackedNode <RemoveComponentNodeModel>();
            stack.CreateStackedNode <SetComponentNodeModel>();
            stack.CreateStackedNode <SetPositionNodeModel>();
            stack.CreateStackedNode <SetRotationNodeModel>();
            stack.CreateStackedNode <WhileNodeModel>();
            stack.CreateStackedNode <SetPropertyGroupNodeModel>();
            stack.CreateStackedNode <SetVariableNodeModel>();
            funcModel.CreateStackedNode <ReturnNodeModel>();

            TypeHandle eventTypeHandle = typeof(UnitTestEvent).GenerateTypeHandle(Stencil);

            onUpdateModel.CreateStackedNode <SendEventNodeModel>("SendEventNodeModel", 0, SpawnFlags.Default, n => n.EventType = eventTypeHandle);
        }