예제 #1
0
        public override bool AcceptsAttachment(DefaultObject obj)
        {
            Type type = (obj != null) ? obj.GetType() : null;

            return(type != null && ((this.IsFSM && Plugin.IsClassDerived(type, typeof(Behaviac.Design.Attachments.AttachAction))) ||  //if fsm, only accept effectors
                                    (!Plugin.IsClassDerived(type, typeof(Behaviac.Design.Attachments.AttachAction)) &&
                                     !Plugin.IsClassDerived(type, typeof(Behaviac.Design.Attachments.Event)) &&
                                     !Plugin.IsClassDerived(type, typeof(Behaviac.Design.Nodes.Behavior)))));
        }
예제 #2
0
        protected VariableDef parseConstVar(List<Nodes.Node.ErrorCheck> result, DefaultObject node, object parentObject, string str)
        {
            Debug.Check(str.StartsWith("const"));

            //const Int32 1
            object propertyMemberDepended = null;
            Type objType = node.GetType();

            if (this.DependedProperty != "") {
                System.Reflection.PropertyInfo pi = objType.GetProperty(this.DependedProperty);

                if (pi != null) {
                    propertyMemberDepended = pi.GetValue(node, null);

                } else if (pi == null && parentObject != null) {
                    Type parentType = parentObject.GetType();
                    pi = parentType.GetProperty(this.DependedProperty);
                    propertyMemberDepended = pi.GetValue(parentObject, null);
                }
            }

            Type valueType = null;
            VariableDef variableDepended = propertyMemberDepended as VariableDef;

            if (variableDepended != null) {
                valueType = variableDepended.GetValueType();

            } else if (propertyMemberDepended != null) {
                MethodDef methodDepended = propertyMemberDepended as MethodDef;

                if (methodDepended != null) {
                    valueType = methodDepended.ReturnType;

                } else {
                    RightValueDef varRV = propertyMemberDepended as RightValueDef;

                    if (varRV != null) {
                        valueType = varRV.ValueType;
                    }
                }

            } else {
                string[] tokens = str.Split(' ');
                Debug.Check(tokens.Length >= 3);

                valueType = Plugin.GetTypeFromName(tokens[1]);
            }

            if (valueType != null) {
                VariableDef variable = new VariableDef(null);

                //string[] tokens = str.Split(' ');
                //Debug.Check(tokens.Length == 3);
                Debug.Check(str.StartsWith("const"));
                //skip 'const '
                int pos = str.IndexOf(' ');
                Debug.Check(pos != -1);
                pos = str.IndexOf(' ', pos + 1);
                string token = str.Substring(pos + 1);

                Plugin.InvokeTypeParser(result, valueType, token,
                                        (object value) => variable.Value = value,
                                        node);

                return variable;
            }

            return null;
        }
예제 #3
0
파일: Plugin.cs 프로젝트: wuzhen/behaviac
        private static void checkPar(DefaultObject obj, ParInfo par, ref List<Node.ErrorCheck> result)
        {
            Node node = getNode(obj);

            if (node != null && par != null) {
                Type type = obj.GetType();
                foreach(PropertyInfo property in type.GetProperties()) {
                    try {
                        object value = property.GetValue(obj, null);

                        if (value != null) {
                            if (property.PropertyType == typeof(MethodDef)) {
                                MethodDef method = value as MethodDef;
                                Debug.Check(method != null);

                                if (method.CheckPar(par))
                                { result.Add(new Node.ErrorCheck(node, ErrorCheckLevel.Error, "Par as a parameter of the method.")); }

                            } else if (property.PropertyType == typeof(VariableDef)) {
                                VariableDef var = value as VariableDef;
                                Debug.Check(var != null);

                                if (var.CheckPar(par))
                                { result.Add(new Node.ErrorCheck(node, ErrorCheckLevel.Error, "Par as a value.")); }

                            } else if (property.PropertyType == typeof(RightValueDef)) {
                                RightValueDef rv = value as RightValueDef;
                                Debug.Check(rv != null);

                                if (rv.CheckPar(par))
                                { result.Add(new Node.ErrorCheck(node, ErrorCheckLevel.Error, "Par as a right value.")); }
                            }
                        }

                    } catch {
                    }
                }
            }
        }
예제 #4
0
파일: Plugin.cs 프로젝트: wuzhen/behaviac
        public static void GetObjectsBySelfPropertyMethod(Nodes.Node root, DefaultObject obj, string propertyName, bool matchCase, bool matchWholeWord, ref List<ObjectPair> objects)
        {
            if (root == null || string.IsNullOrEmpty(propertyName))
            { return; }

            if (!ContainObjectPair(objects, root, obj)) {
                bool found = false;

                // search from its members
                Type type = obj.GetType();
                foreach(System.Reflection.PropertyInfo property in type.GetProperties()) {
                    Attribute[] attributes = (Attribute[])property.GetCustomAttributes(typeof(Behaviac.Design.Attributes.DesignerProperty), false);

                    if (attributes == null || attributes.Length == 0) {
                        continue;
                    }

                    try {
                        object value = property.GetValue(obj, null);

                        if (value != null) {
                            if (property.PropertyType == typeof(MethodDef)) {
                                MethodDef method = value as MethodDef;
                                Debug.Check(method != null);

                                if (CompareTwoTypes(method.Name, propertyName, matchCase, matchWholeWord) ||
                                    CompareTwoTypes(method.DisplayName, propertyName, matchCase, matchWholeWord) ||
                                    CompareTwoTypes(method.GetDisplayValue(), propertyName, matchCase, matchWholeWord) ||
                                    CompareTwoTypes(method.GetExportValue(), propertyName, matchCase, matchWholeWord)) {
                                    found = true;
                                    break;
                                }

                            } else if (property.PropertyType == typeof(VariableDef)) {
                                VariableDef var = value as VariableDef;
                                Debug.Check(var != null);

                                if (CompareTwoTypes(var.GetDisplayValue(), propertyName, matchCase, matchWholeWord) ||
                                    CompareTwoTypes(var.GetExportValue(), propertyName, matchCase, matchWholeWord)) {
                                    found = true;
                                    break;
                                }

                            } else if (property.PropertyType == typeof(RightValueDef)) {
                                RightValueDef rv = value as RightValueDef;
                                Debug.Check(rv != null);

                                if (CompareTwoTypes(rv.GetDisplayValue(), propertyName, matchCase, matchWholeWord) ||
                                    CompareTwoTypes(rv.GetExportValue(), propertyName, matchCase, matchWholeWord)) {
                                    found = true;
                                    break;
                                }

                            } else if (CompareTwoTypes(value.ToString(), propertyName, matchCase, matchWholeWord)) {
                                found = true;
                                break;
                            }
                        }

                    } catch (Exception) {
                    }
                }

                // search from its pars
                if (!found) {
                    if (obj is Behavior) {
                        foreach(ParInfo par in((Behavior)obj).LocalVars) {
                            if (CompareTwoTypes(par.Name, propertyName, matchCase, matchWholeWord)) {
                                found = true;
                                break;
                            }
                        }
                    }
                }

                if (found) {
                    objects.Add(new ObjectPair(root, obj));
                }
            }
        }
예제 #5
0
        protected VariableDef parseConstVar(List <Nodes.Node.ErrorCheck> result, DefaultObject node, object parentObject, string str)
        {
            Debug.Check(str.StartsWith("const"));

            //const Int32 1
            object propertyMemberDepended = null;
            Type   objType = node.GetType();

            if (this.DependedProperty != "")
            {
                System.Reflection.PropertyInfo pi = objType.GetProperty(this.DependedProperty);

                if (pi != null)
                {
                    propertyMemberDepended = pi.GetValue(node, null);
                }
                else if (pi == null && parentObject != null)
                {
                    Type parentType = parentObject.GetType();
                    pi = parentType.GetProperty(this.DependedProperty);
                    propertyMemberDepended = pi.GetValue(parentObject, null);
                }
            }

            Type        valueType        = null;
            VariableDef variableDepended = propertyMemberDepended as VariableDef;

            if (variableDepended != null)
            {
                valueType = variableDepended.GetValueType();
            }
            else if (propertyMemberDepended != null)
            {
                MethodDef methodDepended = propertyMemberDepended as MethodDef;

                if (methodDepended != null)
                {
                    valueType = methodDepended.ReturnType;
                }
                else
                {
                    RightValueDef varRV = propertyMemberDepended as RightValueDef;

                    if (varRV != null)
                    {
                        valueType = varRV.ValueType;
                    }
                }
            }
            else
            {
                string[] tokens = str.Split(' ');
                Debug.Check(tokens.Length >= 3);

                valueType = Plugin.GetTypeFromName(tokens[1]);
            }

            if (valueType != null)
            {
                VariableDef variable = new VariableDef(null);

                //string[] tokens = str.Split(' ');
                //Debug.Check(tokens.Length == 3);
                Debug.Check(str.StartsWith("const"));
                //skip 'const '
                int pos = str.IndexOf(' ');
                Debug.Check(pos != -1);
                pos = str.IndexOf(' ', pos + 1);
                string token = str.Substring(pos + 1);

                Plugin.InvokeTypeParser(result, valueType, token,
                                        (object value) => variable.Value = value,
                                        node);

                return(variable);
            }

            return(null);
        }
예제 #6
0
 public override bool AcceptsAttachment(DefaultObject obj)
 {
     Type type = (obj != null) ? obj.GetType() : null;
     return type != null && ((this.IsFSM && Plugin.IsClassDerived(type, typeof(Behaviac.Design.Attachments.AttachAction))) ||  //if fsm, only accept effectors
                             (!Plugin.IsClassDerived(type, typeof(Behaviac.Design.Attachments.AttachAction)) &&
                              !Plugin.IsClassDerived(type, typeof(Behaviac.Design.Attachments.Event)) &&
                              !Plugin.IsClassDerived(type, typeof(Behaviac.Design.Nodes.Behavior))));
 }