Example #1
0
        /// <summary>
        /// Used to duplicate all properties. Any property added must be duplicated here as well.
        /// </summary>
        /// <param name="newnode">The new node which is supposed to get a copy of the properties.</param>
        protected virtual void CloneProperties(Node newnode) {
            Debug.Check(newnode != null);

            // clone properties
            newnode.ScreenLocation = this.ScreenLocation;
            newnode.Id = this.Id;
            newnode.Enable = this.Enable;

            if (this.CommentObject != null) {
                newnode.CommentObject = this.CommentObject.Clone();
            }

            checkPrefabFile();
            newnode.PrefabName = this.PrefabName;
            newnode.PrefabNodeId = this.PrefabNodeId;
            newnode.HasOwnPrefabData = this.HasOwnPrefabData;

            // clone pars.
            if (this is Behavior) {
                Behavior bnew = newnode as Behavior;
                bnew.LocalVars.Clear();

                foreach(ParInfo par in((Behavior)this).LocalVars) {
                    bnew.LocalVars.Add(par.Clone(bnew));
                }
            }

            // clone attachements
            newnode.Attachments.Clear();
            foreach(Attachments.Attachment attach in _attachments) {
                newnode.AddAttachment(attach.Clone(newnode));
            }
        }
Example #2
0
        /// <summary>
        /// Used to duplicate all properties. Any property added must be duplicated here as well.
        /// </summary>
        /// <param name="newnode">The new node which is supposed to get a copy of the properties.</param>
        protected virtual void CloneProperties(Node newnode)
        {
            Debug.Check(newnode != null);

            // clone properties
            newnode.Version = this.Version;
            newnode.Id = this.Id;
            newnode.Enable = this.Enable;
            newnode.WasModified = this.WasModified;
            if (this.CommentObject != null)
            {
                newnode.CommentObject = this.CommentObject.Clone();
            }

            checkPrefabFile();
            newnode.PrefabName = this.PrefabName;
            newnode.PrefabNodeId = this.PrefabNodeId;
            newnode.HasOwnPrefabData = this.HasOwnPrefabData;

            if (this.EnterAction != null)
            {
                newnode.EnterAction = (MethodDef)this.EnterAction.Clone();
            }
            if (this.ExitAction != null)
            {
                newnode.ExitAction = (MethodDef)this.ExitAction.Clone();
            }

            // clone pars.
            newnode.Pars.Clear();
            foreach (ParInfo par in this.Pars)
            {
                newnode.Pars.Add(par.Clone(newnode));
            }

            // clone attachements
            newnode.Attachments.Clear();
            foreach (Attachments.Attachment attach in _attachments)
            {
                newnode.AddAttachment(attach.Clone(newnode));
            }
        }
Example #3
0
        private bool replaceNode(Node node, Node newnode) {
            if (node == null || !node.IsFSM && node.ParentConnector == null || newnode == null) {
                return false;
            }

            bool replaced = (node.Children.Count == 0);

            if (!replaced && newnode.CanAdoptChildren(node)) {
                foreach(Node.Connector connector in node.Connectors) {
                    Node.Connector newConnector = newnode.GetConnector(connector.Identifier);

                    if (newConnector != null) {
                        for (int i = 0; i < connector.ChildCount; ++i) {
                            replaced |= newnode.AddChild(newConnector, (Node)connector.GetChild(i));
                        }

                        connector.ClearChildrenInternal();
                    }
                }
            }

            if (replaced)
            {
                Node parentNode = (Node)node.Parent;

                if (node.IsFSM)
                {
                    Debug.Check(newnode.IsFSM);

                    parentNode.RemoveFSMNode(node);
                    parentNode.AddFSMNode(newnode);

                    newnode.ScreenLocation = node.ScreenLocation;
                }
                else
                {
                    Node.Connector parentConnector = node.ParentConnector;
                    Debug.Check(parentConnector != null);

                    int index = parentConnector.GetChildIndex(node);
                    Debug.Check(index >= 0);

                    parentNode.RemoveChild(parentConnector, node);
                    parentNode.AddChild(parentConnector, newnode, index);
                }

                foreach (Attachments.Attachment attach in node.Attachments)
                {
                    if (attach != null && newnode.AcceptsAttachment(attach))
                        newnode.AddAttachment(attach);
                }
            }

            return replaced;
        }
Example #4
0
        //if there is a 'Predicate' attachment, convert it to a Condition node and attach it to the '_custom_condition' connector.
        private void AutoRestruct(List<Node.ErrorCheck> result, int version, Behaviac.Design.Attachments.Attachment a, Node node)
        {
            if (version <= 1)
            {
                string attachClass = a.GetType().FullName;
                if (attachClass.IndexOf("PluginBehaviac.Events.Predicate") >= 0)
                {
                    DesignerPropertyInfo propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opl");
                    RightValueDef opl = propInfo.GetValue(a) as RightValueDef;
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opr");
                    RightValueDef opr = propInfo.GetValue(a) as RightValueDef;
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Operator");
                    OperatorType oprr = (OperatorType)propInfo.GetValue(a);
                    OperatorTypes oprType = (OperatorTypes)((int)OperatorTypes.Equal - (int)OperatorType.Equal + (int)oprr);
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "BinaryOperator");
                    Behaviac.Design.Attachments.BinaryOperator binaryOpr = (Behaviac.Design.Attachments.BinaryOperator)propInfo.GetValue(a);

                    string clss = node.GetType().FullName;
                    bool bIsSeqSel = (node.GetType().IsSubclassOf(typeof(Sequence)) ||
                        node.GetType().IsSubclassOf(typeof(Selector)));

                    bool bCare = (bIsSeqSel ||
                        node.GetType().IsSubclassOf(typeof(Impulse))
                       );

                    if (bCare ||
                        clss == "PluginBehaviac.Nodes.Query" ||
                        clss == "PluginBehaviac.Nodes.DecoratorCountLimit")
                    {
                        node.RemoveAttachment(a);
                        node.Behavior.TriggerWasModified(node);

                        Type newType = Plugin.GetType("PluginBehaviac.Nodes.Condition");

                        Behaviac.Design.Nodes.Node newNode = Behaviac.Design.Nodes.Node.Create(newType);
                        Behaviac.Design.Nodes.Node.Connector connector = node.GetConnector(Node.Connector.kInterupt);

                        if (connector != null && connector.Identifier == Node.Connector.kInterupt && connector.ChildCount > 0)
                        {
                            //it has multiple Predicates, so insert all of them to a newly created Sequence
                            Node oldOne = (Node)connector.GetChild(0);
                            if (oldOne.GetType().IsSubclassOf(typeof(Condition)))
                            {
                                AddAfterConditions(node, binaryOpr, newNode, connector, oldOne);
                            }
                            else
                            {
                                if (bIsSeqSel)
                                {
                                    Debug.Check(oldOne.GetType().IsSubclassOf(typeof(Decorator)));
                                    Decorator d = oldOne as Decorator;
                                    node = oldOne;
                                    connector = node.GetConnector(BaseNode.Connector.kGeneric);
                                    oldOne = (Node)d.Children[0];
                                }

                                if (oldOne.GetType()== typeof(PluginBehaviac.Nodes.And))
                                {
                                    if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.Or)
                                    {
                                        node.RemoveChild(connector, oldOne);
                                        Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.Or");

                                        Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1);
                                        sel.AddChild(BaseNode.Connector.kGeneric, oldOne);
                                        sel.AddChild(BaseNode.Connector.kGeneric, newNode);

                                        node.AddChild(BaseNode.Connector.kInterupt, sel);
                                    }
                                    else
                                    {
                                        oldOne.AddChild(BaseNode.Connector.kGeneric, newNode);
                                    }
                                }
                                else if (oldOne.GetType() == typeof(PluginBehaviac.Nodes.Or))
                                {
                                    if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.And)
                                    {
                                        node.RemoveChild(connector, oldOne);
                                        Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.And");

                                        Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1);
                                        sel.AddChild(BaseNode.Connector.kGeneric, oldOne);
                                        sel.AddChild(BaseNode.Connector.kGeneric, newNode);

                                        node.AddChild(BaseNode.Connector.kInterupt, sel);
                                    }
                                    else
                                    {
                                        oldOne.AddChild(BaseNode.Connector.kGeneric, newNode);
                                    }
                                }
                                else if (oldOne.GetType().IsSubclassOf(typeof(Condition)))
                                {
                                    AddAfterConditions(node, binaryOpr, newNode, connector, oldOne);
                                }
                                else
                                {
                                    Debug.Check(false);
                                }
                            }
                        }
                        else
                        {
                            //the first condition
                            Behaviac.Design.Nodes.Node notNode = null;
                            if (bIsSeqSel)
                            {
                                //for sequence/selector, it is reverted
                                Type notType = Plugin.GetType("PluginBehaviac.Nodes.DecoratorNot");

                                notNode = Behaviac.Design.Nodes.Node.Create(notType);
                                node.AddChild(BaseNode.Connector.kInterupt, notNode);
                                notNode.AddChild(BaseNode.Connector.kGeneric, newNode);
                            }
                            else
                            {
                                node.AddChild(BaseNode.Connector.kInterupt, newNode);
                            }
                        }

                        // initialise the attachments properties
                        IList<DesignerPropertyInfo> lp = newNode.GetDesignerProperties();
                        for (int p = 0; p < lp.Count; ++p)
                        {
                            if (lp[p].Property.Name == "Opl")
                            {
                                lp[p].Property.SetValue(newNode, opl, null);
                            }
                            else if (lp[p].Property.Name == "Opr")
                            {
                                lp[p].Property.SetValue(newNode, opr, null);
                            }
                            else if (lp[p].Property.Name == "Operator")
                            {
                                lp[p].Property.SetValue(newNode, oprr, null);
                            }
                        }

                        // update attacheent with attributes
                        newNode.OnPropertyValueChanged(false);
                    }
                    else if (clss == "PluginBehaviac.Nodes.Action")
                    {
                        Type newType = Plugin.GetType("PluginBehaviac.Events.Precondition");

                        Behaviac.Design.Attachments.Attachment newNode = Behaviac.Design.Attachments.Attachment.Create(newType, node);
                        node.AddAttachment(newNode);
                        node.RemoveAttachment(a);
                        node.Behavior.TriggerWasModified(node);

                        // initialise the attachments properties
                        IList<DesignerPropertyInfo> lp = newNode.GetDesignerProperties();
                        for (int p = 0; p < lp.Count; ++p)
                        {
                            if (lp[p].Property.Name == "BinaryOperator")
                            {
                                lp[p].Property.SetValue(newNode, binaryOpr, null);
                            }
                            else if (lp[p].Property.Name == "Opl")
                            {
                                lp[p].Property.SetValue(newNode, opl, null);
                            }
                            else if (lp[p].Property.Name == "Opr2")
                            {
                                lp[p].Property.SetValue(newNode, opr, null);
                            }
                            else if (lp[p].Property.Name == "Operator")
                            {
                                lp[p].Property.SetValue(newNode, oprType, null);
                            }
                            else if (lp[p].Property.Name == "IsAlive")
                            {
                                lp[p].SetValueFromString(result, newNode, "true");
                            }
                        }

                        // update attacheent with attributes
                        newNode.OnPropertyValueChanged(false);
                    }
                    else
                    {
                        Debug.Check(false);
                    }
                }
            } // if (version <= 1)
        }