diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index dfec5ff8..e84265bb 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -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 devices = Items[game][0].Machine.Devices; - List newdevs = new List(); - foreach (string device in devices) + List deviceReferences = Items[game][0].Machine.DeviceReferences; + List newdevs = new List(); + 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 devItems = Items[device]; + List devItems = Items[deviceReference.Name]; foreach (DatItem item in devItems) { DatItem datItem = (DatItem)item.Clone(); - newdevs.AddRange(datItem.Machine.Devices ?? new List()); + newdevs.AddRange(datItem.Machine.DeviceReferences ?? new List()); 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 diff --git a/SabreTools.Library/DatFiles/Json.cs b/SabreTools.Library/DatFiles/Json.cs index 4a7606c3..60668594 100644 --- a/SabreTools.Library/DatFiles/Json.cs +++ b/SabreTools.Library/DatFiles/Json.cs @@ -542,11 +542,11 @@ namespace SabreTools.Library.DatFiles machine.Runnable = jtr.ReadAsString().AsRunnable(); break; case "devices": - machine.Devices = new List(); + machine.DeviceReferences = new List(); 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(); diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index 3606adb7..ef9b1177 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -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(), + DeviceReferences = new List(), SlotOptions = new List(), 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; diff --git a/SabreTools.Library/DatFiles/SeparatedValue.cs b/SabreTools.Library/DatFiles/SeparatedValue.cs index d6d884b2..9a79cdac 100644 --- a/SabreTools.Library/DatFiles/SeparatedValue.cs +++ b/SabreTools.Library/DatFiles/SeparatedValue.cs @@ -380,11 +380,11 @@ namespace SabreTools.Library.DatFiles break; case "Machine.Devices": - machine.Devices = new List(); + machine.DeviceReferences = new List(); var devices = value.Split(';'); foreach (var device in devices) { - machine.Devices.Add(device); + machine.DeviceReferences.Add(new ListXmlDeviceReference() { Name = device }); } break; diff --git a/SabreTools.Library/DatItems/Machine.cs b/SabreTools.Library/DatItems/Machine.cs index 6c8b4558..7a671db0 100644 --- a/SabreTools.Library/DatItems/Machine.cs +++ b/SabreTools.Library/DatItems/Machine.cs @@ -152,9 +152,8 @@ namespace SabreTools.Library.DatItems /// /// List of associated device names /// - /// TODO: Use ListXmlDeviceReference for this... [JsonProperty("devices")] - public List Devices { get; set; } = null; + public List DeviceReferences { get; set; } = null; /// /// 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()); + fieldValue = string.Join(";", DeviceReferences ?? new List()); break; case Field.SlotOptions: fieldValue = string.Join(";", SlotOptions ?? new List()); @@ -554,11 +553,11 @@ namespace SabreTools.Library.DatItems if (mappings.Keys.Contains(Field.Devices)) { - if (Devices == null) - Devices = new List(); + if (DeviceReferences == null) + DeviceReferences = new List(); - 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;