Make GetSupportedTypes a property

This commit is contained in:
Matt Nadareski
2025-01-09 06:14:01 -05:00
parent f2c9139e41
commit 51bf5f9d9b
19 changed files with 199 additions and 190 deletions

View File

@@ -38,6 +38,11 @@ namespace SabreTools.DatFiles
[JsonProperty("items"), XmlElement("items")]
public ItemDictionaryDB ItemsDB { get; private set; } = new ItemDictionaryDB();
/// <summary>
/// List of supported types for writing
/// </summary>
public abstract ItemType[] SupportedTypes { get; }
#endregion
#region Logging
@@ -696,16 +701,6 @@ namespace SabreTools.DatFiles
return new KeyValuePair<long, DatItem>(item.Key, rom);
}
/// <summary>
/// Get supported types for write
/// </summary>
/// <returns>List of supported types for writing</returns>
/// TODO: Make this into a property instead of a method
protected virtual ItemType[] GetSupportedTypes()
{
return Enum.GetValues(typeof(ItemType)) as ItemType[] ?? [];
}
/// <summary>
/// Return list of required fields missing from a DatItem
/// </summary>
@@ -727,7 +722,7 @@ namespace SabreTools.DatFiles
foreach (DatItem datItem in datItems)
{
ItemType itemType = datItem.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
if (Array.Exists(GetSupportedTypes(), t => t == itemType))
if (Array.Exists(SupportedTypes, t => t == itemType))
return true;
}
@@ -749,7 +744,7 @@ namespace SabreTools.DatFiles
foreach (var datItem in datItems)
{
ItemType itemType = datItem.Value.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
if (Array.Exists(GetSupportedTypes(), t => t == itemType))
if (Array.Exists(SupportedTypes, t => t == itemType))
return true;
}
@@ -990,7 +985,7 @@ namespace SabreTools.DatFiles
// If we have an item type not in the list of supported values
string datFormat = Header?.GetFieldValue<DatFormat>(DatHeader.DatFormatKey).ToString() ?? "Unknown Format";
ItemType itemType = datItem.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue<ItemType>();
if (!Array.Exists(GetSupportedTypes(), t => t == itemType))
if (!Array.Exists(SupportedTypes, t => t == itemType))
{
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
_logger?.Verbose($"Item '{itemString}' was skipped because it was not supported in {datFormat}");