static public List <PlayerController.MapElement> loadExistMapList() { List <PlayerController.MapElement> list = new List <PlayerController.MapElement>(); String[] directories = DataUtility.getFolderList(); for (int i = 0; i < directories.Length; i++) { WorldDataConst.WorldData worldInfo = DataUtility.load <WorldDataConst.WorldData>(directories[i], WORLD_FILENAME); if (worldInfo != null) { PlayerController.MapElement element = new PlayerController.MapElement(); element.name = worldInfo.name; element.uuid = worldInfo.uuid; element.seeds = worldInfo.seeds; element.width = worldInfo.width; element.height = worldInfo.height; element.lastUpdate_long = worldInfo.lastUpdate; element.lastUpdate = DateTimeOffset.FromUnixTimeSeconds(worldInfo.lastUpdate).LocalDateTime.ToString(); element.pathName = directories[i]; list.Add(element); } } MapComparer comparer = new MapComparer(); list.Sort((a, b) => (int)(a.lastUpdate_long - b.lastUpdate_long)); list.Reverse(); return(list); }
public IEnumerable <K> SortByValue(Comparer <V> comparer = null) { var keys = this.Keys.ToList(); var mapComparer = new MapComparer <K>(this, comparer); keys.Sort(mapComparer); return(keys); }
public void MapComparerTest() { var c = new MapComparer <string, string>(s => s.ToUpperInvariant()); Assert.AreEqual(-1, c.Compare("ABC", "DEF")); Assert.AreEqual(1, c.Compare("DEF", "ABC")); Assert.AreEqual(1, c.Compare("def", "ABC")); Assert.AreEqual(1, c.Compare("DEF", "abc")); }
public bool Equals(MapData other) { if (other == null) { return(false); } int levelNumber = MapComparer.MapNameToLevel(other.NameInternal); return(LevelNumber == levelNumber); }
public MapData(string name, string nameSafe, string nameInternal) { Name = name; NameSafe = nameSafe; NameInternal = nameInternal; LevelNumber = MapComparer.MapNameToLevel(NameInternal); foreach (char invalidPathChar in Path.GetInvalidPathChars()) { NameSafe = NameSafe.Replace(invalidPathChar, ' '); } }
private void Parse(string content) { if (string.IsNullOrEmpty(content)) { return; } foreach (string line in content.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)) { if (line.Contains("=")) { string[] values = line.Split('='); if (values.Length < 2) { continue; } if (values[0] == "completed") { Completed = int.Parse(values[1]) == 1; } if (values[0] == "date") { SavedAt = DateTime.Now; if (int.TryParse(values[1], out var unix)) { SavedAt = DateTimeOffset.FromUnixTimeSeconds(unix).LocalDateTime; } // For folder name DateTimeSafe = SavedAt.ToString("yyyy-MM-dd HH.mm.ss"); // For list view DateTimeString = SavedAt.ToString("yyyy-MM-dd HH:mm:ss"); } if (values[0] == "difficulty") { Difficulty = int.Parse(values[1]); DiffToString(Difficulty); } if (values[0] == "mapDesc") { MapDesc = values[1]; } if (values[0] == "mapName") { MapName = values[1]; } if (values[0] == "time") { PlayedTime = new TimeSpan(0, 0, int.Parse(values[1])); } } } if (MapDesc != "") { MapSafe = MapDesc; } foreach (char invalidPathChar in System.IO.Path.GetInvalidPathChars()) { MapSafe = MapSafe.Replace(invalidPathChar, ' '); } LevelNumber = MapComparer.MapNameToLevel(MapName); if (LevelNumber > 0) { MapSafe = LevelNumber.ToString().PadRight(2) + " - " + MapSafe; } }