mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Reduce nesting in comparison delegates
This commit is contained in:
@@ -439,33 +439,24 @@ namespace SabreTools.DatFiles
|
|||||||
int? ySourceIndex = y.Item2.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
int? ySourceIndex = y.Item2.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
||||||
string? yType = y.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey);
|
string? yType = y.Item2.GetStringFieldValue(Models.Metadata.DatItem.TypeKey);
|
||||||
|
|
||||||
// If machine names match, more refinement is needed
|
// If machine names don't match
|
||||||
if (xMachineName == yMachineName)
|
if (xMachineName != yMachineName)
|
||||||
{
|
return nc.Compare(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);
|
|
||||||
|
|
||||||
// Otherwise, just sort based on item names
|
// If types don't match
|
||||||
return nc.Compare(xName, yName);
|
if (xType != yType)
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, just sort based on directory name
|
|
||||||
return nc.Compare(xDirectoryName, yDirectoryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, just sort based on item type
|
|
||||||
return xType.AsEnumValue<ItemType>() - yType.AsEnumValue<ItemType>();
|
return xType.AsEnumValue<ItemType>() - yType.AsEnumValue<ItemType>();
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, just sort based on machine name
|
// If directory names don't match
|
||||||
return nc.Compare(xMachineName, yMachineName);
|
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
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -635,33 +635,24 @@ namespace SabreTools.DatItems
|
|||||||
int? ySourceIndex = y.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
int? ySourceIndex = y.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
||||||
string? yType = y.GetStringFieldValue(Models.Metadata.DatItem.TypeKey);
|
string? yType = y.GetStringFieldValue(Models.Metadata.DatItem.TypeKey);
|
||||||
|
|
||||||
// If machine names match, more refinement is needed
|
// If machine names don't match
|
||||||
if (xMachineName == yMachineName)
|
if (xMachineName != yMachineName)
|
||||||
{
|
return nc.Compare(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);
|
|
||||||
|
|
||||||
// Otherwise, just sort based on item names
|
// If types don't match
|
||||||
return nc.Compare(xName, yName);
|
if (xType != yType)
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, just sort based on directory name
|
|
||||||
return nc.Compare(xDirectoryName, yDirectoryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, just sort based on item type
|
|
||||||
return xType.AsEnumValue<ItemType>() - yType.AsEnumValue<ItemType>();
|
return xType.AsEnumValue<ItemType>() - yType.AsEnumValue<ItemType>();
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, just sort based on machine name
|
// If directory names don't match
|
||||||
return nc.Compare(xMachineName, yMachineName);
|
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
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user