mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make Extra INI more consistent
This commit is contained in:
@@ -82,7 +82,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// Populate the setters using a set of field names
|
/// Populate the setters using a set of field names
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mappings">Dictionary of mappings</param>
|
/// <param name="mappings">Dictionary of mappings</param>
|
||||||
public void PopulateSettersFromDictionary(Dictionary<(string, string), string>? mappings)
|
public void PopulateSettersFromDictionary(Dictionary<string, string>? mappings)
|
||||||
{
|
{
|
||||||
// If the dictionary is null or empty, just return
|
// If the dictionary is null or empty, just return
|
||||||
if (mappings == null || mappings.Count == 0)
|
if (mappings == null || mappings.Count == 0)
|
||||||
@@ -93,7 +93,7 @@ namespace SabreTools.DatFiles
|
|||||||
// Now we loop through and get values for everything
|
// Now we loop through and get values for everything
|
||||||
foreach (var mapping in mappings)
|
foreach (var mapping in mappings)
|
||||||
{
|
{
|
||||||
string field = $"{mapping.Key.Item1}.{mapping.Key.Item2}";
|
string field = mapping.Key;
|
||||||
string value = mapping.Value;
|
string value = mapping.Value;
|
||||||
|
|
||||||
if (!SetSetter(field, value))
|
if (!SetSetter(field, value))
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace SabreTools.Filtering
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of extras to apply
|
/// List of extras to apply
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ExtraIniItem> Items { get; } = [];
|
public readonly List<ExtraIniItem> Items = [];
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -55,8 +55,6 @@ namespace SabreTools.Filtering
|
|||||||
|
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
ExtraIniItem item = new();
|
|
||||||
|
|
||||||
// If we don't even have a possible field and file combination
|
// If we don't even have a possible field and file combination
|
||||||
if (!input.Contains(":"))
|
if (!input.Contains(":"))
|
||||||
{
|
{
|
||||||
@@ -69,7 +67,7 @@ namespace SabreTools.Filtering
|
|||||||
string fileString = inputTrimmed.Substring(fieldString.Length + 1).Trim('"', ' ', '\t');
|
string fileString = inputTrimmed.Substring(fieldString.Length + 1).Trim('"', ' ', '\t');
|
||||||
|
|
||||||
FilterParser.ParseFilterId(fieldString, out string itemName, out string fieldName);
|
FilterParser.ParseFilterId(fieldString, out string itemName, out string fieldName);
|
||||||
item.FieldName = (itemName, fieldName);
|
var item = new ExtraIniItem(itemName, fieldName);
|
||||||
if (item.PopulateFromFile(fileString))
|
if (item.PopulateFromFile(fileString))
|
||||||
Items.Add(item);
|
Items.Add(item);
|
||||||
}
|
}
|
||||||
@@ -210,9 +208,9 @@ namespace SabreTools.Filtering
|
|||||||
/// Combine ExtraIni fields
|
/// Combine ExtraIni fields
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Mapping dictionary from machine name to field mapping</returns>
|
/// <returns>Mapping dictionary from machine name to field mapping</returns>
|
||||||
private Dictionary<string, Dictionary<(string, string), string>> CombineExtras()
|
private Dictionary<string, Dictionary<string, string>> CombineExtras()
|
||||||
{
|
{
|
||||||
var machineMap = new Dictionary<string, Dictionary<(string, string), string>>();
|
var machineMap = new Dictionary<string, Dictionary<string, string>>();
|
||||||
|
|
||||||
// Loop through each of the extras
|
// Loop through each of the extras
|
||||||
foreach (ExtraIniItem item in Items)
|
foreach (ExtraIniItem item in Items)
|
||||||
@@ -225,7 +223,7 @@ namespace SabreTools.Filtering
|
|||||||
if (!machineMap.ContainsKey(machineName))
|
if (!machineMap.ContainsKey(machineName))
|
||||||
machineMap[machineName] = [];
|
machineMap[machineName] = [];
|
||||||
|
|
||||||
machineMap[machineName][item.FieldName!] = value;
|
machineMap[machineName][item.Key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,35 @@ namespace SabreTools.Filtering
|
|||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Type and field to update with INI information
|
/// Item type and field to update with INI information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public (string?, string?) FieldName { get; set; } = (null, null);
|
/// <remarks>Formatted like "ItemName.FieldName"</remarks>
|
||||||
|
public string Key => $"{_itemName}.{_fieldName}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Item type to update with INI information
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _itemName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Field to update with INI information
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _fieldName;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mappings from machine names to value
|
/// Mappings from machine names to value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<string, string> Mappings { get; } = [];
|
public readonly Dictionary<string, string> Mappings = [];
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public ExtraIniItem(string itemName, string fieldName)
|
||||||
|
{
|
||||||
|
_itemName = itemName;
|
||||||
|
_fieldName = fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ Reset the internal state: reset();";
|
|||||||
|
|
||||||
// Create the extra INI
|
// Create the extra INI
|
||||||
var extraIni = new ExtraIni();
|
var extraIni = new ExtraIni();
|
||||||
var extraIniItem = new ExtraIniItem() { FieldName = (itemName, fieldName) };
|
var extraIniItem = new ExtraIniItem(itemName, fieldName);
|
||||||
extraIniItem.PopulateFromFile(extraFile);
|
extraIniItem.PopulateFromFile(extraFile);
|
||||||
extraIni.Items.Add(extraIniItem);
|
extraIni.Items.Add(extraIniItem);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user