From 349d3d1a7860d1e8c32153f346b4373a3baef154 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 24 Oct 2024 02:47:30 -0400 Subject: [PATCH] Make Extra INI more consistent --- SabreTools.DatFiles/Setter.cs | 4 ++-- SabreTools.Filtering/ExtraIni.cs | 12 +++++------- SabreTools.Filtering/ExtraIniItem.cs | 27 ++++++++++++++++++++++++--- SabreTools/Features/Batch.cs | 2 +- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/SabreTools.DatFiles/Setter.cs b/SabreTools.DatFiles/Setter.cs index 747c83e2..2a048137 100644 --- a/SabreTools.DatFiles/Setter.cs +++ b/SabreTools.DatFiles/Setter.cs @@ -82,7 +82,7 @@ namespace SabreTools.DatFiles /// Populate the setters using a set of field names /// /// Dictionary of mappings - public void PopulateSettersFromDictionary(Dictionary<(string, string), string>? mappings) + public void PopulateSettersFromDictionary(Dictionary? mappings) { // If the dictionary is null or empty, just return if (mappings == null || mappings.Count == 0) @@ -93,7 +93,7 @@ namespace SabreTools.DatFiles // Now we loop through and get values for everything foreach (var mapping in mappings) { - string field = $"{mapping.Key.Item1}.{mapping.Key.Item2}"; + string field = mapping.Key; string value = mapping.Value; if (!SetSetter(field, value)) diff --git a/SabreTools.Filtering/ExtraIni.cs b/SabreTools.Filtering/ExtraIni.cs index 771f8b6a..5747b3c1 100644 --- a/SabreTools.Filtering/ExtraIni.cs +++ b/SabreTools.Filtering/ExtraIni.cs @@ -14,7 +14,7 @@ namespace SabreTools.Filtering /// /// List of extras to apply /// - public List Items { get; } = []; + public readonly List Items = []; #endregion @@ -55,8 +55,6 @@ namespace SabreTools.Filtering foreach (string input in inputs) { - ExtraIniItem item = new(); - // If we don't even have a possible field and file combination if (!input.Contains(":")) { @@ -69,7 +67,7 @@ namespace SabreTools.Filtering string fileString = inputTrimmed.Substring(fieldString.Length + 1).Trim('"', ' ', '\t'); FilterParser.ParseFilterId(fieldString, out string itemName, out string fieldName); - item.FieldName = (itemName, fieldName); + var item = new ExtraIniItem(itemName, fieldName); if (item.PopulateFromFile(fileString)) Items.Add(item); } @@ -210,9 +208,9 @@ namespace SabreTools.Filtering /// Combine ExtraIni fields /// /// Mapping dictionary from machine name to field mapping - private Dictionary> CombineExtras() + private Dictionary> CombineExtras() { - var machineMap = new Dictionary>(); + var machineMap = new Dictionary>(); // Loop through each of the extras foreach (ExtraIniItem item in Items) @@ -225,7 +223,7 @@ namespace SabreTools.Filtering if (!machineMap.ContainsKey(machineName)) machineMap[machineName] = []; - machineMap[machineName][item.FieldName!] = value; + machineMap[machineName][item.Key] = value; } } diff --git a/SabreTools.Filtering/ExtraIniItem.cs b/SabreTools.Filtering/ExtraIniItem.cs index 4b1797e8..bce3ea01 100644 --- a/SabreTools.Filtering/ExtraIniItem.cs +++ b/SabreTools.Filtering/ExtraIniItem.cs @@ -10,14 +10,35 @@ namespace SabreTools.Filtering #region Fields /// - /// Type and field to update with INI information + /// Item type and field to update with INI information /// - public (string?, string?) FieldName { get; set; } = (null, null); + /// Formatted like "ItemName.FieldName" + public string Key => $"{_itemName}.{_fieldName}"; + + /// + /// Item type to update with INI information + /// + private readonly string _itemName; + + /// + /// Field to update with INI information + /// + private readonly string _fieldName; /// /// Mappings from machine names to value /// - public Dictionary Mappings { get; } = []; + public readonly Dictionary Mappings = []; + + #endregion + + #region Constructors + + public ExtraIniItem(string itemName, string fieldName) + { + _itemName = itemName; + _fieldName = fieldName; + } #endregion diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index 33ac1f65..92c8c565 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -342,7 +342,7 @@ Reset the internal state: reset();"; // Create the extra INI var extraIni = new ExtraIni(); - var extraIniItem = new ExtraIniItem() { FieldName = (itemName, fieldName) }; + var extraIniItem = new ExtraIniItem(itemName, fieldName); extraIniItem.PopulateFromFile(extraFile); extraIni.Items.Add(extraIniItem);