mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Make inverted DiskArea less impactful
This commit is contained in:
@@ -98,7 +98,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DipSwitch? dipSwitch = Array.Find(datItems, item => item is DipSwitch dipSwitch && dipSwitch.PartInterface is null) as DipSwitch;
|
||||
ValidateDipSwitch(dipSwitch);
|
||||
|
||||
Disk? disk = Array.Find(datItems, item => item is Disk disk && !disk.DiskAreaSpecified && disk.PartInterface is null) as Disk;
|
||||
Disk? disk = Array.Find(datItems, item => item is Disk disk && disk.DiskAreaName is null && disk.PartInterface is null) as Disk;
|
||||
ValidateDisk(disk);
|
||||
|
||||
Display? display = Array.Find(datItems, item => item is Display display && display.AspectX is null) as Display;
|
||||
@@ -131,9 +131,9 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.Equal("name", partDipSwitch.PartName);
|
||||
|
||||
// All other fields are tested separately
|
||||
Disk? partDisk = Array.Find(datItems, item => item is Disk disk && disk.DiskAreaSpecified && disk.PartInterface is not null) as Disk;
|
||||
Disk? partDisk = Array.Find(datItems, item => item is Disk disk && disk.DiskAreaName is not null && disk.PartInterface is not null) as Disk;
|
||||
Assert.NotNull(partDisk);
|
||||
ValidateDiskArea(partDisk.DiskArea);
|
||||
Assert.Equal("name", partDisk.DiskAreaName);
|
||||
Assert.Equal("interface", partDisk.PartInterface);
|
||||
Assert.Equal("name", partDisk.PartName);
|
||||
|
||||
|
||||
@@ -193,19 +193,12 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
{
|
||||
Disk item = new Disk(CreateMetadataDisk());
|
||||
item.CopyMachineInformation(machine);
|
||||
item.DiskArea = CreateDiskArea(machine);
|
||||
item.DiskAreaName = "name";
|
||||
item.PartInterface = "interface";
|
||||
item.PartName = "name";
|
||||
return item;
|
||||
}
|
||||
|
||||
private static DiskArea CreateDiskArea(Machine machine)
|
||||
{
|
||||
DiskArea item = new DiskArea(CreateMetadataDiskArea());
|
||||
item.CopyMachineInformation(machine);
|
||||
return item;
|
||||
}
|
||||
|
||||
private static Display CreateDisplay(Machine machine)
|
||||
{
|
||||
Display item = new Display(CreateMetadataDisplay());
|
||||
|
||||
@@ -638,7 +638,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
{
|
||||
foreach (var diskArea in diskAreas)
|
||||
{
|
||||
var diskAreaitem = new DiskArea(diskArea, machine, source);
|
||||
var disks = diskArea.Disk;
|
||||
if (disks is null)
|
||||
continue;
|
||||
@@ -651,7 +650,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
|
||||
var diskItem = new Disk(disk, machine, source)
|
||||
{
|
||||
DiskArea = diskAreaitem,
|
||||
DiskAreaName = diskArea.Name,
|
||||
PartInterface = item.Interface,
|
||||
PartName = item.Name,
|
||||
};
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
|
||||
// Add Part mapping
|
||||
if (dipSwitch.PartInterface is not null || dipSwitch.PartName is not null)
|
||||
partMappings[new Data.Models.Metadata.Part { Interface = dipSwitch.PartInterface, Name = dipSwitch.PartName}] = dipSwitchItem;
|
||||
partMappings[new Data.Models.Metadata.Part { Interface = dipSwitch.PartInterface, Name = dipSwitch.PartName }] = dipSwitchItem;
|
||||
|
||||
break;
|
||||
case DatItems.Formats.Disk disk:
|
||||
@@ -148,7 +148,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
machine.Disk = [.. machine.Disk, diskItem];
|
||||
|
||||
// Add Part and DiskArea mappings
|
||||
if ((disk.PartInterface is not null || disk.PartName is not null) && disk.DiskArea is not null)
|
||||
if ((disk.PartInterface is not null || disk.PartName is not null) && disk.DiskAreaName is not null)
|
||||
{
|
||||
var partItemInternal = new Data.Models.Metadata.Part
|
||||
{
|
||||
@@ -156,7 +156,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
Name = disk.PartName,
|
||||
};
|
||||
partMappings[partItemInternal] = diskItem;
|
||||
diskAreaMappings[partItemInternal] = (disk.DiskArea.GetInternalClone(), diskItem);
|
||||
diskAreaMappings[partItemInternal] = (new Data.Models.Metadata.DiskArea { Name = disk.DiskAreaName }, diskItem);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -193,7 +193,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
|
||||
// Add Part mapping
|
||||
if (partFeature.PartInterface is not null || partFeature.PartName is not null)
|
||||
partMappings[new Data.Models.Metadata.Part { Interface = partFeature.PartInterface, Name = partFeature.PartName}] = partFeatureItem;
|
||||
partMappings[new Data.Models.Metadata.Part { Interface = partFeature.PartInterface, Name = partFeature.PartName }] = partFeatureItem;
|
||||
|
||||
break;
|
||||
case DatItems.Formats.Port port:
|
||||
@@ -477,7 +477,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
|
||||
// Add Part mapping
|
||||
if (dipSwitch.PartInterface is not null || dipSwitch.PartName is not null)
|
||||
partMappings[new Data.Models.Metadata.Part { Interface = dipSwitch.PartInterface, Name = dipSwitch.PartName}] = dipSwitchItem;
|
||||
partMappings[new Data.Models.Metadata.Part { Interface = dipSwitch.PartInterface, Name = dipSwitch.PartName }] = dipSwitchItem;
|
||||
|
||||
break;
|
||||
case DatItems.Formats.Disk disk:
|
||||
@@ -486,7 +486,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
machine.Disk = [.. machine.Disk, diskItem];
|
||||
|
||||
// Add Part and DiskArea mappings
|
||||
if ((disk.PartInterface is not null || disk.PartName is not null) && disk.DiskArea is not null)
|
||||
if ((disk.PartInterface is not null || disk.PartName is not null) && disk.DiskAreaName is not null)
|
||||
{
|
||||
var partItemInternal = new Data.Models.Metadata.Part
|
||||
{
|
||||
@@ -494,7 +494,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
Name = disk.PartName,
|
||||
};
|
||||
partMappings[partItemInternal] = diskItem;
|
||||
diskAreaMappings[partItemInternal] = (disk.DiskArea.GetInternalClone(), diskItem);
|
||||
diskAreaMappings[partItemInternal] = (new Data.Models.Metadata.DiskArea { Name = disk.DiskAreaName }, diskItem);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -531,7 +531,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
|
||||
// Add Part mapping
|
||||
if (partFeature.PartInterface is not null || partFeature.PartName is not null)
|
||||
partMappings[new Data.Models.Metadata.Part { Interface = partFeature.PartInterface, Name = partFeature.PartName}] = partFeatureItem;
|
||||
partMappings[new Data.Models.Metadata.Part { Interface = partFeature.PartInterface, Name = partFeature.PartName }] = partFeatureItem;
|
||||
|
||||
break;
|
||||
case DatItems.Formats.Port port:
|
||||
|
||||
@@ -151,15 +151,8 @@ namespace SabreTools.Metadata.DatFiles.Formats
|
||||
missingFields.Add(nameof(Data.Models.Metadata.Part.Interface));
|
||||
}
|
||||
|
||||
if (!disk.DiskAreaSpecified)
|
||||
{
|
||||
if (disk.DiskAreaName is null)
|
||||
missingFields.Add(nameof(Data.Models.Metadata.DiskArea.Name));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(disk.DiskArea!.Name))
|
||||
missingFields.Add(nameof(Data.Models.Metadata.DiskArea.Name));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(disk.Name))
|
||||
missingFields.Add(nameof(Data.Models.Metadata.Disk.Name));
|
||||
|
||||
@@ -10,15 +10,13 @@ namespace SabreTools.Metadata.DatItems.Formats.Test
|
||||
[Fact]
|
||||
public void ConvertToRomTest()
|
||||
{
|
||||
DiskArea diskArea = new DiskArea { Name = "name" };
|
||||
|
||||
Machine machine = new Machine { Name = "name" };
|
||||
|
||||
Source source = new Source(0, "source");
|
||||
|
||||
Disk disk = new Disk
|
||||
{
|
||||
DiskArea = diskArea,
|
||||
DiskAreaName = "name",
|
||||
DupeType = DupeType.All | DupeType.External,
|
||||
Machine = machine,
|
||||
MD5 = HashType.MD5.ZeroString,
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace SabreTools.Metadata.DatItems
|
||||
[XmlInclude(typeof(DipSwitch))]
|
||||
[XmlInclude(typeof(DipValue))]
|
||||
[XmlInclude(typeof(Disk))]
|
||||
[XmlInclude(typeof(DiskArea))]
|
||||
[XmlInclude(typeof(Display))]
|
||||
[XmlInclude(typeof(Driver))]
|
||||
[XmlInclude(typeof(Feature))]
|
||||
|
||||
@@ -15,11 +15,7 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public DiskArea? DiskArea { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool DiskAreaSpecified
|
||||
=> DiskArea is not null && !string.IsNullOrEmpty(DiskArea.Name);
|
||||
public string? DiskAreaName { get; set; }
|
||||
|
||||
public string? Flags
|
||||
{
|
||||
@@ -146,9 +142,9 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
var rom = new Rom(_internal.ConvertToRom()!);
|
||||
|
||||
// Create a DataArea if there was an existing DiskArea
|
||||
if (DiskArea is not null)
|
||||
if (DiskAreaName is not null)
|
||||
{
|
||||
var dataArea = new DataArea { Name = DiskArea.Name };
|
||||
var dataArea = new DataArea { Name = DiskAreaName };
|
||||
rom.DataArea = dataArea;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user