1 using System.Collections.Generic;
2 using System.Collections.Immutable;
8 internal static class CampaignModePresets
10 public static readonly ImmutableArray<CampaignSettings> List;
11 private static readonly ImmutableDictionary<Identifier, CampaignSettingDefinitions> definitions;
13 private static readonly
string fileListPath = Path.Combine(
"Data",
"campaignsettings.xml");
15 static CampaignModePresets()
17 if (!File.Exists(fileListPath) || !(XMLExtensions.TryLoadXml(fileListPath)?.Root is { } docRoot))
19 List = ImmutableArray<CampaignSettings>.Empty;
23 List<CampaignSettings> presetList =
new List<CampaignSettings>();
24 Dictionary<Identifier, CampaignSettingDefinitions> tempDefinitions =
new Dictionary<Identifier, CampaignSettingDefinitions>();
26 foreach (XElement element
in docRoot.Elements())
28 Identifier name = element.NameAsIdentifier();
31 if (name == CampaignSettings.LowerCaseSaveElementName)
33 presetList.Add(
new CampaignSettings(element));
36 else if (name == nameof(CampaignSettingDefinitions))
39 foreach (XElement subElement
in element.Elements())
41 tempDefinitions.Add(subElement.NameAsIdentifier(),
new CampaignSettingDefinitions(subElement));
46 List = presetList.ToImmutableArray();
47 definitions = tempDefinitions.ToImmutableDictionary();
50 public static bool TryGetAttribute(Identifier propertyName, Identifier attributeName, out XAttribute attribute)
53 if (definitions.TryGetValue(propertyName, out CampaignSettingDefinitions definition))
55 if (definition.Attributes.TryGetValue(attributeName, out XAttribute att))
65 internal readonly
struct CampaignSettingDefinitions
67 public readonly ImmutableDictionary<Identifier, XAttribute> Attributes;
69 public CampaignSettingDefinitions(XElement element)
71 Attributes = element.Attributes().ToImmutableDictionary(
72 a => a.NameAsIdentifier(),