private void PopulateEnabledUniques(BaseModComponent component) { if (component is ModComponent c) { if (Configuration.UserSetComponents.ContainsKey(c.Unique)) { Configuration.UserSetComponents.Remove(c.Unique); } Configuration.UserSetComponents.Add(c.Unique, c.EnabledByDefault); } foreach (var child in component.SubComponents) { PopulateEnabledUniques(child); } }
static BaseModComponent ParseModComponent(ModIdentity identity, XElement node) { var uniqueAttr = node.Attribute("unique"); if (uniqueAttr == null) { throw new FormatException("A component must have a 'unique' attribute"); } BaseModComponent component = null; if (node.Name.LocalName.ToLowerInvariant() == "componentgroup") { component = new MutualExclusiveComponentGroup(identity, uniqueAttr.Value); } else { component = new ModComponent(identity, uniqueAttr.Value); } var displayAttr = node.Attribute("displayName"); if (displayAttr != null) { component.DisplayName = displayAttr.Value; } if (node.Name.LocalName.ToLowerInvariant() == "componentgroup") { foreach (XElement subNode in node.Elements()) { var subComponent = ParseModComponent(identity, subNode); subComponent.Parent = component; component.SubComponents.Add(subComponent); } if (!component.SubComponents.Any()) { throw new FormatException("Component group " + component.Unique + ": a 'componentgroup' must have at least one subcomponent"); } } else { var descAttr = node.Attribute("description"); if (descAttr != null) { component.Description = descAttr.Value; } var gameAttr = node.Attribute("game"); component.Files.AddRange(ParseFiles(node.Value, gameAttr == null ? null : gameAttr.Value, "Component " + component.Unique, "game")); var defaultCheckedAttr = node.Attribute("defaultChecked"); if (defaultCheckedAttr != null) { if (bool.TryParse(defaultCheckedAttr.Value, out bool isEnabled)) { component.EnabledByDefault = isEnabled; } else { throw new FormatException("Component " + component.Unique + ": '" + defaultCheckedAttr.Value + "' is not a boolean"); } } } var imagePlacement = node.Attribute("imagePlacement"); if (imagePlacement != null) { if (component is ModComponent cmpnt) { if (Enum.TryParse(imagePlacement.Value, out ImagePlacementType placement)) { cmpnt.ImagePlacement = placement; } else { throw new FormatException("Component " + component.Unique + ": '" + imagePlacement.Value + "' is not a valid value for 'imagePlacement'"); } } } return(component); }