コード例 #1
0
        public void SerializeWorld(World world, Stream stream)
        {
            var rootNode = new TWXmlNode(TWXmlNode.CreateXmlDocument(), "World");

            var typesList = new List <WorldObjectType>();

            var worldObjectsNode = rootNode.CreateChildNode("WorldObjects");

            for (int i = 0; i < world.WorldObjectList.Count; i++)
            {
                var wObj = world.WorldObjectList[i];
                if (!typesList.Contains(wObj.ObjectType))
                {
                    typesList.Add(wObj.ObjectType);
                }

                SerializeWorldObject(wObj, worldObjectsNode.CreateChildNode("WorldObject"));
            }

            var typesNode = rootNode.CreateChildNode("WorldObjectTypes");

            for (int i = 0; i < typesList.Count; i++)
            {
                var type = typesList[i];

                SerializeWorldObjectType(type, typesNode.CreateChildNode("Type"));
            }


            rootNode.Document.Save(stream);
        }
コード例 #2
0
        public void SerializeTileData(TileData data, Stream stream)
        {
            var node  = new TWXmlNode(TWXmlNode.CreateXmlDocument(), "TileData");
            var guide = node.CreateChildNode("Guid");

            XMLSerializer.WriteGuid(guide, data.Guid);
            var mesh = node.CreateChildNode("Mesh");

            XMLSerializer.WriteGuid(mesh, data.Mesh.Guid);

            var dimensions = node.CreateChildNode("Dimensions");

            XMLSerializer.WriteVector3(dimensions, data.Dimensions);

            var facetypes = node.CreateChildNode("Faces");

            for (int i = 0; i < data.FaceTypes.Length; i++)
            {
                if (data.FaceTypes[i] == null)
                {
                    continue;
                }
                var faceNode = facetypes.CreateChildNode("Face");
                var face     = (TileFace)(i + 1);
                faceNode.AddAttribute("Face", face.ToString());

                XMLSerializer.WriteGuid(faceNode.CreateChildNode("Type"), data.FaceTypes[i].GetRoot().Guid);
                XMLSerializer.WriteBoolean(faceNode.CreateChildNode("Winding"), data.GetTotalWinding(face));
            }

            node.XmlDocument.Save(stream);
        }
コード例 #3
0
        public void Save(DirectoryInfo dir)
        {
            TWXmlNode root = new TWXmlNode(TWXmlNode.CreateXmlDocument(), "World");

            root.AddChildNode("SerializerVersion", "0.1");
            var entitiesNode = root.CreateChildNode("Entities");

            entitiesNode.AddAttributeInt("Count", entities.Count);

            dir.Create();
            for (int i = 0; i < entities.Count; i++)
            {
                var ent = entities[i];


                var relativePath = "Entity" + i.ToString("0000") + ".xml";

                var fi = new FileInfo(dir.FullName + "\\" + relativePath);

                saveEntity(ent, fi);

                var entityNode = entitiesNode.CreateChildNode("Entity");
                entityNode.AddAttribute("Type", ent.GetType().AssemblyQualifiedName);
                entityNode.AddAttribute("RelativePath", relativePath);
            }
            using (var fs = new FileStream(dir.FullName + "\\World.xml", FileMode.Create))
            {
                root.Document.Save(fs);
            }
        }
コード例 #4
0
        public void Serialize(T obj, Stream strm)
        {
            var type = typeof(T);

            var rootNode = new TWXmlNode(TWXmlNode.CreateXmlDocument(), type.Name);

            serializeObject(type, rootNode, obj);


            rootNode.Document.Save(strm);
        }