public static void Initialize() { string folder = "data/tile_manifests"; string[] files = FileStuff.GetFilesInFolder(folder, false); foreach (string file in files) { string path = folder + "/" + file; string contents = FileStuff.ReadFile(path); string name = file.EndsWith(".txt") ? file.Substring(0, file.Length - 4) : file; InitializeCategory(name, contents); } }
public Level(string name, bool overwrite) { this.Name = name; this.IsDirty = false; string filepath = "data/levels/" + name + ".txt"; if (overwrite && FileStuff.Exists(filepath)) { System.Windows.MessageBox.Show("Warning: a level with this name already exists. Saving this level will overwrite that level."); } string contents = overwrite ? "" : FileStuff.ReadFile(filepath); foreach (string line in contents.Split('\n')) { string formattedLine = line.Trim(); if (formattedLine.Length > 0 && formattedLine[0] == '#') { string[] parts = formattedLine.Substring(1).Split(':'); if (parts.Length > 1) { string key = parts[0]; string value = parts[1]; for (int i = 2; i < parts.Length; ++i) { value += ":" + parts[i]; } this.values[key] = value; } } } int width = 12; int height = 12; bool loadTiles = this.values.ContainsKey("width") && this.values.ContainsKey("height") && int.TryParse(this.values["width"], out width) && int.TryParse(this.values["height"], out height) && this.values.ContainsKey("tiles"); this.Width = width; this.Height = height; this.Grid = new List <Tile> [width * height]; if (loadTiles) { string[] rawTileColumns = this.values["tiles"].Split(','); for (int i = 0; i < width * height; ++i) { List <Tile> tileStack = new List <Tile>(); string[] rawTileColumn = rawTileColumns[i].Split('|'); if (rawTileColumn.Length > 0 && rawTileColumn[0].Length > 0) { foreach (string rawTileCell in rawTileColumn) { tileStack.Add(TileStore.GetTile(rawTileCell)); } } this.Grid[i] = tileStack; } } else { for (int i = 0; i < width * height; ++i) { this.Grid[i] = new List <Tile>(); } } }