Esempio n. 1
0
        public void PinConnected(NodeItem fromConnect, string property)
        {
            Type t    = DotaAction.GetType();
            var  prop = t.GetProperty(property);

            if (prop == null)
            {
                throw new ArgumentException("Property must be a valid KV property");
            }
            if (fromConnect.Node is VariableNode)
            {
                if (prop.PropertyType == typeof(NumberValue))
                {
                    var vn = fromConnect.Node as VariableNode;
                    var nv = new NumberValue("%" + vn.Variable.Name);

                    prop.SetMethod.Invoke(DotaAction, new object[] { nv });
                }
            }
            if (fromConnect is TargetNodeItem)
            {
                if (prop.PropertyType == typeof(TargetKey))
                {
                    var target = (fromConnect as TargetNodeItem).Target;

                    prop.SetMethod.Invoke(DotaAction, new object[] { target });
                }
            }
        }
Esempio n. 2
0
        public void RefreshVariableRefs()
        {
            VariableReferences.Clear();

            Type t = DotaAction.GetType();

            //Loop through all of this action's properties and add node elements for each property type
            PropertyInfo[] properties = t.GetProperties();

            foreach (PropertyInfo prop in properties)
            {
                //Skip DotaDataObject's properties as they don't go into the node
                if (prop.Name == "ClassName")
                {
                    continue;
                }
                if (prop.Name == "KeyValue")
                {
                    continue;
                }
                if (prop.Name == "ObjectInfo")
                {
                    continue;
                }
                if (prop.Name == "Target")
                {
                    continue;                        //Skip target because we handled it already
                }
                if (prop.PropertyType == typeof(NumberValue))
                {
                    NumberValue nv = prop.GetMethod.Invoke(DotaAction, new object[] { }) as NumberValue;

                    if (nv.IsVariable)
                    {
                        //Check to see if we have a variable reference in our list
                        VariableRefInfo varRef = VariableReferences.FirstOrDefault(x => x.VariableName == nv.Value);
                        if (varRef != null) //varRef is not null, so we can just add this pin to the reference list
                        {
                            //Get the pin for this property
                            NodeItem pin = this.Items.FirstOrDefault(x => (string)x.Tag == prop.Name);

                            List <NodeItem> pins = new List <NodeItem>(varRef.InputPins);
                            pins.Add(pin);
                            varRef.InputPins = pins.ToArray();
                        }
                        else //We don't have a reference entry fo this one.  Lets add it
                        {
                            varRef = new VariableRefInfo();
                            varRef.VariableName = nv.Value;

                            //Get the pin for this property
                            NodeItem pin = this.Items.FirstOrDefault(x => (string)x.Tag == prop.Name);

                            varRef.InputPins = new NodeItem[] { pin };

                            VariableReferences.Add(varRef);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void AddNodeElements()
        {
            Type t = DotaAction.GetType();

            InputExecute = new ExecuteNodeItem("Execute", NodeItemType.Input);
            this.AddItem(InputExecute);

            OutputExecute = new ExecuteNodeItem("Execute", NodeItemType.Output);
            this.AddItem(OutputExecute);

            //Loop through all of this action's properties and add node elements for each property type
            PropertyInfo[] properties = t.GetProperties();

            //Target should always be ordered first
            var target = properties.FirstOrDefault(x => x.Name == "Target");

            if (target != null)
            {
                TargetPin     = new TargetNodeItem(target.Name, NodeItemType.Input);
                TargetPin.Tag = "Target";
                this.AddItem(TargetPin);
            }


            foreach (PropertyInfo prop in properties)
            {
                //Skip DotaDataObject's properties as they don't go into the node
                if (prop.Name == "ClassName")
                {
                    continue;
                }
                if (prop.Name == "KeyValue")
                {
                    continue;
                }
                if (prop.Name == "ObjectInfo")
                {
                    continue;
                }
                if (prop.Name == "Target")
                {
                    continue;                        //Skip target because we handled it already
                }
                NodeItem item = null;
                if (prop.PropertyType == typeof(NumberValue))
                {
                    item = new NumberValueItem(prop.Name, 20, 20, 0, 100, 0, NodeItemType.Input);
                }
                if (prop.PropertyType == typeof(TargetKey))
                {
                    item = new TargetNodeItem(prop.Name, NodeItemType.Input);
                }
                if (prop.PropertyType == typeof(DotaActionCollection))
                {
                    item = new ExecuteNodeItem(prop.Name, NodeItemType.Output);

                    var ex = item as ExecuteNodeItem;
                    ex.ActionCollection = prop.GetMethod.Invoke(DotaAction, new object[] { }) as DotaActionCollection; //Assign this execute node as the end point
                                                                                                                       //for an action collection execute chain
                }

                if (item == null)
                {
                    item = new NodeLabelItem(prop.Name, NodeItemType.Input);
                }

                item.Tag = prop.Name;
                this.AddItem(item);
            }
        }