コード例 #1
0
ファイル: FlexBone.cs プロジェクト: JOJOyh/ldd-modder
        public XElement SerializeToXml()
        {
            var boneElem = new XElement("Bone", new XAttribute("boneId", ID));

            if (ConnectionCheck != null)
            {
                boneElem.Add(new XAttribute("flexCheckConnection", $"{ConnectionCheck.Item1},{ConnectionCheck.Item2},{ConnectionCheck.Item3}"));
            }

            boneElem.Add(Transform.ToXmlAttributes());

            if (Collisions.Any())
            {
                var collisionElem = boneElem.AddElement("Collision");
                foreach (var col in Collisions)
                {
                    collisionElem.Add(col.SerializeToXml());
                }
            }

            if (Connectors.Any())
            {
                var connectivityElem = boneElem.AddElement("Connectivity");
                foreach (var con in Connectors)
                {
                    connectivityElem.Add(con.SerializeToXml());
                }
            }

            if (PhysicsAttributes != null)
            {
                boneElem.Add(PhysicsAttributes.SerializeToXml());
            }

            if (Bounding != null)
            {
                var boundingElem = boneElem.AddElement("Bounding");
                boundingElem.Add(Bounding.SerializeToXml("AABB"));
            }

            return(boneElem);
        }
コード例 #2
0
ファイル: Primitive.cs プロジェクト: swenyan/ldd-modder
        public XElement SerializeToXml()
        {
            var rootElem = new XElement("LEGOPrimitive",
                                        new XAttribute("versionMajor", FileVersion.Major),
                                        new XAttribute("versionMinor", FileVersion.Minor));

            var annotations = rootElem.AddElement("Annotations");

            if (!Aliases.Contains(ID) && ID > 0)
            {
                Aliases.Add(ID);
            }

            if (Aliases.Any())
            {
                annotations.Add(new XElement("Annotation", new XAttribute("aliases", string.Join(";", Aliases))));
            }

            annotations.Add(new XElement("Annotation", new XAttribute("designname", Name)));

            if (MainGroup != null)
            {
                annotations.Add(new XElement("Annotation", new XAttribute("maingroupid", MainGroup.ID)));
                annotations.Add(new XElement("Annotation", new XAttribute("maingroupname", MainGroup.Name)));
            }

            if (Platform != null)
            {
                annotations.Add(new XElement("Annotation", new XAttribute("platformid", Platform.ID)));
                annotations.Add(new XElement("Annotation", new XAttribute("platformname", Platform.Name)));
            }

            annotations.Add(new XElement("Annotation", new XAttribute("version", PartVersion)));

            foreach (var extra in ExtraAnnotations)
            {
                annotations.Add(new XElement("Annotation", new XAttribute(extra.Key, extra.Value)));
            }

            if (Collisions.Any())
            {
                rootElem.Add(new XElement("Collision", Collisions.Select(x => x.SerializeToXml())));
            }

            if (Connectors.Any())
            {
                rootElem.Add(new XElement("Connectivity", Connectors.Select(x => x.SerializeToXml())));
            }

            if (FlexBones.Any())
            {
                rootElem.Add(new XElement("Flex", FlexBones.Select(x => x.SerializeToXml())));
            }

            if (PhysicsAttributes != null && !PhysicsAttributes.IsEmpty)
            {
                rootElem.Add(PhysicsAttributes.SerializeToXml());
            }

            if (Bounding != null)
            {
                var boundingElem = rootElem.AddElement("Bounding");
                boundingElem.Add(Bounding.SerializeToXml("AABB"));
            }

            if (GeometryBounding != null)
            {
                var boundingElem = rootElem.AddElement("GeometryBounding");
                boundingElem.Add(GeometryBounding.SerializeToXml("AABB"));
            }

            if (SubMaterials != null)
            {
                var decorationElem = rootElem.AddElement("Decoration");
                decorationElem.Add(new XAttribute("faces", SubMaterials.Length));
                decorationElem.Add(new XAttribute("subMaterialRedirectLookupTable", string.Join(",", SubMaterials)));
            }

            if (DefaultOrientation != null)
            {
                rootElem.Add(new XElement("DefaultOrientation", DefaultOrientation.ToXmlAttributes()));
            }

            if (DefaultCamera != null)
            {
                rootElem.Add(XmlHelper.DefaultSerialize(DefaultCamera, "DefaultCamera"));
            }

            foreach (var elem in rootElem.Descendants("Custom2DField"))
            {
                int depth = elem.AncestorsAndSelf().Count();
                elem.Value  = elem.Value.Indent(depth, "  ");
                elem.Value += StringExtensions.Tab(depth - 1, "  "); //fixes the closing tag indentation
            }

            if (ExtraElements != null)
            {
                foreach (var elem in ExtraElements)
                {
                    if (elem.Parent != null)
                    {
                        var parentElem = rootElem.Descendants().FirstOrDefault(x => x.Name.LocalName == elem.Parent.Name.LocalName);
                        //if (parentElem != null)
                        //    parentElem.Add(elem.)
                    }
                    else
                    {
                        rootElem.Add(elem);
                    }
                }
            }
            return(rootElem);
        }