mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Flatten merge and make consistent across implementations
This commit is contained in:
@@ -123,75 +123,6 @@ namespace SabreTools.DatItems
|
||||
/// <returns>Clone of the DatItem</returns>
|
||||
public abstract object Clone();
|
||||
|
||||
/// <summary>
|
||||
/// Conditionally copy all machine information from another item
|
||||
/// </summary>
|
||||
/// <param name="item">Existing item to copy information from</param>
|
||||
/// <remarks>
|
||||
/// The cases when Machine data is updated:
|
||||
/// - Current machine is a clone of the other machine
|
||||
/// - Current machine is a rom of the other machine
|
||||
/// </remarks>
|
||||
public void ConditionalUpdateMachine(DatItem item)
|
||||
{
|
||||
// Get the machines for the two items
|
||||
Machine? selfMachine = GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
Machine? itemMachine = item.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
|
||||
// If either machine is missing
|
||||
if (selfMachine == null || itemMachine == null)
|
||||
return;
|
||||
|
||||
// Get the required strings
|
||||
string? selfCloneOf = selfMachine.GetStringFieldValue(Models.Metadata.Machine.CloneOfKey);
|
||||
string? selfRomOf = selfMachine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
||||
string? otherMachineName = itemMachine.GetStringFieldValue(Models.Metadata.Machine.NameKey);
|
||||
|
||||
// If the other machine has no name
|
||||
if (otherMachineName == null)
|
||||
return;
|
||||
|
||||
// If the current machine is a child of the new machine, use the new machine instead
|
||||
if (selfCloneOf == otherMachineName)
|
||||
{
|
||||
CopyMachineInformation(item);
|
||||
SetName(item.GetName());
|
||||
}
|
||||
else if (selfRomOf == otherMachineName)
|
||||
{
|
||||
CopyMachineInformation(item);
|
||||
SetName(item.GetName());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conditionally copy all source information from another item
|
||||
/// </summary>
|
||||
/// <param name="item">Existing item to copy information from</param>
|
||||
/// <remarks>
|
||||
/// The cases when Source data is updated:
|
||||
/// - Current source data has an index higher than the other item
|
||||
/// </remarks>
|
||||
public void ConditionalUpdateSource(DatItem item)
|
||||
{
|
||||
// Get the sources for comparison
|
||||
Source? selfSource = GetFieldValue<Source?>(DatItem.SourceKey);
|
||||
Source? itemSource = item.GetFieldValue<Source?>(DatItem.SourceKey);
|
||||
|
||||
// If either source is missing
|
||||
if (selfSource == null || itemSource == null)
|
||||
return;
|
||||
|
||||
// Use the new source if less than
|
||||
if (selfSource.Index > itemSource.Index)
|
||||
{
|
||||
SetFieldValue<Source?>(DatItem.SourceKey, itemSource.Clone() as Source);
|
||||
CopyMachineInformation(item);
|
||||
SetName(item.GetName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy all machine information over in one shot
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user