public IEnumerable <IPortModel> GetPortsForComponent(TypeHandle th)
 {
     return(m_PortDescriptions
            .FirstOrDefault(pm => pm.Component == th)
            ?.GetFieldIds()
            .Select(id => InputsById[id])
            ?? Enumerable.Empty <IPortModel>());
 }
Example #2
0
 public static TypeSyntax ToTypeSyntax(this TypeHandle handle, Stencil stencil)
 {
     if (handle.GraphModelReference != null)
     {
         return(handle.GraphModelReference.ToTypeSyntax());
     }
     return(handle.Resolve(stencil).ToTypeSyntax());
 }
        public static ComponentPortsDescription FromData(TypeHandle componentType, IReadOnlyList <Tuple <string, TypeHandle> > componentDescriptions, string prefix = null)
        {
            var result = new ComponentPortsDescription(componentType, componentDescriptions.Count, prefix)
            {
                m_FieldNames = componentDescriptions.Select(t => t.Item1).ToList()
            };

            return(result);
        }
        public void DeleteComponentOperation(TypeHandle th)
        {
            var i = m_AdditionalComponents.FindIndex(compOps => compOps.Type == th);

            if (i != -1)
            {
                m_AdditionalComponents.RemoveAt(i);
            }
        }
        internal ComponentPortsDescription AddPortsForComponent(TypeHandle comp, string prefix = null)
        {
            var inputsFromComponentType = HighLevelNodeModelHelpers.GetDataInputsFromComponentType(Stencil, comp).ToList();

            var description = ComponentPortsDescription.FromData(comp, inputsFromComponentType, prefix);

            foreach (Tuple <string, TypeHandle> field in inputsFromComponentType)
            {
                AddDataInput($"{field.Item1}", field.Item2, description.GetFieldId(field.Item1));
            }

            return(description);
        }
        internal static IEnumerable <Tuple <string, TypeHandle> > GetDataInputsFromComponentType(
            Stencil stencil,
            TypeHandle componentTypeHandle
            )
        {
            var componentType = componentTypeHandle.Resolve(stencil);
            var fields        = componentType.GetFields(BindingFlags.Public | BindingFlags.Instance);
            var type          = HasSinglePredefinedFieldType(fields)
                    ? fields[0].FieldType
                    : componentType;

            return(type.GetFields(BindingFlags.Public | BindingFlags.Instance)
                   .Select(f => new Tuple <string, TypeHandle>(f.Name, f.FieldType.GenerateTypeHandle(stencil))));
        }
        public static void AddCriterion(this ICriteriaModelContainer criteriaModelContainer,
                                        CriteriaModel criteriaModel,
                                        TypeHandle typeHandle,
                                        TypeMember typeMember,
                                        BinaryOperatorKind operatorKind)
        {
            if (!criteriaModelContainer.CriteriaModels.Contains(criteriaModel))
            {
                return;
            }

            Undo.RegisterCompleteObjectUndo(criteriaModelContainer.SerializableAsset, "Add Criterion To Criteria Model");
            criteriaModel.AddCriterion((VSGraphModel)criteriaModelContainer.GraphModel, typeHandle, typeMember, operatorKind);
        }
        public SearcherFilter GetEdgeSearcherFilter(IEdgeModel edgeModel)
        {
            Type       it  = edgeModel.InputPortModel.DataType.Resolve(m_Stencil);
            IPortModel opm = edgeModel.OutputPortModel;
            TypeHandle oth = opm.DataType == TypeHandle.ThisType ? m_Stencil.GetThisType() : opm.DataType;
            Type       ot  = oth.Resolve(m_Stencil);

            return(new SearcherFilter(SearcherContext.Graph)
                   .WithVisualScriptingNodesExcept(new[] { typeof(ThisNodeModel) }) // TODO : We should be able to determine if a VSNode type has input port instead of doing this
                   .WithFields(ot, it)
                   .WithUnaryOperators(ot, opm.NodeModel is IConstantNodeModel)
                   .WithBinaryOperators(ot)
                   .WithMethods(ot, it)
                   .WithProperties(ot, it, false));
        }
        public virtual SearcherFilter GetOutputToStackSearcherFilter(IPortModel portModel, IStackModel stackModel)
        {
            // TODO : Need to be handled by TypeHandle.Resolve
            TypeHandle      typeHandle = portModel.DataType == TypeHandle.ThisType ? m_Stencil.GetThisType() : portModel.DataType;
            Type            type       = typeHandle.Resolve(m_Stencil);
            GraphAssetModel assetModel = portModel.AssetModel as GraphAssetModel;

            return(new SearcherFilter(SearcherContext.Stack)
                   .WithVisualScriptingNodes()
                   .WithFields(type)
                   .WithUnaryOperators(type)
                   .WithIfConditions(typeHandle, stackModel)
                   .WithMethods(type)
                   .WithProperties(type, false)
                   .WithGraphAsset(assetModel));
        }
        public SearcherFilter GetOutputToGraphSearcherFilter(IPortModel portModel)
        {
            // TODO : Need to be handled by TypeHandle.Resolve
            TypeHandle        typeHandle = portModel.DataType == TypeHandle.ThisType ? m_Stencil.GetThisType() : portModel.DataType;
            Type              type       = typeHandle.Resolve(m_Stencil);
            VSGraphAssetModel assetModel = portModel.AssetModel as VSGraphAssetModel;

            return(new SearcherFilter(SearcherContext.Graph)
                   .WithVisualScriptingNodes()
                   .WithFields(type)
                   .WithUnaryOperators(type, portModel.NodeModel is IConstantNodeModel)
                   .WithBinaryOperators(type)
                   .WithMethods(type)
                   .WithProperties(type)
                   .WithGraphAsset(assetModel));
        }
        public virtual List <SearcherDatabase> GetTypeMembersSearcherDatabases(TypeHandle typeHandle)
        {
            // TODO : Need to be handled by TypeHandle.Resolve
            Type type = typeHandle == TypeHandle.ThisType
                ? m_Stencil.GetThisType().Resolve(m_Stencil)
                : typeHandle.Resolve(m_Stencil);

            return(new List <SearcherDatabase>
            {
                new GraphElementSearcherDatabase(m_Stencil)
                .AddMembers(
                    new[] { type },
                    MemberFlags.Field | MemberFlags.Method | MemberFlags.Property | MemberFlags.Extension,
                    BindingFlags.Instance | BindingFlags.Public
                    )
                .Build()
            });
        }
Example #12
0
        public virtual Type GetConstantNodeModelType(TypeHandle typeHandle)
        {
            if (s_TypeToConstantNodeModelTypeCache == null)
            {
                s_TypeToConstantNodeModelTypeCache = new Dictionary <TypeHandle, Type>
                {
                    { typeof(Boolean).GenerateTypeHandle(this), typeof(BooleanConstantNodeModel) },
                    { typeof(Color).GenerateTypeHandle(this), typeof(ColorConstantModel) },
                    { typeof(AnimationCurve).GenerateTypeHandle(this), typeof(CurveConstantNodeModel) },
                    { typeof(Double).GenerateTypeHandle(this), typeof(DoubleConstantModel) },
                    { typeof(Unknown).GenerateTypeHandle(this), typeof(EnumConstantNodeModel) },
                    { typeof(Single).GenerateTypeHandle(this), typeof(FloatConstantModel) },
                    { typeof(InputName).GenerateTypeHandle(this), typeof(InputConstantModel) },
                    { typeof(Int32).GenerateTypeHandle(this), typeof(IntConstantModel) },
                    { typeof(LayerName).GenerateTypeHandle(this), typeof(LayerConstantModel) },
                    { typeof(LayerMask).GenerateTypeHandle(this), typeof(LayerMaskConstantModel) },
                    { typeof(Object).GenerateTypeHandle(this), typeof(ObjectConstantModel) },
                    { typeof(Quaternion).GenerateTypeHandle(this), typeof(QuaternionConstantModel) },
                    { typeof(String).GenerateTypeHandle(this), typeof(StringConstantModel) },
                    { typeof(TagName).GenerateTypeHandle(this), typeof(TagConstantModel) },
                    { typeof(Type).GenerateTypeHandle(this), typeof(TypeConstantModel) },
                    { typeof(Vector2).GenerateTypeHandle(this), typeof(Vector2ConstantModel) },
                    { typeof(Vector3).GenerateTypeHandle(this), typeof(Vector3ConstantModel) },
                    { typeof(Vector4).GenerateTypeHandle(this), typeof(Vector4ConstantModel) },
                    { typeof(SceneAsset).GenerateTypeHandle(this), typeof(ConstantSceneAssetNodeModel) },
                };
            }

            if (s_TypeToConstantNodeModelTypeCache.TryGetValue(typeHandle, out var result))
            {
                return(result);
            }

            Type t = typeHandle.Resolve(this);

            if (t.IsEnum || t == typeof(Enum))
            {
                return(typeof(EnumConstantNodeModel));
            }

            return(null);
        }
        public void SetComponentOperation(TypeHandle type, ComponentOperationType operation)
        {
            var i = m_AdditionalComponents.FindIndex(compOps => compOps.Type == type);

            if (i == -1)
            {
                m_AdditionalComponents.Add(new ComponentOperation(type, operation));
            }
            else if (operation == ComponentOperationType.AddComponent ||
                     operation == ComponentOperationType.RemoveComponent ||
                     operation == ComponentOperationType.SetComponent)
            {
                m_AdditionalComponents[i] =
                    new ComponentOperation(type, operation, m_AdditionalComponents[i].FromArchetype);
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(operation), operation, null);
            }
        }
Example #14
0
 public static TypeSyntax ToTypeSyntax(this TypeHandle handle, Stencil stencil)
 {
     return(handle.Resolve(stencil).ToTypeSyntax());
 }
 ComponentPortsDescription(TypeHandle component, int capacity, string prefix = null)
 {
     Component    = component;
     m_FieldNames = new List <string>(capacity);
     m_Prefix     = prefix;
 }
Example #16
0
        protected override void UpdateInputPortModels()
        {
            Port.CreateInputPort(m_Store, Model.InstancePort, inputContainer, inputContainer);
            Port.CreateInputPort(m_Store, Model.EntityPort, titleContainer, inputContainer);
            //TODO deal with presence of same component type in both lists

            foreach (var componentOperation in Model.GetEditableComponents())
            {
                TypeHandle compType           = componentOperation.Type;
                var        componentContainer = new VisualElement {
                    name = "instantiateComponentNode"
                };
                var componentTitleContainer = new VisualElement {
                    name = "componentDataTitle"
                };
                componentContainer.Add(new VisualElement {
                    name = "componentSeparatorLine"
                });
                componentContainer.Add(componentTitleContainer);

                var deleteComponentButton = new Button {
                    name = "deleteComponentIcon"
                };
                deleteComponentButton.clickable.clicked += () => { DeleteComponentOperation(compType); };
                componentTitleContainer.Insert(0, deleteComponentButton);

                deleteComponentButton.EnableInClassList("deletable", !componentOperation.FromArchetype);
                componentTitleContainer.Add(deleteComponentButton);

                componentTitleContainer.Add(new Label(compType.Name(Model.GraphModel.Stencil))
                {
                    name = "componentTitle"
                });

                componentTitleContainer.Add(new VisualElement {
                    name = "filler"
                });

                var operationType = new EnumField(componentOperation.OperationType)
                {
                    name = "componentOperationType"
                };

                //Do I need to unregister it afterwards?
                //Also, allocation a closure for each component operations... meh?
                operationType.RegisterValueChangedCallback(eventValue => SetComponentOperation(compType, (ComponentOperation.ComponentOperationType)eventValue.newValue));
                componentTitleContainer.Add(operationType);
                inputContainer.Add(componentContainer);

                if (componentOperation.OperationType != ComponentOperation.ComponentOperationType.RemoveComponent)
                {
                    var componentPortsContainer = new VisualElement {
                        name = "componentDataPorts"
                    };
                    componentContainer.Add(componentPortsContainer);
                    foreach (var port in Model.GetPortsForComponent(componentOperation.Type))
                    {
                        Port.CreateInputPort(m_Store, port, componentPortsContainer, componentPortsContainer);
                    }
                }
            }
        }
Example #17
0
        void DeleteComponentOperation(TypeHandle componentType)
        {
            var action = new RemoveOperationForComponentTypeInInstantiateNodeAction(Model, componentType);

            m_Store.Dispatch(action);
        }
Example #18
0
        public static List <NodeModel> SpawnAllNodeModelsInGraph(VSGraphModel graphModel)
        {
            List <NodeModel>          spawnedNodes = new List <NodeModel>();
            Stencil                   stencil      = graphModel.Stencil;
            StackModel                stack;
            FunctionModel             funcModel;
            OnUpdateEntitiesNodeModel onUpdateModel;

            //--Floating Nodes--

            //Stack-Derived NodeModels
            spawnedNodes.Add(stack         = graphModel.CreateNode <StackModel>("StackModel"));
            spawnedNodes.Add(funcModel     = graphModel.CreateNode <FunctionModel>("FunctionModel"));
            spawnedNodes.Add(onUpdateModel = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("OnUpdateEntitiesNodeModel"));

            var methodInfo = TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true);

            spawnedNodes.Add(graphModel.CreateEventFunction(methodInfo, Vector2.zero));
            spawnedNodes.Add(graphModel.CreateNode <OnEndEntitiesNodeModel>("OnEndEntitiesNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <OnEventNodeModel>("OnEventNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <OnStartEntitiesNodeModel>("OnStartEntitiesNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <PostUpdate>("PostUpdate"));
            spawnedNodes.Add(graphModel.CreateNode <PreUpdate>("PreUpdate"));
            spawnedNodes.Add(graphModel.CreateNode <KeyDownEventModel>("KeyDownEventModel"));
            spawnedNodes.Add(graphModel.CreateNode <CountEntitiesNodeModel>("CountEntitiesNodeModel"));
            spawnedNodes.Add(graphModel.CreateLoopStack(typeof(ForEachHeaderModel), Vector2.zero));
            spawnedNodes.Add(graphModel.CreateLoopStack(typeof(WhileHeaderModel), Vector2.zero));
            spawnedNodes.Add(graphModel.CreateLoopStack(typeof(ForAllEntitiesStackModel), Vector2.zero));
            spawnedNodes.Add(graphModel.CreateLoopStack(typeof(CoroutineStackModel), Vector2.zero));

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

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

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

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

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

            TypeHandle eventTypeHandle = typeof(DummyEvent).GenerateTypeHandle(stencil);

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

            return(spawnedNodes);
        }
Example #19
0
        void AddComponentOperation(TypeHandle componentType)
        {
            var action = new SetOperationForComponentTypeInCreateEntityNodeAction(Model, componentType);

            m_Store.Dispatch(action);
        }
Example #20
0
 public static Type Resolve(this TypeHandle th, Stencil stencil)
 {
     return(th.Resolve(stencil.GraphContext.TypeHandleSerializer));
 }
Example #21
0
 public static Type Resolve(this TypeHandle th, ITypeBasedTypeHandleSerializer serializer)
 {
     return(serializer.ResolveType(th));
 }
Example #22
0
 public Type ResolveType(TypeHandle th)
 {
     return(Deserialize(th.Identification));
 }
 public VSGraphModel ResolveGraph(TypeHandle th)
 {
     return(th.GraphModelReference != null ? th.GraphModelReference : null);
 }
Example #24
0
 public static ITypeMetadata GetMetadata(this TypeHandle th, Stencil stencil)
 {
     return(th.GetMetadata(stencil.GraphContext.TypeMetadataResolver));
 }
Example #25
0
 public static ITypeMetadata GetMetadata(this TypeHandle th, ITypeMetadataResolver resolver)
 {
     return(resolver.Resolve(th));
 }
Example #26
0
 public static Type Resolve(this TypeHandle th, CSharpTypeSerializer serializer)
 {
     return(serializer.ResolveType(th));
 }
 public ComponentOperation(TypeHandle type, ComponentOperationType operationType, bool fromArchetype = false)
 {
     Type          = type;
     OperationType = operationType;
     FromArchetype = fromArchetype;
 }
Example #28
0
        void SetComponentOperation(TypeHandle componentType, ComponentOperation.ComponentOperationType newValue)
        {
            var action = new SetOperationForComponentTypeInInstantiateNodeAction(Model, componentType, newValue);

            m_Store.Dispatch(action);
        }
 public Type ResolveType(TypeHandle th)
 {
     return(m_TypeSerializer.ResolveType(th));
 }
Example #30
0
 public void DeleteComponentOperation(TypeHandle type) => m_AdditionalComponents.Remove(type);