public void Save(IReadWritePackage toPackage)
{
MapFormat = SupportedMapFormat;
var root = new List<MiniYamlNode>();
foreach (var field in YamlFields)
field.Serialize(this, root);
// Saving to a new package: copy over all the content from the map
if (Package != null && toPackage != Package)
foreach (var file in Package.Contents)
toPackage.Update(file, Package.GetStream(file).ReadAllBytes());
if (!LockPreview)
toPackage.Update("map.png", SavePreview());
// Update the package with the new map data
var s = root.WriteToString();
toPackage.Update("map.yaml", Encoding.UTF8.GetBytes(s));
toPackage.Update("map.bin", SaveBinaryData());
Package = toPackage;
// Update UID to match the newly saved data
Uid = ComputeUID(toPackage);
}