mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
(Badly) use DeviceReference
This commit is contained in:
@@ -1534,8 +1534,8 @@ namespace SabreTools.Library.DatFiles
|
||||
continue;
|
||||
|
||||
// If the game has no devices, we continue
|
||||
if (Items[game][0].Machine.Devices == null
|
||||
|| Items[game][0].Machine.Devices.Count == 0
|
||||
if (Items[game][0].Machine.DeviceReferences == null
|
||||
|| Items[game][0].Machine.DeviceReferences.Count == 0
|
||||
|| (slotoptions && Items[game][0].Machine.SlotOptions == null)
|
||||
|| (slotoptions && Items[game][0].Machine.SlotOptions.Count == 0))
|
||||
{
|
||||
@@ -1543,21 +1543,21 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// Determine if the game has any devices or not
|
||||
List<string> devices = Items[game][0].Machine.Devices;
|
||||
List<string> newdevs = new List<string>();
|
||||
foreach (string device in devices)
|
||||
List<ListXmlDeviceReference> deviceReferences = Items[game][0].Machine.DeviceReferences;
|
||||
List<ListXmlDeviceReference> newdevs = new List<ListXmlDeviceReference>();
|
||||
foreach (ListXmlDeviceReference deviceReference in deviceReferences)
|
||||
{
|
||||
// If the device doesn't exist then we continue
|
||||
if (Items[device].Count == 0)
|
||||
if (Items[deviceReference.Name].Count == 0)
|
||||
continue;
|
||||
|
||||
// Otherwise, copy the items from the device to the current game
|
||||
DatItem copyFrom = Items[game][0];
|
||||
List<DatItem> devItems = Items[device];
|
||||
List<DatItem> devItems = Items[deviceReference.Name];
|
||||
foreach (DatItem item in devItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
newdevs.AddRange(datItem.Machine.Devices ?? new List<string>());
|
||||
newdevs.AddRange(datItem.Machine.DeviceReferences ?? new List<ListXmlDeviceReference>());
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
if (Items[game].Where(i => i.Name.ToLowerInvariant() == datItem.Name.ToLowerInvariant()).Count() == 0)
|
||||
{
|
||||
@@ -1568,10 +1568,10 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// Now that every device is accounted for, add the new list of devices, if they don't already exist
|
||||
foreach (string device in newdevs)
|
||||
foreach (ListXmlDeviceReference device in newdevs)
|
||||
{
|
||||
if (!Items[game][0].Machine.Devices.Contains(device))
|
||||
Items[game][0].Machine.Devices.Add(device);
|
||||
if (!Items[game][0].Machine.DeviceReferences.Select(d => d.Name).Contains(device.Name))
|
||||
Items[game][0].Machine.DeviceReferences.Add(new ListXmlDeviceReference() { Name = device.Name });
|
||||
}
|
||||
|
||||
// If we're checking slotoptions too
|
||||
|
||||
@@ -542,11 +542,11 @@ namespace SabreTools.Library.DatFiles
|
||||
machine.Runnable = jtr.ReadAsString().AsRunnable();
|
||||
break;
|
||||
case "devices":
|
||||
machine.Devices = new List<string>();
|
||||
machine.DeviceReferences = new List<ListXmlDeviceReference>();
|
||||
jtr.Read(); // Start Array
|
||||
while (!sr.EndOfStream && jtr.TokenType != JsonToken.EndArray)
|
||||
{
|
||||
machine.Devices.Add(jtr.ReadAsString());
|
||||
machine.DeviceReferences.Add(new ListXmlDeviceReference() { Name = jtr.ReadAsString() });
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1728,9 +1728,9 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
jtw.WritePropertyName("devices");
|
||||
jtw.WriteStartArray();
|
||||
foreach (string device in datItem.Machine.Devices)
|
||||
foreach (ListXmlDeviceReference device in datItem.Machine.DeviceReferences)
|
||||
{
|
||||
jtw.WriteValue(device);
|
||||
jtw.WriteValue(device.Name);
|
||||
}
|
||||
|
||||
jtw.WriteEndArray();
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace SabreTools.Library.DatFiles
|
||||
CloneOf = reader.GetAttribute("cloneof") ?? string.Empty,
|
||||
RomOf = reader.GetAttribute("romof") ?? string.Empty,
|
||||
SampleOf = reader.GetAttribute("sampleof") ?? string.Empty,
|
||||
Devices = new List<string>(),
|
||||
DeviceReferences = new List<ListXmlDeviceReference>(),
|
||||
SlotOptions = new List<string>(),
|
||||
|
||||
MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType),
|
||||
@@ -285,9 +285,7 @@ namespace SabreTools.Library.DatFiles
|
||||
var deviceReference = new ListXmlDeviceReference();
|
||||
deviceReference.Name = reader.GetAttribute("name");
|
||||
|
||||
// TODO: Retire this direct machine setter
|
||||
if (!machine.Devices.Contains(deviceReference.Name))
|
||||
machine.Devices.Add(deviceReference.Name);
|
||||
machine.DeviceReferences.Add(deviceReference);
|
||||
|
||||
reader.Read();
|
||||
break;
|
||||
|
||||
@@ -380,11 +380,11 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
|
||||
case "Machine.Devices":
|
||||
machine.Devices = new List<string>();
|
||||
machine.DeviceReferences = new List<ListXmlDeviceReference>();
|
||||
var devices = value.Split(';');
|
||||
foreach (var device in devices)
|
||||
{
|
||||
machine.Devices.Add(device);
|
||||
machine.DeviceReferences.Add(new ListXmlDeviceReference() { Name = device });
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -152,9 +152,8 @@ namespace SabreTools.Library.DatItems
|
||||
/// <summary>
|
||||
/// List of associated device names
|
||||
/// </summary>
|
||||
/// TODO: Use ListXmlDeviceReference for this...
|
||||
[JsonProperty("devices")]
|
||||
public List<string> Devices { get; set; } = null;
|
||||
public List<ListXmlDeviceReference> DeviceReferences { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// List of slot options
|
||||
@@ -382,7 +381,7 @@ namespace SabreTools.Library.DatItems
|
||||
fieldValue = Runnable.ToString();
|
||||
break;
|
||||
case Field.Devices:
|
||||
fieldValue = string.Join(";", Devices ?? new List<string>());
|
||||
fieldValue = string.Join(";", DeviceReferences ?? new List<ListXmlDeviceReference>());
|
||||
break;
|
||||
case Field.SlotOptions:
|
||||
fieldValue = string.Join(";", SlotOptions ?? new List<string>());
|
||||
@@ -554,11 +553,11 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
if (mappings.Keys.Contains(Field.Devices))
|
||||
{
|
||||
if (Devices == null)
|
||||
Devices = new List<string>();
|
||||
if (DeviceReferences == null)
|
||||
DeviceReferences = new List<ListXmlDeviceReference>();
|
||||
|
||||
string[] devices = mappings[Field.Devices].Split(';');
|
||||
Devices.AddRange(devices);
|
||||
var devices = mappings[Field.Devices].Split(';').Select(d => new ListXmlDeviceReference() { Name = d, });
|
||||
DeviceReferences.AddRange(devices);
|
||||
}
|
||||
|
||||
if (mappings.Keys.Contains(Field.SlotOptions))
|
||||
@@ -738,7 +737,7 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
SourceFile = this.SourceFile,
|
||||
Runnable = this.Runnable,
|
||||
Devices = this.Devices,
|
||||
DeviceReferences = this.DeviceReferences,
|
||||
SlotOptions = this.SlotOptions,
|
||||
Infos = this.Infos,
|
||||
MachineType = this.MachineType,
|
||||
@@ -933,14 +932,14 @@ namespace SabreTools.Library.DatItems
|
||||
return false;
|
||||
|
||||
// Filter on devices
|
||||
if (Devices != null && Devices.Any())
|
||||
if (DeviceReferences != null && DeviceReferences.Any())
|
||||
{
|
||||
bool anyPositiveDevice = false;
|
||||
bool anyNegativeDevice = false;
|
||||
foreach (string device in Devices)
|
||||
foreach (ListXmlDeviceReference device in DeviceReferences)
|
||||
{
|
||||
anyPositiveDevice |= filter.Devices.MatchesPositiveSet(device) != false;
|
||||
anyNegativeDevice |= filter.Devices.MatchesNegativeSet(device) == false;
|
||||
anyPositiveDevice |= filter.Devices.MatchesPositiveSet(device.Name) != false;
|
||||
anyNegativeDevice |= filter.Devices.MatchesNegativeSet(device.Name) == false;
|
||||
}
|
||||
|
||||
if (!anyPositiveDevice || anyNegativeDevice)
|
||||
@@ -1154,7 +1153,7 @@ namespace SabreTools.Library.DatItems
|
||||
Runnable = Runnable.NULL;
|
||||
|
||||
if (fields.Contains(Field.Devices))
|
||||
Devices = null;
|
||||
DeviceReferences = null;
|
||||
|
||||
if (fields.Contains(Field.SlotOptions))
|
||||
SlotOptions = null;
|
||||
@@ -1318,7 +1317,7 @@ namespace SabreTools.Library.DatItems
|
||||
Runnable = machine.Runnable;
|
||||
|
||||
if (fields.Contains(Field.Devices))
|
||||
Devices = machine.Devices;
|
||||
DeviceReferences = machine.DeviceReferences;
|
||||
|
||||
if (fields.Contains(Field.SlotOptions))
|
||||
SlotOptions = machine.SlotOptions;
|
||||
|
||||
Reference in New Issue
Block a user