diff --git a/SabreTools.DatFiles/ItemDictionaryDB.cs b/SabreTools.DatFiles/ItemDictionaryDB.cs index 710c8c09..0c1c6e5b 100644 --- a/SabreTools.DatFiles/ItemDictionaryDB.cs +++ b/SabreTools.DatFiles/ItemDictionaryDB.cs @@ -439,33 +439,24 @@ namespace SabreTools.DatFiles int? ySourceIndex = y.Item2.GetFieldValue(DatItem.SourceKey)?.Index; string? yType = y.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey); - // If machine names match, more refinement is needed - if (xMachineName == yMachineName) - { - // If item types match, more refinement is needed - if (xType == yType) - { - // If item directory names match, more refinement is needed - if (xDirectoryName == yDirectoryName) - { - // If item names match, then compare on machine or source, depending on the flag - if (xName == yName) - return (norename ? nc.Compare(xMachineName, yMachineName) : (xSourceIndex - ySourceIndex) ?? 0); + // If machine names don't match + if (xMachineName != yMachineName) + return nc.Compare(xMachineName, yMachineName); - // Otherwise, just sort based on item names - return nc.Compare(xName, yName); - } - - // Otherwise, just sort based on directory name - return nc.Compare(xDirectoryName, yDirectoryName); - } - - // Otherwise, just sort based on item type + // If types don't match + if (xType != yType) return xType.AsEnumValue() - yType.AsEnumValue(); - } - // Otherwise, just sort based on machine name - return nc.Compare(xMachineName, yMachineName); + // If directory names don't match + if (xDirectoryName != yDirectoryName) + return nc.Compare(xDirectoryName, yDirectoryName); + + // If item names don't match + if (xName != yName) + return nc.Compare(xName, yName); + + // Otherwise, compare on machine or source, depending on the flag + return (norename ? nc.Compare(xMachineName, yMachineName) : (xSourceIndex - ySourceIndex) ?? 0); } catch { diff --git a/SabreTools.DatItems/DatItem.cs b/SabreTools.DatItems/DatItem.cs index 0adc4380..178da2e1 100644 --- a/SabreTools.DatItems/DatItem.cs +++ b/SabreTools.DatItems/DatItem.cs @@ -635,33 +635,24 @@ namespace SabreTools.DatItems int? ySourceIndex = y.GetFieldValue(DatItem.SourceKey)?.Index; string? yType = y.GetStringFieldValue(Models.Metadata.DatItem.TypeKey); - // If machine names match, more refinement is needed - if (xMachineName == yMachineName) - { - // If item types match, more refinement is needed - if (xType == yType) - { - // If item directory names match, more refinement is needed - if (xDirectoryName == yDirectoryName) - { - // If item names match, then compare on machine or source, depending on the flag - if (xName == yName) - return (norename ? nc.Compare(xMachineName, yMachineName) : (xSourceIndex - ySourceIndex) ?? 0); + // If machine names don't match + if (xMachineName != yMachineName) + return nc.Compare(xMachineName, yMachineName); - // Otherwise, just sort based on item names - return nc.Compare(xName, yName); - } - - // Otherwise, just sort based on directory name - return nc.Compare(xDirectoryName, yDirectoryName); - } - - // Otherwise, just sort based on item type + // If types don't match + if (xType != yType) return xType.AsEnumValue() - yType.AsEnumValue(); - } - // Otherwise, just sort based on machine name - return nc.Compare(xMachineName, yMachineName); + // If directory names don't match + if (xDirectoryName != yDirectoryName) + return nc.Compare(xDirectoryName, yDirectoryName); + + // If item names don't match + if (xName != yName) + return nc.Compare(xName, yName); + + // Otherwise, compare on machine or source, depending on the flag + return (norename ? nc.Compare(xMachineName, yMachineName) : (xSourceIndex - ySourceIndex) ?? 0); } catch {