public void Save(TextWriter output) { // Compress m_tileMap.Compress(); // Save out header var kvp = new KeyValuePairs(); kvp.Comment = "Level data"; kvp.Set("id", Info.ID); kvp.Set("title", Info.Title); kvp.Set("music", Info.MusicPath); kvp.Set("sky", Info.SkyPath); kvp.Set("script", Info.ScriptPath); kvp.Set("item", Info.ItemPath); kvp.Set("intro", Info.IntroPath); kvp.Set("outro", Info.OutroPath); kvp.Set("item_count", Info.TotalPlacements); kvp.Set("ever_completed", Info.EverCompleted); kvp.Set("camera.pitch", Info.CameraPitch); kvp.Set("camera.yaw", Info.CameraYaw); kvp.Set("camera.distance", Info.CameraDistance); kvp.Set("random.seed", Info.RandomSeed); // Save out tiles kvp.Set("tiles.width", Tiles.Width); kvp.Set("tiles.height", Tiles.Height); kvp.Set("tiles.depth", Tiles.Depth); kvp.Set("tiles.x_origin", Tiles.MinX); kvp.Set("tiles.y_origin", Tiles.MinY); kvp.Set("tiles.z_origin", Tiles.MinZ); var lookup = new TileLookup(); int lastID = -1; var tiles = new StringBuilder(); var robotCount = 0; for (int x = Tiles.MinX; x < Tiles.MaxX; ++x) { for (int y = Tiles.MinY; y < Tiles.MaxY; ++y) { for (int z = Tiles.MinZ; z < Tiles.MaxZ; ++z) { var coords = new TileCoordinates(x, y, z); var tile = Tiles.GetTile(coords); var direction = tile.GetDirection(this, coords); if (tile == Dan200.Game.Level.Tiles.Extension) { tile = Dan200.Game.Level.Tiles.Air; direction = FlatDirection.North; } int id = lookup.GetIDForTile(tile); if (id < 0) { id = lookup.AddTile(tile); lastID = id; } tiles.Append(Base64.ToString(id, 2)); tiles.Append(Base64.ToString((int)direction, 1)); var behaviour = tile.GetBehaviour(this, coords); if (behaviour is SpawnTileBehaviour && ((SpawnTileBehaviour)behaviour).Required) { robotCount++; } } } } kvp.Set("tiles.data", tiles.ToString()); kvp.Set("robot_count", robotCount); // Save out lookup var lookupString = new StringBuilder(); for (int i = 0; i <= lastID; ++i) { var tile = lookup.GetTileFromID(i); lookupString.Append(tile.Path); if (i < lastID) { lookupString.Append(','); } } kvp.Set("tiles.lookup", lookupString.ToString()); // Save out file kvp.Save(output); }