Example #1
0
        public void TestOverriddenAttributeInfo()
        {
            AttributeInfo info = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            DomNodeType   test = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { info },
                EmptyEnumerable <ChildInfo> .Instance,
                EmptyEnumerable <ExtensionInfo> .Instance);

            AttributeInfo overridden = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            DomNodeType   child      = new DomNodeType("child", test,
                                                       new AttributeInfo[] { overridden },
                                                       EmptyEnumerable <ChildInfo> .Instance,
                                                       EmptyEnumerable <ExtensionInfo> .Instance);

            Assert.AreSame(child.GetAttributeInfo("foo"), overridden);
            Assert.AreEqual(overridden.OwningType, child);
            Assert.AreEqual(overridden.DefiningType, test);

            Assert.True(info.Equivalent(overridden));
            Assert.True(overridden.Equivalent(info));

            Assert.True(test.IsValid(overridden));
            Assert.True(child.IsValid(info));
        }
Example #2
0
        private static void GenerateAttributeDefault(DomNodeType nodeType, string typeName, XmlNode tag, StringBuilder sb)
        {
            var attrName = GetXmlAttribute(tag, "name");

            if (attrName == null)
            {
                return;
            }

            AttributeInfo attribute = nodeType.GetAttributeInfo(attrName);

            if (attribute == null)
            {
                return;
            }

            var attrValue = GetXmlAttribute(tag, "default");

            if (attrValue != null)
            {
                if (attribute.Type.ClrType == typeof(string))
                {
                    WriteLine(sb, "            {0}.{1}Attribute.DefaultValue = \"{2}\".Localize();", typeName, attribute.Name, attrValue);
                }
                else
                {
                    WriteLine(sb, "            {0}.{1}Attribute.DefaultValue = {2};", typeName, attribute.Name, attrValue);
                }
            }
        }
Example #3
0
        public void TestCustomAttributeInfo()
        {
            AttributeInfo info = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            DomNodeType   test = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { info },
                EmptyEnumerable <ChildInfo> .Instance,
                EmptyEnumerable <ExtensionInfo> .Instance);

            Utilities.TestSequenceEqual(test.Attributes, info);
            Assert.True(test.IsValid(info));
            Assert.AreSame(test.GetAttributeInfo("foo"), info);
            // check that type is now frozen
            Assert.Throws <InvalidOperationException>(delegate { test.Define(GetStringAttribute("notFoo")); });

            Assert.AreEqual(info.OwningType, test);
            Assert.AreEqual(info.DefiningType, test);
            Assert.Null(test.GetAttributeInfo("bar"));
        }
Example #4
0
        string _ExportScene(DomNode root)
        {
            StringBuilder txt = new StringBuilder();

            foreach (DomNode node in root.Subtree)
            {
                DomNodeType type = node.Type;
                if (!bitBoxSchema.nodeType.Type.IsAssignableFrom(type))
                {
                    continue;
                }

                AttributeInfo attr_nodeName = type.GetAttributeInfo("name");
                if (attr_nodeName == null)
                {
                    continue;
                }

                string typeName = type.Name.Split(':').Last(); //.Replace("Node", "");
                string nodeName = (string)node.GetAttribute(attr_nodeName);

                txt.AppendLine();
                txt.AppendLine("@" + typeName + " " + nodeName);

                foreach (AttributeInfo ainfo in type.Attributes)
                {
                    if (ainfo.Name == "name")
                    {
                        continue;
                    }

                    object value = node.GetAttribute(ainfo);
                    if (!value.Equals(ainfo.DefaultValue))
                    {
                        string valueAsSting = "";
                        if (value is string)
                        {
                            valueAsSting = "\"" + (string)value + "\"";
                        }
                        else
                        {
                            valueAsSting = ainfo.Type.Convert(value);
                        }
                        txt.AppendLine("$" + ainfo.Name + " " + valueAsSting);
                    }
                }
            }

            return(txt.ToString());
        }
Example #5
0
        private static void GeneratePaletteTag(DomNodeType nodeType, string typeName, XmlNode tag, StringBuilder sb)
        {
            var    attrCategory = tag.Attributes["category"];
            string strCategory  = null;

            if (attrCategory != null)
            {
                strCategory = attrCategory.Value;
            }

            var attrDisplayName = tag.Attributes["displayName"];

            if (attrDisplayName == null || attrDisplayName.Value == null)
            {
                return;
            }
            string displayName = attrDisplayName.Value;

            if (string.IsNullOrEmpty(displayName))
            {
                displayName = typeName;
            }

            var attrIcon = tag.Attributes["icon"];

            if (attrIcon == null || attrIcon.Value == null)
            {
                return;
            }

            string        paletteName = typeName;
            AttributeInfo attribute   = nodeType.GetAttributeInfo("name");

            if (attribute != null && attribute.Type.ClrType == typeof(string) && !string.IsNullOrEmpty((string)attribute.DefaultValue))
            {
                paletteName = (string)attribute.DefaultValue;
            }

            if (string.IsNullOrEmpty(strCategory))
            {
                WriteLine(sb, "            {0}.Type.SetTag(new NodeTypePaletteItem({0}.Type, \"{1}\", \"{2}\".Localize(), {3}));",
                          typeName, paletteName, displayName, attrIcon.Value);
            }
            else
            {
                WriteLine(sb, "            {0}.Type.SetTag(new NodeTypePaletteItem({0}.Type, \"{1}\", \"{2}\".Localize(), {3}, {4}. {5}));",
                          typeName, paletteName, displayName, attrIcon.Value, strCategory, paletteName);
            }
        }
Example #6
0
        public void TestInheritedAttributeInfo()
        {
            AttributeInfo info = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            DomNodeType   test = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { info },
                EmptyEnumerable <ChildInfo> .Instance,
                EmptyEnumerable <ExtensionInfo> .Instance);

            DomNodeType child = new DomNodeType("child");

            child.BaseType = test;

            AttributeInfo inherited = child.GetAttributeInfo("foo");

            Assert.AreEqual(inherited.OwningType, test);
            Assert.AreEqual(inherited.DefiningType, test);

            Assert.True(inherited.Equivalent(info));
            Assert.True(info.Equivalent(inherited));
        }
Example #7
0
        public void Test()
        {
            XmlSchemaTypeLoader loader = new XmlSchemaTypeLoader();

            loader.SchemaResolver = new ResourceStreamResolver(
                Assembly.GetExecutingAssembly(),
                "UnitTests.Atf/Resources");
            loader.Load("testComplexTypes.xsd");

            DomNodeType abstractType = loader.GetNodeType("test:abstractType");

            Assert.IsTrue(abstractType != null);
            Assert.IsTrue(abstractType.IsAbstract);

            DomNodeType complexType1 = loader.GetNodeType("test:complexType1");

            Assert.IsTrue(complexType1 != null);
            Assert.IsTrue(!complexType1.IsAbstract);
            Assert.IsTrue(complexType1.BaseType == abstractType);
            //Assert.IsTrue(complexType1.FindAnnotation("annotation") != null);
            //Assert.IsTrue(complexType1.FindAnnotation("annotation", "attr1") != null);

            DomNodeType complexType2 = loader.GetNodeType("test:complexType2");

            Assert.IsTrue(complexType2 != null);
            Assert.IsTrue(!complexType2.IsAbstract);
            AttributeInfo attr1 = complexType2.GetAttributeInfo("attr1");

            Assert.IsTrue(attr1 != null);
            Assert.IsTrue(attr1.DefaultValue.Equals(1));
            //Assert.IsTrue(attr1.FindAnnotation("annotation") != null);
            AttributeInfo attr2 = complexType2.GetAttributeInfo("attr2");

            Assert.IsTrue(attr2 != null);
            Assert.IsTrue(attr2.DefaultValue.Equals(2));

            DomNodeType complexType3 = loader.GetNodeType("test:complexType3");

            Assert.IsTrue(complexType3 != null);
            Assert.IsTrue(!complexType3.IsAbstract);
            Assert.IsTrue(complexType3.BaseType == complexType2);
            AttributeInfo attr3 = complexType3.GetAttributeInfo("attr3");

            Assert.IsTrue(attr3 != null);
            ChildInfo elem1 = complexType3.GetChildInfo("elem1");

            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == complexType1);
            //Assert.IsTrue(elem1.FindAnnotation("annotation") != null);
            ChildInfo elem2 = complexType3.GetChildInfo("elem2");

            Assert.IsTrue(elem2 != null);
            Assert.IsTrue(elem2.Type == complexType1);
            Assert.IsTrue(MinMaxCheck(elem2, 1, 3));
            ChildInfo elem3 = complexType3.GetChildInfo("elem3");

            Assert.IsTrue(elem3 != null); //because a sequence of simple types becomes a sequence of child DomNodes
            attr3 = complexType3.GetAttributeInfo("elem3");
            Assert.IsTrue(attr3 == null); //because a sequence of simple types becomes a sequence of child DomNodes
            DomNode       node3                   = new DomNode(complexType3);
            DomNode       elem3Child1             = new DomNode(elem3.Type);
            AttributeInfo elem3ValueAttributeInfo = elem3.Type.GetAttributeInfo(string.Empty);

            elem3Child1.SetAttribute(elem3ValueAttributeInfo, 1);
            DomNode elem3Child2 = new DomNode(elem3.Type);

            elem3Child2.SetAttribute(elem3ValueAttributeInfo, 1);
            DomNode elem3Child3 = new DomNode(elem3.Type);

            elem3Child3.SetAttribute(elem3ValueAttributeInfo, 1);
            node3.GetChildList(elem3).Add(elem3Child1);
            node3.GetChildList(elem3).Add(elem3Child2);
            node3.GetChildList(elem3).Add(elem3Child3);

            IList <DomNode> node3Children = node3.GetChildList(elem3);

            Assert.IsTrue((int)node3Children[0].GetAttribute(elem3ValueAttributeInfo) == 1);
            Assert.IsTrue((int)node3Children[1].GetAttribute(elem3ValueAttributeInfo) == 1);
            Assert.IsTrue((int)node3Children[2].GetAttribute(elem3ValueAttributeInfo) == 1);

            // Update on 8/16/2011. DomXmlReader would not be able to handle a sequence of elements
            //  of a simple type like this. When reading, each subsequent element's value would be
            //  used to set the attribute on the DomNode, overwriting the previous one. So, since
            //  this behavior of converting more than one element of a simple type into an attribute
            //  array was broken, I want to change this unit test that I wrote and make sequences of
            //  elements of simple types into a sequence of DomNode children with a value attribute.
            //  (A value attribute means an attribute whose name is "".) --Ron
            //ChildInfo elem3 = complexType3.GetChildInfo("elem3");
            //Assert.IsTrue(elem3 == null); //because a sequence of simple types becomes an attribute
            //attr3 = complexType3.GetAttributeInfo("elem3");
            //Assert.IsTrue(attr3 != null); //because a sequence of simple types becomes an attribute
            //DomNode node3 = new DomNode(complexType3);
            //object attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int &&
            //    (int)attr3Obj == 0); //the default integer
            //node3.SetAttribute(attr3, 1);
            //attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int &&
            //    (int)attr3Obj == 1);
            //node3.SetAttribute(attr3, new int[] { 1, 2, 3 });
            //attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int[] &&
            //    ((int[])attr3Obj)[2]==3);

            DomNodeType complexType4 = loader.GetNodeType("test:complexType4");

            Assert.IsTrue(complexType4 != null);
            Assert.IsTrue(!complexType4.IsAbstract);
            attr1 = complexType4.GetAttributeInfo("attr1");
            Assert.IsTrue(attr1 != null);
            elem1 = complexType4.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == complexType3);
            Assert.IsTrue(MinMaxCheck(elem1, 1, 1));

            DomNodeType complexType5 = loader.GetNodeType("test:complexType5");

            Assert.IsTrue(complexType5 != null);
            Assert.IsTrue(!complexType5.IsAbstract);
            elem1 = complexType5.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == abstractType);
            Assert.IsTrue(MinMaxCheck(elem1, 1, Int32.MaxValue));

            DomNode node5 = new DomNode(complexType5);

            elem2 = complexType5.GetChildInfo("elem2");
            DomNode node2 = new DomNode(complexType2);

            node5.SetChild(elem2, node2);
            node5.SetChild(elem2, null);
            node3 = new DomNode(complexType3);
            elem3 = complexType5.GetChildInfo("elem3");
            node5.SetChild(elem3, node3);
            //The following should violate xs:choice, but we don't fully support this checking yet.
            //ExceptionTester.CheckThrow<InvalidOperationException>(delegate { node5.AddChild(elem2, node2); });

            DomNodeType complexType6 = loader.GetNodeType("test:complexType6");

            Assert.IsTrue(complexType6 != null);
            Assert.IsTrue(!complexType6.IsAbstract);
            elem1 = complexType6.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == abstractType);
            Assert.IsTrue(MinMaxCheck(elem1, 1, Int32.MaxValue));
            elem2 = complexType6.GetChildInfo("elem2");
            Assert.IsTrue(elem2 != null);
            Assert.IsTrue(elem2.Type == complexType2);
            Assert.IsTrue(MinMaxCheck(elem2, 1, Int32.MaxValue));

            //DomNodeType complexType7 = loader.GetNodeType("test:complexType7");
            //Assert.IsTrue(complexType7 != null);
            //Assert.IsTrue(!complexType7.IsAbstract);
            //AttributeInfo attrSimpleSequence = complexType7.GetAttributeInfo("elemSimpleSequence");
            //Assert.IsTrue(attrSimpleSequence == null); //because a sequence of simple types becomes a sequence of child DomNodes
            //ChildInfo elemSimpleSequence = complexType7.GetChildInfo("elemSimpleSequence");
            //Assert.IsTrue(elemSimpleSequence != null); //because a sequence of simple types becomes a sequence of child DomNodes
            //DomNode node7 = new DomNode(complexType7);
            //object attrObj7 = node7.GetAttribute(attrSimpleSequence);
            //Assert.IsTrue(
            //    attrObj7 is float[] &&
            //    ((float[])attrObj7)[0] == 0 &&
            //    ((float[])attrObj7)[1] == 0 &&
            //    ((float[])attrObj7)[2] == 0); //the default vector
            //float[][] newSequence =
            //{
            //    new float[] {1, 2, 3},
            //    new float[] {4, 5, 6},
            //    new float[] {7, 8, 9}
            //};
            //node7.SetAttribute(attrSimpleSequence, newSequence);
            //attrObj7 = node7.GetAttribute(attrSimpleSequence);
            //Assert.IsTrue(ArraysEqual(attrObj7, newSequence));
        }
Example #8
0
        public void TestCustomAttributeInfo()
        {
            AttributeInfo info = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            DomNodeType test = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { info },
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            Utilities.TestSequenceEqual(test.Attributes, info);
            Assert.True(test.IsValid(info));
            Assert.AreSame(test.GetAttributeInfo("foo"), info);
            // check that type is now frozen
            Assert.Throws<InvalidOperationException>(delegate { test.Define(GetStringAttribute("notFoo")); });

            Assert.AreEqual(info.OwningType, test);
            Assert.AreEqual(info.DefiningType, test);
            Assert.Null(test.GetAttributeInfo("bar"));
        }
Example #9
0
        public void TestOverriddenAttributeInfo()
        {
            AttributeInfo info = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            DomNodeType test = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { info },
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            AttributeInfo overridden = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            DomNodeType child = new DomNodeType("child", test,
                new AttributeInfo[] { overridden },
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            Assert.AreSame(child.GetAttributeInfo("foo"), overridden);
            Assert.AreEqual(overridden.OwningType, child);
            Assert.AreEqual(overridden.DefiningType, test);

            Assert.True(info.Equivalent(overridden));
            Assert.True(overridden.Equivalent(info));

            Assert.True(test.IsValid(overridden));
            Assert.True(child.IsValid(info));
        }
Example #10
0
        public void TestInheritedAttributeInfo()
        {
            AttributeInfo info = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            DomNodeType test = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { info },
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            DomNodeType child = new DomNodeType("child");
            child.BaseType = test;

            AttributeInfo inherited = child.GetAttributeInfo("foo");
            Assert.AreEqual(inherited.OwningType, test);
            Assert.AreEqual(inherited.DefiningType, test);

            Assert.True(inherited.Equivalent(info));
            Assert.True(info.Equivalent(inherited));
        }
Example #11
0
        void IInitializable.Initialize()
        {
            m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent);
            m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this);

            Application.ApplicationExit += delegate
            {
                Util3D.Shutdown();
                GameEngine.Shutdown();
            };

            GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews();

            m_gameDocumentRegistry.DocumentAdded   += m_gameDocumentRegistry_DocumentAdded;
            m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved;

            string ns = m_schemaLoader.NameSpace;

            // register GridRenderer on grid child.
            DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType");

            gridType.Define(new ExtensionInfo <GridRenderer>());

            // register NativeGameWorldAdapter on game type.
            m_schemaLoader.GameType.Define(new ExtensionInfo <NativeDocumentAdapter>());

            // parse schema annotation.
            foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes())
            {
                var topLevelAnnotations = domType.GetTagLocal <IEnumerable <XmlNode> >();
                if (topLevelAnnotations == null)
                {
                    continue;
                }

                // First, go through and interpret the annotations that are not inherited
                List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>();
                foreach (XmlNode annot in topLevelAnnotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == NativeAnnotations.NativeType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeObjectAdapter>());
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeDocumentType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeDocumentType, GameEngine.GetDocumentTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeDocumentAdapter>());
                        }
                    }
                }

                if (domType.GetTag(NativeAnnotations.NativeType) == null)
                {
                    continue;
                }
                uint typeId          = (uint)domType.GetTag(NativeAnnotations.NativeType);
                bool isBoundableType = false;

                // Now, go through and interpret annotations that can be inheritted from base clases.
                // Sometimes a native property can be inheritted from a base class. In this model, we
                // will create a separate "property id" for each concrete class. When a property is
                // inheritted, the "property ids" for each type in the inheritance chain will be different
                // and unrelated.

                foreach (var inherittedType in domType.Lineage)
                {
                    var annotations = inherittedType.GetTagLocal <IEnumerable <XmlNode> >();
                    if (annotations == null)
                    {
                        continue;
                    }

                    foreach (XmlNode annot in annotations)
                    {
                        XmlElement elm = annot as XmlElement;
                        if (elm.LocalName == NativeAnnotations.NativeProperty)
                        {
                            // find a prop name and added to the attribute.
                            string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName);
                            string attribName     = elm.GetAttribute(NativeAnnotations.Name);
                            uint   propId         = GameEngine.GetObjectPropertyId(typeId, nativePropName);
                            if (!string.IsNullOrEmpty(attribName))
                            {
                                AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name));
                                attribInfo.SetTag(NativeAnnotations.NativeProperty, propId);
                            }
                            else
                            {
                                NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId);
                                nativeAttribs.Add(attribInfo);
                            }

                            if (nativePropName == "Bounds" || nativePropName == "LocalBounds")
                            {
                                isBoundableType = true;
                            }
                        }
                        else if (elm.LocalName == NativeAnnotations.NativeElement)
                        {
                            ChildInfo info = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name));
                            string    name = elm.GetAttribute(NativeAnnotations.NativeName);
                            info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name));
                        }
                        else if (elm.LocalName == NativeAnnotations.NativeVis)
                        {
                            using (var transfer = new NativeObjectAdapter.NativePropertyTransfer())
                            {
                                using (var stream = transfer.CreateStream())
                                    foreach (var a in elm.Attributes)
                                    {
                                        var attrib = a as XmlAttribute;
                                        if (attrib.Name == "geo")
                                        {
                                            NativeObjectAdapter.PushAttribute(
                                                0,
                                                typeof(string), 1,
                                                attrib.Value,
                                                transfer.Properties, stream);
                                        }
                                    }

                                GameEngine.SetTypeAnnotation(typeId, "vis", transfer.Properties);
                            }
                        }
                    }
                }

                if (nativeAttribs.Count > 0)
                {
                    domType.SetTag(nativeAttribs.ToArray());
                }

                if (isBoundableType && domType.IsAbstract == false)
                {
                    domType.Define(new ExtensionInfo <BoundableObject>());
                }
            }


            // register BoundableObject
            m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>());   // doesn't have a bound native attributes -- is this really intended?s

            #region code to handle gameObjectFolder

            {
                // This code is fragile and need to be updated whenever
                // any relevant part of the schema changes.
                // purpose:
                // gameObjectFolderType does not exist in C++
                // this code will map gameObjectFolderType to gameObjectGroupType.
                DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType;
                DomNodeType groupType     = m_schemaLoader.GameObjectGroupType;

                // map native bound attrib from gameObject to GobFolder
                NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>();
                foreach (var attrib in nativeAttribs)
                {
                    if (attrib.Name == "Bounds")
                    {
                        gobFolderType.SetTag(new NativeAttributeInfo[] { attrib });
                        break;
                    }
                }

                // map type.
                //      XLE --> Separate GameObjectFolder type from GameObjectGroup type
                // gobFolderType.Define(new ExtensionInfo<NativeObjectAdapter>());
                // gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType));

                // map all native attributes of gameObjectGroup to gameFolder
                foreach (AttributeInfo srcAttrib in groupType.Attributes)
                {
                    object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty);
                    if (nativeIdObject == null)
                    {
                        continue;
                    }
                    AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name);
                    if (destAttrib == null)
                    {
                        continue;
                    }
                    destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject);
                    destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib);
                }

                // map native element from gameObjectGroupType to gameObjectFolderType.
                object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement);
                foreach (ChildInfo srcChildInfo in gobFolderType.Children)
                {
                    if (srcChildInfo.IsList)
                    {
                        srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId);
                    }
                }

                m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId);
            }

            #endregion

            // set up scripting bindings
            if (m_scriptingService != null)
            {
                m_scriptingService.SetVariable("cv", new GUILayer.TweakableBridge());
            }
        }
Example #12
0
        void IInitializable.Initialize()
        {
            m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent);
            m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this);

            Application.ApplicationExit += delegate
            {
                Util3D.Shutdown();
                GameEngine.Shutdown();
            };

            GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews();

            m_gameDocumentRegistry.DocumentAdded   += m_gameDocumentRegistry_DocumentAdded;
            m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved;

            string ns = m_schemaLoader.NameSpace;

            // register GridRenderer on grid child.
            DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType");

            gridType.Define(new ExtensionInfo <GridRenderer>());

            // register NativeGameWorldAdapter on game type.
            m_schemaLoader.GameType.Define(new ExtensionInfo <NativeGameWorldAdapter>());

            // parse schema annotation.
            foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes())
            {
                IEnumerable <XmlNode> annotations = domType.GetTagLocal <IEnumerable <XmlNode> >();
                if (annotations == null)
                {
                    continue;
                }


                // collect all the properties that only exist in native side.
                List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>();

                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == NativeAnnotations.NativeType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeObjectAdapter>());
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeProperty)
                    {
                        // find a prop name and added to the attribute.


                        string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName);
                        string attribName     = elm.GetAttribute(NativeAnnotations.Name);
                        uint   typeId         = (uint)domType.GetTag(NativeAnnotations.NativeType);
                        uint   propId         = GameEngine.GetObjectPropertyId(typeId, nativePropName);
                        if (!string.IsNullOrEmpty(attribName))
                        {
                            AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name));
                            attribInfo.SetTag(NativeAnnotations.NativeProperty, propId);
                        }
                        else
                        {
                            NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId);
                            nativeAttribs.Add(attribInfo);
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeElement)
                    {
                        ChildInfo info   = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name));
                        uint      typeId = (uint)domType.GetTag(NativeAnnotations.NativeType);
                        string    name   = elm.GetAttribute(NativeAnnotations.NativeName);
                        info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name));
                    }
                }

                if (nativeAttribs.Count > 0)
                {
                    domType.SetTag(nativeAttribs.ToArray());
                }
            }


            // register BoundableObject
            m_schemaLoader.GameObjectType.Define(new ExtensionInfo <BoundableObject>());
            m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>());

            #region code to handle gameObjectFolder

            {
                // This code is fragile and need to be updated whenever
                // any relevant part of the schema changes.
                // purpose:
                // gameObjectFolderType does not exist in C++
                // this code will map gameObjectFolderType to gameObjectGroupType.
                DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType;
                DomNodeType groupType     = m_schemaLoader.GameObjectGroupType;

                // map native bound attrib from gameObject to GobFolder
                NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>();
                foreach (var attrib in nativeAttribs)
                {
                    if (attrib.Name == "Bounds")
                    {
                        gobFolderType.SetTag(new NativeAttributeInfo[] { attrib });
                        break;
                    }
                }

                // map type.
                gobFolderType.Define(new ExtensionInfo <NativeObjectAdapter>());
                gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType));

                // map all native attributes of gameObjectGroup to gameFolder
                foreach (AttributeInfo srcAttrib in groupType.Attributes)
                {
                    object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty);
                    if (nativeIdObject == null)
                    {
                        continue;
                    }
                    AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name);
                    if (destAttrib == null)
                    {
                        continue;
                    }
                    destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject);
                    destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib);
                }

                // map native element from gameObjectGroupType to gameObjectFolderType.
                object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement);
                foreach (ChildInfo srcChildInfo in gobFolderType.Children)
                {
                    if (srcChildInfo.IsList)
                    {
                        srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId);
                    }
                }

                m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId);
            }

            #endregion
        }