using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Xml;
namespace TeslaConsole.BattleTech;
///
/// Loads and exposes the BattleTech data catalog (BattleTech\BTConfig.xml),
/// mirroring TeslaConsole.RedPlanet.RPConfig. The single BT scenario is
/// "Free For All"; No Return reuses the same catalog and differs only by role.
///
public static class BTConfig
{
private static readonly BTScenario mFreeForAll;
private static readonly Dictionary mMaps;
private static readonly Dictionary mVehicles;
private static readonly Dictionary mTimesOfDay;
private static readonly Dictionary mWeather;
public static BTScenario FreeForAll => mFreeForAll;
public static Dictionary Maps => mMaps;
public static Dictionary Vehicles => mVehicles;
public static Dictionary TimesOfDay => mTimesOfDay;
public static Dictionary Weather => mWeather;
static BTConfig()
{
mMaps = new Dictionary();
mVehicles = new Dictionary();
mTimesOfDay = new Dictionary();
mWeather = new Dictionary();
XmlNode freeForAllNode = null;
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "BattleTech\\BTConfig.xml"));
foreach (XmlNode childNode in xmlDocument.DocumentElement.ChildNodes)
{
switch (childNode.Name)
{
case "freeforall":
freeForAllNode = childNode;
break;
case "map":
{
BTMap bTMap = new BTMap(childNode);
mMaps.Add(bTMap.Key, bTMap);
break;
}
case "vehicle":
{
BTVehicle bTVehicle = new BTVehicle(childNode);
mVehicles.Add(bTVehicle.Key, bTVehicle);
break;
}
case "time":
AddKeyNameNode(childNode, mTimesOfDay);
break;
case "weather":
{
BTWeather bTWeather = new BTWeather(childNode);
mWeather.Add(bTWeather.Key, bTWeather);
break;
}
}
}
mFreeForAll = new BTScenario(freeForAllNode);
}
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].Name;
}
}