using System.Collections.Generic; using System.IO; using System.Windows.Forms; using System.Xml; namespace TeslaConsole.RedPlanet; public static class RPConfig { private static readonly DeathRaceScenario mRace; private static readonly FootballScenario mFootball; private static readonly Dictionary mMaps; private static readonly Dictionary mVehicles; private static readonly Dictionary mTimesOfDay; private static readonly Dictionary mWeather; public static DeathRaceScenario DeathRace => mRace; public static FootballScenario Football => mFootball; public static Dictionary Maps => mMaps; public static Dictionary Vehicles => mVehicles; public static Dictionary TimesOfDay => mTimesOfDay; public static Dictionary Weather => mWeather; static RPConfig() { mRace = null; mFootball = null; mMaps = new Dictionary(); mVehicles = new Dictionary(); mTimesOfDay = new Dictionary(); mWeather = new Dictionary(); XmlNode scenarioNode = null; XmlNode scenarioNode2 = null; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RedPlanet\\RPConfig.xml")); foreach (XmlNode childNode in xmlDocument.DocumentElement.ChildNodes) { switch (childNode.Name) { case "race": scenarioNode = childNode; break; case "football": scenarioNode2 = childNode; break; case "map": { RPMap rPMap = new RPMap(childNode); mMaps.Add(rPMap.Key, rPMap); break; } case "vehicle": { RPVehicle rPVehicle = new RPVehicle(childNode); mVehicles.Add(rPVehicle.Key, rPVehicle); break; } case "time": AddKeyNameNode(childNode, mTimesOfDay); break; case "weather": AddKeyNameNode(childNode, mWeather); break; } } mRace = new DeathRaceScenario(scenarioNode); mFootball = new FootballScenario(scenarioNode2); } internal static void AddKeyNameNode(XmlNode node, Dictionary list) { list.Add(node.Attributes["key"].InnerText, node.Attributes["name"].InnerText); } public static string MapNameOrKey(string mapKey) { if (!mMaps.ContainsKey(mapKey)) { return mapKey; } return mMaps[mapKey].Name; } public static string VehicleNameOrKey(string vehicleKey) { if (!mVehicles.ContainsKey(vehicleKey)) { return vehicleKey; } return mVehicles[vehicleKey].Name; } public static string TimeOfDayNameOrKey(string timeOfDayKey) { if (!mTimesOfDay.ContainsKey(timeOfDayKey)) { return timeOfDayKey; } return mTimesOfDay[timeOfDayKey]; } public static string WeatherNameOrKey(string weatherKey) { if (!mWeather.ContainsKey(weatherKey)) { return weatherKey; } return mWeather[weatherKey]; } }