protected override void Save(StackWriter writer, Map map) { foreach (var item in map.Resources) { writer.WriteStack(item.Key, item.Value); } }
protected override void Save(StackWriter writer, Map map) { foreach (var building in map.Buildings) { if (building is Core) { continue; } writer.PushItems(building.Pos, building.Type); if (building is Workshop w) { writer.PushItem(w.Recipe.Name); } if (building.Output is DirectProducer p) { writer.PushItem(p.Buffer); } if (building.Input is DirectConsumer c) { foreach (var buffer in c.Buffers) { writer.PushItems(buffer.Item, buffer.Buffer); } } writer.WriteStack(); } }
protected override void Save(StackWriter writer, Map map) { foreach (var path in map.VehiclePaths.Paths) { if (path.PathType == PathType.Driveway || path.Fixed) { continue; } writer.WriteStack(path.Source, path.Dest, path.PathType); } }
protected override void Save(StackWriter writer, Map map) { foreach (var vehicle in map.Vehicles) { writer.PushItems(vehicle.Type, vehicle.Route.Id, vehicle.RouteIndex, vehicle.FrontPos); if (vehicle is Hauler h) { writer.PushItems(h.Carrying); } writer.WriteStack(); } foreach (var type in map.AvailableVehicles) { writer.PushItems(type, Guid.Empty); writer.WriteStack(); } }
protected override void Save(StackWriter writer, Map map) { foreach (var route in map.Routes) { writer.PushItem(route.Id); writer.PushItem(route.Destinations.Count); foreach (var destination in route.Destinations) { var action = route.GetAction(destination); writer.PushItems(destination.Pos, action.Type, action.Item); } foreach (var node in route.Path) { writer.PushItem(node.Pos); } writer.WriteStack(); } }
public static void Save(Map map, string name) { Console.Write("Saving... "); var start = DateTime.Now; if (!Directory.Exists(_saveDirectory)) { Directory.CreateDirectory(_saveDirectory); } // Create ZIP file if using var stream = new MemoryStream(); if (_zip) { _archive = new ZipArchive(stream, ZipArchiveMode.Create, true); } else { if (Directory.Exists(SavePath(name))) { Directory.Delete(SavePath(name), true); } Directory.CreateDirectory(SavePath(name)); Directory.CreateDirectory(SavePath(name, "chunks")); } foreach (var provider in _providers) { provider.Save(GetWriteStream(name, provider.Path), map); } // Save chunks foreach (var chunk in map.Chunks) { using (var writer = new StackWriter(GetWriteStream(name, $"chunks/chunk_{chunk.Pos.X}_{chunk.Pos.Y}.csv"))) { foreach (var tile in chunk.Tiles) { if (tile.Resource == Item.None) { writer.WriteStack(tile.Nutrients); } else { writer.WriteStack(tile.Nutrients, tile.Resource, tile.ResourceCount); } } } } if (_zip) { _archive.Dispose(); using (var f = File.Open(SavePath(name) + ".zip", FileMode.Create)) { stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(f); } } stream.Dispose(); var end = DateTime.Now; var span = end - start; Console.WriteLine($"done (took {Math.Round(span.TotalMilliseconds)} ms)."); }
protected abstract void Save(StackWriter writer, Map map);
public void Save(Stream stream, Map map) { using (var writer = new StackWriter(stream)) { Save(writer, map); } }