Ejemplo n.º 1
0
        public string GetDisplayValue()
        {
            string str = string.Empty;

            if (_valueClass == kConst)
            {
                if (_value != null)
                {
                    str = DesignerPropertyUtility.RetrieveDisplayValue(_value, null, null);
                }
            }
            else if (_valueClass == kPar)
            {
                if (_value != null)
                {
                    str = DesignerPropertyUtility.RetrieveDisplayValue(_value, null, null);
                }
            }
            else if (_property != null)
            {
                str = DesignerPropertyUtility.RetrieveDisplayValue(_property, null, null);
            }

            return(str);
        }
Ejemplo n.º 2
0
        public string GetExportValue()
        {
            string str = string.Empty;

            if (_valueClass == kConst)
            {
                if (_value != null)
                {
                    str = string.Format("const {0} {1}", Plugin.GetNativeTypeName(_value.GetType()), DesignerPropertyUtility.RetrieveExportValue(_value, null, null));
                }
            }
            else if (_valueClass == kPar)
            {
                if (_value != null)
                {
                    str = DesignerPropertyUtility.RetrieveExportValue(_value, null, null);
                }
            }
            else if (_property != null)
            {
                str = string.Format("{0} {1}", Plugin.GetNativeTypeName(_property.Type), DesignerPropertyUtility.RetrieveExportValue(_property, null, null));
                if (_property.IsStatic)
                {
                    str = str.Insert(0, "static ");
                }
            }

            return(str);
        }
Ejemplo n.º 3
0
        public static string GetGeneratedDefaultValue(Type type, string typename, string defaultValue = null)
        {
            if (type == typeof(void))
            {
                return(null);
            }

            string value = defaultValue;

            if (string.IsNullOrEmpty(defaultValue))
            {
                if (!Plugin.IsStringType(type))
                {
                    value = DesignerPropertyUtility.RetrieveExportValue(Plugin.DefaultValue(type));
                }
                else
                {
                    value = "";
                }
            }

            if (type == typeof(char))
            {
                value = "(char)0";
            }
            else if (type == typeof(float))
            {
                if (!string.IsNullOrEmpty(value) && !value.ToLowerInvariant().EndsWith("f"))
                {
                    value += "f";
                }
            }
            else if (Plugin.IsStringType(type))
            {
                value = "\"" + value + "\"";
            }
            else if (Plugin.IsEnumType(type))
            {
                value = string.Format("{0}.{1}", typename, value);
            }
            else if (Plugin.IsArrayType(type))
            {
                value = "null";
            }
            else if (Plugin.IsCustomClassType(type))
            {
                if (Plugin.IsRefType(type))
                {
                    value = "null";
                }
                else
                {
                    value = "new " + typename + "()";
                }
            }

            return(value);
        }
Ejemplo n.º 4
0
        public string GetRawValue()
        {
            if (_valueClass == kConst && _value != null)
            {
                return(DesignerPropertyUtility.RetrieveExportValue(_value, null, null));
            }

            return(GetDisplayValue());
        }
Ejemplo n.º 5
0
        protected override void GenerateConstructor(Node node, StreamWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            Query query = node as Query;

            Debug.Check(query != null);

            stream.WriteLine("{0}\t\t\tthis->Initialize(\"{1}\", \"{2}\");",
                             indent, query.Domain, DesignerPropertyUtility.RetrieveExportValue(query.Descriptors));
        }
Ejemplo n.º 6
0
        private void LoadDescriptorRefs(List <Nodes.Node.ErrorCheck> result, XmlNode xmlNode, Behavior b)
        {
            b.DescriptorRefs.Clear();

            if (xmlNode != null)
            {
                Type   type        = b.DescriptorRefs.GetType();
                string valueString = xmlNode.Attributes["value"].Value;

                b.DescriptorRefs = (List <Behavior.DescriptorRef>)DesignerPropertyUtility.ParseStringValue(result, type, valueString, b);
            }
        }
Ejemplo n.º 7
0
        public string GetExportValue()
        {
            if (m_var != null)
            {
                return(DesignerPropertyUtility.RetrieveExportValue(m_var, null, null));
            }

            if (m_method != null)
            {
                return(DesignerPropertyUtility.RetrieveExportValue(m_method, null, null));
            }

            return(string.Empty);
        }
Ejemplo n.º 8
0
        public static string GetGeneratedDefaultValue(Type type, string typename, string defaultValue = null)
        {
            if (type == typeof(void))
            {
                return(null);
            }

            string value = (defaultValue == null) ? DesignerPropertyUtility.RetrieveExportValue(Plugin.DefaultValue(type)) : defaultValue;

            if (type == typeof(char))
            {
                value = "(char)0";
            }
            else if (Plugin.IsStringType(type))
            {
                if (typename.EndsWith("char*"))
                {
                    value = "NULL";
                }
                else
                {
                    value = "\"" + value + "\"";
                }
            }
            else if (Plugin.IsEnumType(type))
            {
                value = string.Format("{0}::{1}", typename, value);
            }
            else if (Plugin.IsArrayType(type))
            {
                value = null;
            }
            else if (Plugin.IsCustomClassType(type))
            {
                if (Plugin.IsRefType(type) || typename.EndsWith("*"))
                {
                    value = "NULL";
                }
                else
                {
                    value = null;
                }
            }

            return(value);
        }
Ejemplo n.º 9
0
        private string getStringValue(bool isDisplay)
        {
#if USE_NOOP
            if (MethodDef != MethodDef.Noop)
#endif
            {
                string str = null;
                if (isDisplay)
                {
                    if (this.Owner != VariableDef.kSelf)
                    {
                        str = Plugin.GetInstanceDisplayName(this.Owner) + "." + this.DisplayName;
                    }
                    else
                    {
                        str = this.DisplayName;
                    }
                }
                else
                {
                    str = this.Owner + "." + this.Name;
                }

                str += "(";

                for (int i = 0; i < this.Params.Count; ++i)
                {
                    if (i > 0)
                    {
                        str += ",";
                    }

                    object para = this.Params[i].Value;
                    str += isDisplay ? DesignerPropertyUtility.RetrieveDisplayValue(para, this, this.Params[i].Name) : DesignerPropertyUtility.RetrieveExportValue(para, this, this.Params[i].Name);
                }
                str += ")";

                return(str);
            }
#if USE_NOOP
            return(string.Empty);
#endif
        }
Ejemplo n.º 10
0
        public static string GetGeneratedDefaultValue(Type type, string typename)
        {
            string value = DesignerPropertyUtility.RetrieveExportValue(Plugin.DefaultValue(type));

            if (type == typeof(char))
            {
                value = "(char)0";
            }
            else if (Plugin.IsEnumType(type))
            {
                value = string.Format("{0}.{1}", typename, value);
            }
            else if (Plugin.IsArrayType(type))
            {
                value = "new " + typename + "()";
            }
            else if (Plugin.IsCustomClassType(type))
            {
                value = "new " + typename + "()";
            }

            return(value);
        }
Ejemplo n.º 11
0
        private void ExportBody(StreamWriter file, BehaviorNode behavior)
        {
            string filename = Path.ChangeExtension(behavior.RelativePath, "").Replace(".", "");

            filename = filename.Replace('\\', '/');

            // write comments
            file.WriteLine("\t// Source file: {0}\r\n", filename);

            string btClassName = string.Format("bt_{0}", filename.Replace('/', '_'));
            string agentType   = behavior.AgentType.AgentTypeName;

            // create the class definition of its attachments
            ExportAttachmentClass(file, btClassName, (Node)behavior);

            // create the class definition of its children
            foreach (Node child in ((Node)behavior).Children)
            {
                ExportNodeClass(file, btClassName, agentType, behavior, child);
            }

            // create the bt class
            file.WriteLine("\tpublic static class {0}\r\n\t{{", btClassName);

            // export the build function
            file.WriteLine("\t\tpublic static bool build_behavior_tree(BehaviorTree bt)\r\n\t\t{");
            file.WriteLine("\t\t\tbt.SetClassNameString(\"BehaviorTree\");");
            file.WriteLine("\t\t\tbt.SetId(-1);");
            file.WriteLine("\t\t\tbt.SetName(\"{0}\");", filename);
            file.WriteLine("#if !BEHAVIAC_RELEASE");
            file.WriteLine("\t\t\tbt.SetAgentType(\"{0}\");", agentType.Replace("::", "."));
            file.WriteLine("#endif");
            if (!string.IsNullOrEmpty(((Behavior)behavior).Domains))
            {
                file.WriteLine("\t\t\tbt.SetDomains(\"{0}\");", ((Behavior)behavior).Domains);
            }
            if (((Behavior)behavior).DescriptorRefs.Count > 0)
            {
                file.WriteLine("\t\t\tbt.SetDescriptors(\"{0}\");", DesignerPropertyUtility.RetrieveExportValue(((Behavior)behavior).DescriptorRefs));
            }

            ExportPars(file, "bt", (Node)behavior, "\t\t");

            // export its attachments
            ExportAttachment(file, btClassName, agentType, "bt", (Node)behavior, "\t\t\t");

            file.WriteLine("\t\t\t// children");

            // export its children
            foreach (Node child in ((Node)behavior).Children)
            {
                ExportNode(file, btClassName, agentType, "bt", child, 3);
            }

            file.WriteLine("\t\t\treturn true;");

            // close the build function
            file.WriteLine("\t\t}");

            // close class
            file.WriteLine("\t}\r\n");
        }
Ejemplo n.º 12
0
        public static string GetGeneratedDefaultValue(Type type, string typename, string defaultValue = null)
        {
            if (type == typeof(void))
            {
                return(null);
            }

            string value = defaultValue;

            if (string.IsNullOrEmpty(defaultValue))
            {
                if (!Plugin.IsStringType(type))
                {
                    value = DesignerPropertyUtility.RetrieveExportValue(Plugin.DefaultValue(type));
                }
                else
                {
                    value = "";
                }
            }

            if (type == typeof(char))
            {
                value = "(char)0";
            }
            else if (Plugin.IsStringType(type))
            {
                if (typename.EndsWith("char*"))
                {
                    value = "NULL";
                }
                else
                {
                    value = "\"" + value + "\"";
                }
            }
            else if (Plugin.IsEnumType(type))
            {
                // remove the enum name
                int index = typename.LastIndexOf("::");
                if (index >= 0)
                {
                    typename = typename.Substring(0, index);
                    value    = string.Format("{0}::{1}", typename, value);
                }
            }
            else if (Plugin.IsArrayType(type))
            {
                value = null;
            }
            else if (Plugin.IsCustomClassType(type))
            {
                if (Plugin.IsRefType(type) || typename.EndsWith("*"))
                {
                    value = "NULL";
                }
                else
                {
                    value = null;
                }
            }

            return(value);
        }
Ejemplo n.º 13
0
        private void ExportBody(StreamWriter file, BehaviorNode behavior)
        {
            string filename = Path.ChangeExtension(behavior.RelativePath, "").Replace(".", "");

            filename = filename.Replace('\\', '/');

            // write comments
            file.WriteLine("\t// Source file: {0}\r\n", filename);

            string btClassName = string.Format("bt_{0}", filename.Replace('/', '_'));
            string agentType   = behavior.AgentType.AgentTypeName;

            // create the class definition of its attachments
            ExportAttachmentClass(file, btClassName, (Node)behavior);

            // create the class definition of its children
            foreach (Node child in ((Node)behavior).Children)
            {
                ExportNodeClass(file, btClassName, agentType, behavior, child);
            }

            // export the create function
            file.WriteLine("\tBEHAVIAC_API bool Create_{0}(BehaviorTree* pBT)\r\n\t{{", btClassName);

            file.WriteLine("\t\tpBT->SetClassNameString(\"BehaviorTree\");");
            file.WriteLine("\t\tpBT->SetId(-1);");
            file.WriteLine("\t\tpBT->SetName(\"{0}\");", filename);
            file.WriteLine("#if !defined(BEHAVIAC_RELEASE)");
            file.WriteLine("\t\tpBT->SetAgentType(\"{0}\");", agentType);
            file.WriteLine("#endif");
            if (!string.IsNullOrEmpty(((Behavior)behavior).Domains))
            {
                file.WriteLine("\t\tpBT->SetDomains(\"{0}\");", ((Behavior)behavior).Domains);
            }
            if (((Behavior)behavior).DescriptorRefs.Count > 0)
            {
                file.WriteLine("\t\tpBT->SetDescriptors(\"{0}\");", DesignerPropertyUtility.RetrieveExportValue(((Behavior)behavior).DescriptorRefs));
            }

            ExportPars(file, "pBT", (Node)behavior, "\t");

            // export its attachments
            ExportAttachment(file, btClassName, agentType, "pBT", (Node)behavior, "\t\t");

            file.WriteLine("\t\t// children");

            // export its children
            foreach (Node child in ((Node)behavior).Children)
            {
                ExportNode(file, btClassName, agentType, "pBT", child, 2);
            }

            file.WriteLine("\t\treturn true;");
            file.WriteLine("\t}\r\n");

            // export the register class and its instance
            file.WriteLine("\tstruct Register_{0}\r\n\t{{", btClassName);
            file.WriteLine("\t\tRegister_{0}()\r\n\t\t{{", btClassName);
            file.WriteLine("\t\t\tWorkspace::RegisterBehaviorTreeCreator(\"{0}\", Create_{1});", filename, btClassName);
            file.WriteLine("\t\t}\r\n\t};\r\n");

            file.WriteLine("\tstatic Register_{0} register_{0};\n", btClassName);
        }