public static void Serialize(Stream stream, Map map, bool compress = true) { var oldMap = new Internal.Map(5, compress) { Rulebook = new Internal.Serializables.Rulebook { Rules = StringifyProperties(map.Rulebook) } }; oldMap.Items.AddRange(map.Where(i => i != null).Select(i => new MapItem { ResourceName = i.ResourceName, Position = ToFloatvector(i.Position), Rotation = ToByteVector(i.Rotation), Scale = i.Scale, Properties = StringifyProperties(i.Properties), Rulebook = null })); InternalConverter.Serialize(stream, oldMap); }
public static Map Deserialize(Stream stream) { var oldMap = InternalConverter.Deserialize(stream); var map = new Map { Rulebook = new Rulebook(PropertizeStrings(oldMap.Rulebook.Rules)) }; foreach (var mapItem in oldMap.Items) { map.Add(new Item(mapItem.ResourceName) { Position = MakeVector(mapItem.Position), Rotation = MakeVector(mapItem.Rotation), Scale = mapItem.Scale, Properties = PropertizeStrings(mapItem.Properties) }); } return map; }
public static Map Deserialize(Stream stream, Encoding encoding = null) { var reader = new AtmoReader(stream, encoding); var header = reader.Read<MapHeader>(); int version; if (header.Format != FormatIdentifier || !int.TryParse(header.Version, out version)) { throw new InvalidDataException("Unknown map format"); } if (header.Compressed) { reader = new AtmoReader(new InflaterInputStream(stream)); } var body = reader.Read<MapBody>(); var map = new Map(version) { Rulebook = body.Content .Select(i => i.Rulebook) .First(r => r != null) }; map.Items.AddRange(body.Content.Where(i => i.Rulebook == null)); return map; }
public static void Serialize(Stream stream, Map map, Encoding encoding = null) { var writer = new AtmoWriter(stream, encoding); writer.Write(new MapHeader { Format = FormatIdentifier, Version = map.Version.ToString(), Compressed = map.Compressed, }); if (map.Compressed) { stream = new DeflaterOutputStream(stream, new Deflater(Deflater.BEST_COMPRESSION)); } writer = new AtmoWriter(stream, encoding) { Solver = new ReferenceSolver() }; writer.Write(writer.Solver); writer.Write(new MapItem { ResourceName = "Rulebook", Rulebook = map.Rulebook }); writer.Write((IEnumerable<MapItem>) map.Items); if (map.Compressed) { ((DeflaterOutputStream) stream).Finish(); } }
public static async Task SerializeAsync(Stream stream, Map map, bool compress = true) { await Task.Run(() => Serialize(stream, map, compress)); }