mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make exclusion list population similar to filter
This commit is contained in:
@@ -127,6 +127,104 @@ namespace SabreTools.Filtering
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Population
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Populate the exclusion objects using a set of field names
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fields">List of field names</param>
|
||||||
|
public void PopulateExclusionsFromList(List<string> fields)
|
||||||
|
{
|
||||||
|
// Instantiate the lists, if necessary
|
||||||
|
ExcludeDatHeaderFields ??= new List<DatHeaderField>();
|
||||||
|
ExcludeMachineFields ??= new List<MachineField>();
|
||||||
|
ExcludeDatItemFields ??= new List<DatItemField>();
|
||||||
|
|
||||||
|
foreach (string field in fields)
|
||||||
|
{
|
||||||
|
// If we don't even have a possible field name
|
||||||
|
if (field == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// DatHeader fields
|
||||||
|
DatHeaderField datHeaderField = field.AsDatHeaderField();
|
||||||
|
if (datHeaderField != DatHeaderField.NULL)
|
||||||
|
{
|
||||||
|
ExcludeDatHeaderFields.Add(datHeaderField);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Machine fields
|
||||||
|
MachineField machineField = field.AsMachineField();
|
||||||
|
if (machineField != MachineField.NULL)
|
||||||
|
{
|
||||||
|
ExcludeMachineFields.Add(machineField);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DatItem fields
|
||||||
|
DatItemField datItemField = field.AsDatItemField();
|
||||||
|
if (datItemField != DatItemField.NULL)
|
||||||
|
{
|
||||||
|
ExcludeDatItemFields.Add(datItemField);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we didn't match anything, log an error
|
||||||
|
logger.Warning($"The value {field} did not match any known field names. Please check the wiki for more details on supported field names.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Populate the filters objects using a set of key:value filters
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filters">List of key:value where ~key/!key is negated</param>
|
||||||
|
public void PopulateFiltersFromList(List<string> filters)
|
||||||
|
{
|
||||||
|
// Instantiate the filters, if necessary
|
||||||
|
DatHeaderFilter ??= new DatHeaderFilter();
|
||||||
|
MachineFilter ??= new MachineFilter();
|
||||||
|
DatItemFilter ??= new DatItemFilter();
|
||||||
|
|
||||||
|
foreach (string filterPair in filters)
|
||||||
|
{
|
||||||
|
(string field, string value, bool negate) = ProcessFilterPair(filterPair);
|
||||||
|
|
||||||
|
// If we don't even have a possible filter pair
|
||||||
|
if (field == null && value == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// DatHeader fields
|
||||||
|
DatHeaderField datHeaderField = field.AsDatHeaderField();
|
||||||
|
if (datHeaderField != DatHeaderField.NULL)
|
||||||
|
{
|
||||||
|
DatHeaderFilter.SetFilter(datHeaderField, value, negate);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Machine fields
|
||||||
|
MachineField machineField = field.AsMachineField();
|
||||||
|
if (machineField != MachineField.NULL)
|
||||||
|
{
|
||||||
|
MachineFilter.SetFilter(machineField, value, negate);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DatItem fields
|
||||||
|
DatItemField datItemField = field.AsDatItemField();
|
||||||
|
if (datItemField != DatItemField.NULL)
|
||||||
|
{
|
||||||
|
DatItemFilter.SetFilter(datItemField, value, negate);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we didn't match anything, log an error
|
||||||
|
logger.Warning($"The value {field} did not match any known field names. Please check the wiki for more details on supported field names.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Cleaning
|
#region Cleaning
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -342,54 +440,6 @@ namespace SabreTools.Filtering
|
|||||||
|
|
||||||
#region Filtering
|
#region Filtering
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Populate the filters objects using a set of key:value filters
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filters">List of key:value where ~key/!key is negated</param>
|
|
||||||
public void PopulateFromList(List<string> filters)
|
|
||||||
{
|
|
||||||
// Instantiate the filters, if necessary
|
|
||||||
DatHeaderFilter ??= new DatHeaderFilter();
|
|
||||||
MachineFilter ??= new MachineFilter();
|
|
||||||
DatItemFilter ??= new DatItemFilter();
|
|
||||||
|
|
||||||
foreach (string filterPair in filters)
|
|
||||||
{
|
|
||||||
(string field, string value, bool negate) = ProcessFilterPair(filterPair);
|
|
||||||
|
|
||||||
// If we don't even have a possible filter pair
|
|
||||||
if (field == null && value == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// DatHeader fields
|
|
||||||
DatHeaderField datHeaderField = field.AsDatHeaderField();
|
|
||||||
if (datHeaderField != DatHeaderField.NULL)
|
|
||||||
{
|
|
||||||
DatHeaderFilter.SetFilter(datHeaderField, value, negate);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Machine fields
|
|
||||||
MachineField machineField = field.AsMachineField();
|
|
||||||
if (machineField != MachineField.NULL)
|
|
||||||
{
|
|
||||||
MachineFilter.SetFilter(machineField, value, negate);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DatItem fields
|
|
||||||
DatItemField datItemField = field.AsDatItemField();
|
|
||||||
if (datItemField != DatItemField.NULL)
|
|
||||||
{
|
|
||||||
DatItemFilter.SetFilter(datItemField, value, negate);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we didn't match anything, log an error
|
|
||||||
logger.Warning($"The value {field} did not match any known field names. Please check the wiki for more details on supported field names.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Split the parts of a filter statement
|
/// Split the parts of a filter statement
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -2688,17 +2688,13 @@ Some special strings that can be used:
|
|||||||
Trim = GetBoolean(features, TrimValue),
|
Trim = GetBoolean(features, TrimValue),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add field exclusions
|
// Populate field exclusions
|
||||||
foreach (string fieldName in GetList(features, ExcludeFieldListValue))
|
List<string> exclusionFields = GetList(features, ExcludeFieldListValue);
|
||||||
{
|
cleaner.PopulateExclusionsFromList(exclusionFields);
|
||||||
cleaner.ExcludeDatHeaderFields.Add(fieldName.AsDatHeaderField());
|
|
||||||
cleaner.ExcludeMachineFields.Add(fieldName.AsMachineField());
|
|
||||||
cleaner.ExcludeDatItemFields.Add(fieldName.AsDatItemField());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Populate filters
|
// Populate filters
|
||||||
List<string> filterPairs = GetList(features, FilterListValue);
|
List<string> filterPairs = GetList(features, FilterListValue);
|
||||||
cleaner.PopulateFromList(filterPairs);
|
cleaner.PopulateFiltersFromList(filterPairs);
|
||||||
|
|
||||||
// Include 'of" in game filters
|
// Include 'of" in game filters
|
||||||
cleaner.MachineFilter.IncludeOfInGame = GetBoolean(features, MatchOfTagsValue);
|
cleaner.MachineFilter.IncludeOfInGame = GetBoolean(features, MatchOfTagsValue);
|
||||||
|
|||||||
Reference in New Issue
Block a user