public void Show(HelperData helperData) { try { if (helperData == null) { return; //do nothing } string[] foo = helperData.reachable.Values .Where((location) => location.items.Count > 0) .OrderByDescending((location) => location.items.Count) .Select((location) => $"{location.name} - {location.items.Count} reachable") .ToArray(); GetOrInitializeTextComponent().text = string.Join("\n", foo); GetOrInitializeTextObj().SetActive(true); } catch (Exception e) { logger.Warn($"Show failed: {e}"); } }
public Either <string, HelperData> parse(System.IO.StreamReader reader) { HelperData retVal = new HelperData(); string line; //Read until we see "RECHABLE ITEM LOCATIONS". Boolean sawReachableItemLocations = false; while ((line = reader.ReadLine()) != null) { if (line.Equals("REACHABLE ITEM LOCATIONS")) { sawReachableItemLocations = true; break; } } if (!sawReachableItemLocations) { return(new Either.Left <string, HelperData>("Expected to see 'RECHABLE ITEM LOCATIONS' but hit end of file.")); } line = reader.ReadLine(); if (!Regex.Match(line, @"There are [0-9]+ unchecked reachable locations.", RegexOptions.None).Success) { return(new Either.Left <string, HelperData>($"Expected to see 'There are N unchecked reachable locations.' but got {line}")); } line = reader.ReadLine(); if (!"".Equals(line)) { return(new Either.Left <string, HelperData>($"Expected a blank line but got {line}")); } Boolean sawCheckedItemLocations = false; Location currentLocation = null; const string itemPrefix = " - "; while ((line = reader.ReadLine()) != null) { if (line.Equals("CHECKED ITEM LOCATIONS")) { sawCheckedItemLocations = true; break; } else if (line.Equals("")) { if (currentLocation != null) { try { retVal.reachable.Add(currentLocation.name, currentLocation); } catch (ArgumentException e) { logger.Warn($"Ignoring duplicate entry for locationg {currentLocation.name} (old value = {retVal.reachable[currentLocation.name]}, new value = {currentLocation}) {e.ToString()}"); } } currentLocation = null; } else if (line.StartsWith(itemPrefix)) { currentLocation.items.Add(line.Substring(itemPrefix.Length)); } else { currentLocation = new Location(line); } } if (!sawCheckedItemLocations) { return(new Either.Left <string, HelperData>("Expected to see 'CHECKED ITEM LOCATIONS' but reached end of file.")); } while ((line = reader.ReadLine()) != null) { if (Regex.Match(line, @"Generated helper log in [0-9.]+ seconds\.", RegexOptions.None).Success) { break; } else if (line.Equals("")) { if (currentLocation != null) { try { retVal.checkedd.Add(currentLocation.name, currentLocation); } catch (ArgumentException e) { logger.Warn($"Ignoring duplicate entry for locationg {currentLocation.name} (old value = {retVal.reachable[currentLocation.name]}, new value = {currentLocation}) {e.ToString()}"); } } currentLocation = null; } else if (line.StartsWith(itemPrefix)) { currentLocation.items.Add(line.Substring(itemPrefix.Length)); } else { currentLocation = new Location(line); } } return(new Either.Right <string, HelperData>(retVal)); }