public static RoadPrefixFileIndexer Parse(string[] file) { RoadPrefixFileIndexer result = new RoadPrefixFileIndexer(); foreach (string line in file) { RoadPrefixFileItem item = RoadPrefixFileItem.Parse(line); if (item != null) { result.m_prefixes.Add(item); } } return(result); }
public static RoadPrefixFileItem Parse(string line) { string[] kv = line?.Split('='); if (kv?.Length != 2) { return(null); } RoadPrefixFileItem item = new RoadPrefixFileItem { name = kv[1]?.Trim() }; if (kv[0].Contains("h")) { item.highway = Highway.TRUE; } else if (kv[0].Contains("H")) { item.highway = Highway.FALSE; } MatchCollection matchesLinkingType = Regex.Matches(kv[0], @"[fie]"); if (matchesLinkingType?.Count > 0) { item.oneWay = OneWay.TRUE; item.linking = LinkingType.NONE; foreach (Match m in matchesLinkingType) { switch (m.Value) { case "f": item.linking |= LinkingType.FROM_BIG; break; case "i": item.linking |= LinkingType.FROM_SMALL; break; case "e": item.linking |= LinkingType.SAME_SIZE; break; } } } else { item.linking = LinkingType.NO_LINKING; if (kv[0].Contains("w") || kv[1].Contains("{1}") || kv[1].Contains("{2}") || kv[1].Contains("{3}") || kv[1].Contains("{4}") || kv[1].Contains("{7}")) { item.oneWay = OneWay.TRUE; } else if (kv[0].Contains("W")) { item.oneWay = OneWay.FALSE; } if ((item.oneWay & OneWay.FALSE) != 0) { if (kv[0].Contains("s")) { item.symmetry = Symmetry.TRUE; } else if (kv[0].Contains("S")) { item.symmetry = Symmetry.FALSE; } } } item.requireSource = kv[1].Contains("{1}") || kv[1].Contains("{3}") || kv[1].Contains("{4}"); item.requireTarget = kv[1].Contains("{2}"); MatchCollection matchesRoad = Regex.Matches(kv[0], @"[GBTD]"); if (matchesRoad?.Count > 0) { item.roadType = RoadType.NONE; foreach (Match m in matchesRoad) { switch (m.Value) { case "G": item.roadType |= RoadType.GROUND; break; case "B": item.roadType |= RoadType.BRIDGE; break; case "T": item.roadType |= RoadType.TUNNEL; break; case "D": item.roadType |= RoadType.DAM; break; } } } MatchCollection matchesWidth = Regex.Matches(kv[0], @"\[([0-9]{0,3}),([0-9]{0,3})\]"); if (matchesWidth?.Count > 0) { Match m = matchesWidth[0]; if (ushort.TryParse(m.Groups[1].Value, out ushort minWidth)) { item.minWidth = minWidth; } if (ushort.TryParse(m.Groups[2].Value, out ushort maxWidth)) { item.maxWidth = maxWidth; } } MatchCollection matchesWidthSingle = Regex.Matches(kv[0], @"\[([0-9]{0,3})\]"); if (matchesWidthSingle?.Count > 0) { Match m = matchesWidth[0]; if (ushort.TryParse(m.Groups[1].Value, out ushort minWidth)) { item.minWidth = minWidth; item.maxWidth = ++minWidth; } } MatchCollection matchesLanes = Regex.Matches(kv[0], @"\(([0-9]{0,3}),([0-9]{0,3})\)"); if (matchesLanes?.Count > 0) { Match m = matchesLanes[0]; if (byte.TryParse(m.Groups[1].Value, out byte minLanes)) { item.minLanes = minLanes; } if (byte.TryParse(m.Groups[2].Value, out byte maxLanes)) { item.maxLanes = maxLanes; } } MatchCollection matchesLanesSingle = Regex.Matches(kv[0], @"\(([0-9]{0,3})\)"); if (matchesLanesSingle?.Count > 0) { Match m = matchesLanesSingle[0]; if (byte.TryParse(m.Groups[1].Value, out byte minLanes)) { item.minLanes = minLanes; item.maxLanes = ++minLanes; } } if (kv[0].Contains("p") || kv[1].Contains("{8}") || kv[1].Contains("{10}")) { item.seedConfig = SeedConfiguration.HAS_HIGHWAY_TYPE; } else if (kv[0].Contains("P")) { item.seedConfig = SeedConfiguration.NO_HIGHWAY_TYPE; } else { item.seedConfig = SeedConfiguration.ANY_HIGHWAY_TYPE; } if (kv[0].Contains("n") || kv[1].Contains("{9}")) { item.seedConfig |= SeedConfiguration.HAS_FORCED_NAME; } else if (kv[0].Contains("N")) { item.seedConfig |= SeedConfiguration.NO_FORCED_NAME; } else { item.seedConfig |= SeedConfiguration.ANY_FORCED_NAME; } return(item); }