示例#1
0
        public static string serialize(object contents, ContentType type)
        {
            if (type == ContentType.DictInt)
            {
                StringWriter writer = new StringWriter();
                (contents as SerializableDictionary <int, string>).WriteXml(XmlWriter.Create(writer));
                return(PyNet.CompressString(writer.ToString()));
            }

            if (type == ContentType.DictString)
            {
                StringWriter writer = new StringWriter();
                (contents as SerializableDictionary <string, string>).WriteXml(XmlWriter.Create(writer));
                return(PyNet.CompressString(writer.ToString()));
            }

            if (type == ContentType.Texture)
            {
                return(PyNet.CompressString(JsonConvert.SerializeObject(new SerializationTexture2D((contents as Texture2D)))));
            }

            if (type == ContentType.Map)
            {
                var format = new TMXTile.TMXFormat(Game1.tileSize / Game1.pixelZoom, Game1.tileSize / Game1.pixelZoom, Game1.pixelZoom, Game1.pixelZoom);
                return(PyNet.CompressString(format.StoreAsString((contents as Map))));
            }

            return("na");
        }
示例#2
0
        public static T deserialize <T>(ContentResponse response)
        {
            if (response.type == (int)ContentType.DictInt)
            {
                SerializableDictionary <int, string> newAsset = new SerializableDictionary <int, string>();
                StringReader reader = new StringReader(PyNet.DecompressString(response.content));
                newAsset.ReadXml(XmlReader.Create(reader));
                return((T)(object)newAsset);
            }

            if (response.type == (int)ContentType.DictString)
            {
                SerializableDictionary <string, string> newAsset = new SerializableDictionary <string, string>();
                StringReader reader = new StringReader(PyNet.DecompressString(response.content));
                newAsset.ReadXml(XmlReader.Create(reader));
                return((T)(object)newAsset);
            }

            if (response.type == (int)ContentType.Texture)
            {
                SerializationTexture2D sTexture = JsonConvert.DeserializeObject <SerializationTexture2D>(PyNet.DecompressString(response.content));
                return((T)(object)sTexture.getTexture());
            }

            if (response.type == (int)ContentType.Map)
            {
                TMXTile.TMXFormat format = new TMXTile.TMXFormat(Game1.tileSize / Game1.pixelZoom, Game1.tileSize / Game1.pixelZoom, Game1.pixelZoom, Game1.pixelZoom);
                StringReader      reader = new StringReader(PyNet.DecompressString(response.content));
                Map map = format.Load(XmlReader.Create(reader));
                return((T)(object)map);
            }

            return((T)(object)null);
        }