public void FlatRoadTest() { var testRoads = new RoadContainer() { inGameNamePrefix = "Test Road", roadType = RoadContainer.Type.Road, searchLimit = RoadContainer.Limit.Ground, tags = { new Mapper.OSM.OSMWayTag() { k = "test", v = "value" } } }; var testRoadExtensions = new List<KeyValuePair<string, RoadContainer.Limit>>() { new KeyValuePair<string, RoadContainer.Limit>("Test Bus", RoadContainer.Limit.Bus), new KeyValuePair<string, RoadContainer.Limit>("Test Bicycle", RoadContainer.Limit.Bicycle), new KeyValuePair<string, RoadContainer.Limit>("Test All Elevations", RoadContainer.Limit.ElevationsOnly), new KeyValuePair<string, RoadContainer.Limit>("Test Flat Only", RoadContainer.Limit.Ground) }; var finalList = RoadManager.AddRoadExtensions(testRoads, testRoadExtensions); Assert.IsTrue(finalList.Count == 2); Assert.IsTrue(finalList[0].inGameNamePrefix == "Test Road Test All Elevations"); Assert.IsTrue(finalList[1].inGameNamePrefix == "Test Road Test Flat Only"); }
/// <summary> /// Adds an extension to the name of the base road /// based on the roadExtensions list /// </summary> /// <param name="baseRoad">The initial road to add extension names to</param> /// <param name="roadExtensions">A list of strings containing possible road name extensions</param> /// <returns>A list of new roads plus all extensions in the name</returns> public static List<RoadContainer> AddRoadExtensions(RoadContainer baseRoad, List<KeyValuePair<string, RoadContainer.Limit>> roadExtensions) { List<RoadContainer> returnRoads = new List<RoadContainer>(); foreach (KeyValuePair<string, RoadContainer.Limit> roadExtension in roadExtensions) { if(baseRoad.searchLimit == RoadContainer.Limit.None || (baseRoad.searchLimit & roadExtension.Value) != RoadContainer.Limit.None) { RoadContainer modifiedRoad = new RoadContainer { inGameNamePrefix = baseRoad.inGameNamePrefix + " " + roadExtension.Key, roadType = baseRoad.roadType, inGameNamePostfix = baseRoad.inGameNamePostfix, searchLimit = baseRoad.searchLimit, tags = baseRoad.tags }; returnRoads.Add(modifiedRoad); } } return returnRoads; }
internal static void LoadRoadsFromFile() { Debug.Log("Loading roads from file..."); XmlRoads _xmlRoads = XmlRoadHandler.LoadRoads(); foreach(XmlRoad road in _xmlRoads.roads) { RoadContainer _container = new RoadContainer(); List<OSM.OSMWayTag> _tags = new List<OSM.OSMWayTag>(); _container.inGameNamePostfix = road.postfix; _container.inGameNamePrefix = road.prefix; _container.linkedOption = road.linkedOption; _container.roadType = Enum.Parse(typeof(RoadContainer.Type), road.roadType) as RoadContainer.Type? ?? RoadContainer.Type.Unknown; _container.searchLimit = Enum.Parse(typeof(RoadContainer.Limit), road.searchLimit) as RoadContainer.Limit? ?? RoadContainer.Limit.None; foreach(XmlOSMTag tag in road.tags) { _tags.Add(new OSM.OSMWayTag() { k = tag.key, v = tag.value }); } _container.tags = _tags; Debug.Log("Added " + road.prefix + " " + road.postfix); roads.Add(_container); } }