mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Convert Slot fully over to properties
This commit is contained in:
@@ -206,6 +206,8 @@ namespace SabreTools.Data.Extensions
|
||||
return serials.Clone() as Serials;
|
||||
else if (self is SharedFeat sharedFeat)
|
||||
return sharedFeat.Clone() as SharedFeat;
|
||||
else if (self is Slot slot)
|
||||
return slot.Clone() as Slot;
|
||||
else if (self is SlotOption slotOption)
|
||||
return slotOption.Clone() as SlotOption;
|
||||
else if (self is SoftwareList softwareList)
|
||||
|
||||
@@ -1,25 +1,51 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Data.Models.Metadata
|
||||
{
|
||||
[JsonObject("slot"), XmlRoot("slot")]
|
||||
public class Slot : DatItem
|
||||
public class Slot : DatItem, ICloneable, IEquatable<Slot>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <remarks>SlotOption[]</remarks>
|
||||
[NoFilter]
|
||||
public const string SlotOptionKey = "slotoption";
|
||||
public SlotOption[]? SlotOption { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public Slot() => ItemType = ItemType.Slot;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Clone()
|
||||
{
|
||||
var obj = new Slot();
|
||||
|
||||
obj.Name = Name;
|
||||
if (SlotOption is not null)
|
||||
obj.SlotOption = Array.ConvertAll(SlotOption, i => (SlotOption)i.Clone());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(Slot? other)
|
||||
{
|
||||
// Null never matches
|
||||
if (other is null)
|
||||
return false;
|
||||
|
||||
// Properties
|
||||
if ((Name is null) ^ (other.Name is null))
|
||||
return false;
|
||||
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
// Sub-items
|
||||
// TODO: Figure out how to properly check arrays
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Default = true,
|
||||
DipLocation = [CreateMetadataDipLocation()],
|
||||
DipValue = [CreateMetadataDipValue()],
|
||||
Entry = new string[] { "entry" },
|
||||
Entry = ["entry"],
|
||||
Mask = "mask",
|
||||
Name = "name",
|
||||
Tag = "tag",
|
||||
@@ -913,7 +913,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
return new Data.Models.Metadata.Slot
|
||||
{
|
||||
Name = "name",
|
||||
[Data.Models.Metadata.Slot.SlotOptionKey] = new Data.Models.Metadata.SlotOption[] { CreateMetadataSlotOption() },
|
||||
SlotOption = [CreateMetadataSlotOption()],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1624,7 +1624,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.NotNull(slot);
|
||||
Assert.Equal("name", slot.Name);
|
||||
|
||||
SlotOption[]? slotOptions = slot.Read<SlotOption[]>(Data.Models.Metadata.Slot.SlotOptionKey);
|
||||
SlotOption[]? slotOptions = slot.SlotOption;
|
||||
Assert.NotNull(slotOptions);
|
||||
SlotOption? slotOption = Assert.Single(slotOptions);
|
||||
ValidateSlotOption(slotOption);
|
||||
|
||||
@@ -1168,7 +1168,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Assert.NotNull(slot);
|
||||
Assert.Equal("name", slot.Name);
|
||||
|
||||
Data.Models.Metadata.SlotOption[]? slotOptions = slot.ReadArray<Data.Models.Metadata.SlotOption>(Data.Models.Metadata.Slot.SlotOptionKey);
|
||||
Data.Models.Metadata.SlotOption[]? slotOptions = slot.SlotOption;
|
||||
Assert.NotNull(slotOptions);
|
||||
Data.Models.Metadata.SlotOption? slotOption = Assert.Single(slotOptions);
|
||||
ValidateMetadataSlotOption(slotOption);
|
||||
|
||||
@@ -677,8 +677,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
slotOptions.UnionWith(datItems
|
||||
.FindAll(i => i is Slot)
|
||||
.ConvertAll(i => i as Slot)
|
||||
.FindAll(s => s!.SlotOptionsSpecified)
|
||||
.SelectMany(s => s!.Read<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey)!)
|
||||
.FindAll(s => s!.SlotOptionSpecified)
|
||||
.SelectMany(s => s!.SlotOption!)
|
||||
.Select(so => so.DevName));
|
||||
|
||||
// If we're checking device references
|
||||
@@ -742,8 +742,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
|
||||
newSlotOptions.UnionWith(slotItems
|
||||
.FindAll(i => i is Slot)
|
||||
.FindAll(s => (s as Slot)!.SlotOptionsSpecified)
|
||||
.SelectMany(s => (s as Slot)!.Read<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey)!)
|
||||
.FindAll(s => (s as Slot)!.SlotOptionSpecified)
|
||||
.SelectMany(s => (s as Slot)!.SlotOption!)
|
||||
.Select(o => o.DevName!));
|
||||
|
||||
// Set new machine information and add to the current machine
|
||||
@@ -774,8 +774,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
var slotOptionItem = new SlotOption { DevName = slotOption };
|
||||
slotOptionItem.CopyMachineInformation(copyFrom);
|
||||
|
||||
var slotItem = new Slot();
|
||||
slotItem.Write<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey, [slotOptionItem]);
|
||||
var slotItem = new Slot { SlotOption = [slotOptionItem] };
|
||||
slotItem.CopyMachineInformation(copyFrom);
|
||||
|
||||
Items.AddItem(slotItem, statsOnly: false);
|
||||
@@ -832,8 +831,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
List<string?> slotOptions = items.Values
|
||||
.Where(i => i is Slot)
|
||||
.Select(i => i as Slot)
|
||||
.Where(s => s!.SlotOptionsSpecified)
|
||||
.SelectMany(s => s!.Read<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey)!)
|
||||
.Where(s => s!.SlotOptionSpecified)
|
||||
.SelectMany(s => s!.SlotOption!)
|
||||
.Select(so => so.DevName)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
@@ -910,8 +909,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
// Add to the list of new slot option names
|
||||
newSlotOptions.UnionWith(slotItems.Values
|
||||
.Where(i => i is Slot)
|
||||
.Where(s => (s as Slot)!.SlotOptionsSpecified)
|
||||
.SelectMany(s => (s as Slot)!.Read<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey)!)
|
||||
.Where(s => (s as Slot)!.SlotOptionSpecified)
|
||||
.SelectMany(s => (s as Slot)!.SlotOption!)
|
||||
.Select(o => o.DevName!));
|
||||
|
||||
// Set new machine information and add to the current machine
|
||||
@@ -942,8 +941,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
{
|
||||
var slotOptionItem = new SlotOption { DevName = slotOption };
|
||||
|
||||
var slotItem = new Slot();
|
||||
slotItem.Write<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey, [slotOptionItem]);
|
||||
var slotItem = new Slot { SlotOption = [slotOptionItem] };
|
||||
|
||||
ItemsDB.AddItem(slotItem, machine.Key, source.Key);
|
||||
}
|
||||
|
||||
@@ -23,15 +23,10 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
set => (_internal as Data.Models.Metadata.Slot)?.Name = value;
|
||||
}
|
||||
|
||||
public SlotOption[]? SlotOption { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool SlotOptionsSpecified
|
||||
{
|
||||
get
|
||||
{
|
||||
var slotOptions = Read<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey);
|
||||
return slotOptions is not null && slotOptions.Length > 0;
|
||||
}
|
||||
}
|
||||
public bool SlotOptionSpecified => SlotOption is not null && SlotOption.Length > 0;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -42,12 +37,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
public Slot(Data.Models.Metadata.Slot item) : base(item)
|
||||
{
|
||||
// Handle subitems
|
||||
var slotOptions = item.ReadArray<Data.Models.Metadata.SlotOption>(Data.Models.Metadata.Slot.SlotOptionKey);
|
||||
if (slotOptions is not null)
|
||||
{
|
||||
SlotOption[] slotOptionItems = Array.ConvertAll(slotOptions, slotOption => new SlotOption(slotOption));
|
||||
Write<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey, slotOptionItems);
|
||||
}
|
||||
if (item.SlotOption is not null)
|
||||
SlotOption = Array.ConvertAll(item.SlotOption, slotOption => new SlotOption(slotOption));;
|
||||
}
|
||||
|
||||
public Slot(Data.Models.Metadata.Slot item, Machine machine, Source source) : this(item)
|
||||
@@ -68,12 +59,8 @@ namespace SabreTools.Metadata.DatItems.Formats
|
||||
{
|
||||
var slotItem = base.GetInternalClone();
|
||||
|
||||
var slotOptions = Read<SlotOption[]?>(Data.Models.Metadata.Slot.SlotOptionKey);
|
||||
if (slotOptions is not null)
|
||||
{
|
||||
Data.Models.Metadata.SlotOption[] slotOptionItems = Array.ConvertAll(slotOptions, slotOption => slotOption.GetInternalClone());
|
||||
slotItem[Data.Models.Metadata.Slot.SlotOptionKey] = slotOptionItems;
|
||||
}
|
||||
if (SlotOption is not null)
|
||||
slotItem.SlotOption = Array.ConvertAll(SlotOption, slotOption => slotOption.GetInternalClone());
|
||||
|
||||
return slotItem;
|
||||
}
|
||||
|
||||
@@ -393,6 +393,11 @@ namespace SabreTools.Metadata
|
||||
if (!selfSharedFeat.Equals(otherSharedFeat))
|
||||
return false;
|
||||
}
|
||||
else if (self is Slot selfSlot && other is Slot otherSlot)
|
||||
{
|
||||
if (!selfSlot.Equals(otherSlot))
|
||||
return false;
|
||||
}
|
||||
else if (self is SlotOption selfSlotOption && other is SlotOption otherSlotOption)
|
||||
{
|
||||
if (!selfSlotOption.Equals(otherSlotOption))
|
||||
|
||||
@@ -597,7 +597,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
Name = item.Name,
|
||||
};
|
||||
|
||||
var slotOptions = item.Read<Data.Models.Metadata.SlotOption[]>(Data.Models.Metadata.Slot.SlotOptionKey);
|
||||
var slotOptions = item.SlotOption;
|
||||
if (slotOptions is not null && slotOptions.Length > 0)
|
||||
slot.SlotOption = Array.ConvertAll(slotOptions, ConvertFromInternalModel);
|
||||
|
||||
|
||||
@@ -622,10 +622,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
if (item.SlotOption is not null && item.SlotOption.Length > 0)
|
||||
{
|
||||
slot[Data.Models.Metadata.Slot.SlotOptionKey]
|
||||
= Array.ConvertAll(item.SlotOption, ConvertToInternalModel);
|
||||
}
|
||||
slot.SlotOption = Array.ConvertAll(item.SlotOption, ConvertToInternalModel);
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user