Promote Adjuster, RamOption

This commit is contained in:
Matt Nadareski
2020-09-01 11:34:52 -07:00
parent 7c8bee8e12
commit 4204cf8457
14 changed files with 948 additions and 395 deletions

View File

@@ -0,0 +1,195 @@
using System.Collections.Generic;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
{
/// <summary>
/// Represents which Adjuster(s) is associated with a set
/// </summary>
[JsonObject("adjuster")]
public class Adjuster : DatItem
{
#region Fields
/// <summary>
/// Determine whether the value is default
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool? Default { get; set; }
/// <summary>
/// Conditions associated with the adjustment
/// </summary>
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; }
#endregion
#region Accessors
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
public override void SetFields(Dictionary<Field, string> mappings)
{
// Set base fields
base.SetFields(mappings);
// Handle Adjuster-specific fields
if (mappings.Keys.Contains(Field.DatItem_Default))
Default = mappings[Field.DatItem_Default].AsYesNo();
// TODO: Handle DatItem_Condition*
}
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Adjuster object
/// </summary>
public Adjuster()
{
Name = string.Empty;
ItemType = ItemType.Adjuster;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Adjuster()
{
Name = this.Name,
ItemType = this.ItemType,
DupeType = this.DupeType,
AltName = this.AltName,
AltTitle = this.AltTitle,
Original = this.Original,
OpenMSXSubType = this.OpenMSXSubType,
OpenMSXType = this.OpenMSXType,
Remark = this.Remark,
Boot = this.Boot,
Part = this.Part,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
AreaWidth = this.AreaWidth,
AreaEndianness = this.AreaEndianness,
Value = this.Value,
LoadFlag = this.LoadFlag,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Default = this.Default,
Conditions = this.Conditions,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a BiosSet, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Adjuster
Adjuster newOther = other as Adjuster;
// If the Adjuster information matches
return (Name == newOther.Name && Default == newOther.Default); // TODO: Handle DatItem_Condition*
}
#endregion
#region Filtering
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <returns>True if the item passed the filter, false otherwise</returns>
public override bool PassesFilter(Filter filter)
{
// Check common fields first
if (!base.PassesFilter(filter))
return false;
// Filter on default
if (filter.DatItem_Default.MatchesNeutral(null, Default) == false)
return false;
// TODO: Handle DatItem_Condition*
return true;
}
/// <summary>
/// Remove fields from the DatItem
/// </summary>
/// <param name="fields">List of Fields to remove</param>
public override void RemoveFields(List<Field> fields)
{
// Remove common fields first
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Default))
Default = null;
if (fields.Contains(Field.DatItem_Conditions))
Conditions = null;
// TODO: Handle DatItem_Condition*
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> fields)
{
// Replace common fields first
base.ReplaceFields(item, fields);
// If we don't have a Adjuster to replace from, ignore specific fields
if (item.ItemType != ItemType.Adjuster)
return;
// Cast for easier access
Adjuster newItem = item as Adjuster;
// Replace the fields
if (fields.Contains(Field.DatItem_Default))
Default = newItem.Default;
if (fields.Contains(Field.DatItem_Conditions))
Conditions = newItem.Conditions;
// TODO: Handle DatItem_Condition*
}
#endregion
}
}

View File

@@ -11,23 +11,6 @@ namespace SabreTools.Library.DatItems
#region ListXML
/// <summary>
/// Represents one ListXML adjuster
/// </summary>
/// TODO: Promote to DatItem level
[JsonObject("adjuster")]
public class ListXmlAdjuster
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("default")]
public bool? Default { get; set; }
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; }
}
/// <summary>
/// Represents one ListXML analog
/// </summary>
@@ -41,6 +24,7 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one ListXML condition
/// </summary>
/// TODO: Promote to DatItem level? (Both used at ListXML level AND under a lot of stuff)
[JsonObject("condition")]
public class ListXmlCondition
{
@@ -60,7 +44,7 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one ListXML configuration
/// </summary>
/// TODO: Promote to DatItem level
/// TODO: Promote to DatItem level (contains lists)
[JsonObject("configuration")]
public class ListXmlConfiguration
{
@@ -73,6 +57,9 @@ namespace SabreTools.Library.DatItems
[JsonProperty("mask")]
public string Mask { get; set; }
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; }
[JsonProperty("locations")]
public List<ListXmlConfLocation> Locations { get; set; }
@@ -110,6 +97,9 @@ namespace SabreTools.Library.DatItems
[JsonProperty("default")]
public bool? Default { get; set; }
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; }
}
/// <summary>
@@ -158,7 +148,7 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one ListXML device
/// </summary>
/// TODO: Promote to DatItem level (doesn't have "name" field?)
/// TODO: Promote to DatItem level (doesn't have "name" field?) (contains list)
[JsonObject("device")]
public class ListXmlDevice
{
@@ -238,7 +228,7 @@ namespace SabreTools.Library.DatItems
/// Represents one ListXML dipswitch
/// </summary>
/// <remarks>Also used by SoftwareList</remarks>
/// TODO: Promote to DatItem level
/// TODO: Promote to DatItem level (contains list)
[JsonObject("dipswitch")]
public class ListXmlDipSwitch
{
@@ -251,6 +241,9 @@ namespace SabreTools.Library.DatItems
[JsonProperty("mask")]
public string Mask { get; set; }
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; }
[JsonProperty("locations")]
public List<ListXmlDipLocation> Locations { get; set; }
@@ -289,6 +282,9 @@ namespace SabreTools.Library.DatItems
[JsonProperty("default")]
public bool? Default { get; set; }
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; }
}
/// <summary>
@@ -341,7 +337,7 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one ListXML input
/// </summary>
/// TODO: Promote to DatItem level (doesn't have "name" field?)
/// TODO: Promote to DatItem level (doesn't have "name" field?) (contains list)
[JsonObject("input")]
public class ListXmlInput
{
@@ -377,7 +373,7 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one ListXML port
/// </summary>
/// TODO: Promote to DatItem level (doesn't have "name" field?)
/// TODO: Promote to DatItem level (doesn't have "name" field?) (contains list)
[JsonObject("port")]
public class ListXmlPort
{
@@ -388,21 +384,10 @@ namespace SabreTools.Library.DatItems
public List<ListXmlAnalog> Analogs { get; set; }
}
/// <summary>
/// Represents one ListXML ramoption
/// </summary>
/// TODO: Promote to DatItem level (doesn't have "name" field?)
[JsonObject("ramoption")]
public class ListXmlRamOption
{
[JsonProperty("default")]
public bool? Default { get; set; }
}
/// <summary>
/// Represents one ListXML slot
/// </summary>
/// TODO: Promote to DatItem level
/// TODO: Promote to DatItem level (contains list)
[JsonObject("slot")]
public class ListXmlSlot
{

View File

@@ -264,15 +264,25 @@ namespace SabreTools.Library.DatItems
#region Auxiliary
// Adjuster
Field.DatItem_Default,
Field.DatItem_Conditions,
Field.DatItem_Condition_Tag,
Field.DatItem_Condition_Mask,
Field.DatItem_Condition_Relation,
Field.DatItem_Condition_Value,
// BiosSet
Field.DatItem_Description,
Field.DatItem_Default,
// Chip
Field.DatItem_Tag,
Field.DatItem_ChipType,
Field.DatItem_Clock,
// Ram Option
Field.DatItem_Content,
// Release
Field.DatItem_Language,
@@ -440,6 +450,9 @@ namespace SabreTools.Library.DatItems
#if NET_FRAMEWORK
switch (itemType)
{
case ItemType.Adjuster:
return new Adjuster();
case ItemType.Archive:
return new Archive();
@@ -461,6 +474,9 @@ namespace SabreTools.Library.DatItems
case ItemType.Media:
return new Media();
case ItemType.RamOption:
return new RamOption();
case ItemType.Release:
return new Release();

View File

@@ -223,18 +223,6 @@ namespace SabreTools.Library.DatItems
Machine_Port_Analogs,
Machine_Port_Analog_Mask,
// Adjusters
Machine_Adjusters,
Machine_Adjuster_Name,
Machine_Adjuster_Default,
// Adjusters.Conditions
Machine_Adjuster_Conditions,
Machine_Adjuster_Condition_Tag,
Machine_Adjuster_Condition_Mask,
Machine_Adjuster_Condition_Relation,
Machine_Adjuster_Condition_Value,
// Drivers
Machine_Drivers,
Machine_Driver_Status,
@@ -275,10 +263,6 @@ namespace SabreTools.Library.DatItems
Machine_Slot_SlotOption_DeviceName,
Machine_Slot_SlotOption_Default,
// RamOptions
Machine_RamOptions,
Machine_RamOption_Default,
#endregion
#region Logiqx
@@ -407,15 +391,25 @@ namespace SabreTools.Library.DatItems
#region Auxiliary
// Adjuster
DatItem_Default,
DatItem_Conditions,
DatItem_Condition_Tag,
DatItem_Condition_Mask,
DatItem_Condition_Relation,
DatItem_Condition_Value,
// BiosSet
DatItem_Description,
DatItem_Default,
// Chip
DatItem_Tag,
DatItem_ChipType,
DatItem_Clock,
// Ram Option
DatItem_Content,
// Release
DatItem_Language,
@@ -459,10 +453,12 @@ namespace SabreTools.Library.DatItems
Media,
// "Auxiliary" item types
Adjuster,
Archive,
BiosSet,
Chip,
DeviceReference,
RamOption,
Release,
Sample,
SoftwareList,

View File

@@ -196,12 +196,6 @@ namespace SabreTools.Library.DatItems
[JsonProperty("ports", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<ListXmlPort> Ports { get; set; } = null;
/// <summary>
/// List of associated adjusters
/// </summary>
[JsonProperty("adjusters", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<ListXmlAdjuster> Adjusters { get; set; } = null;
/// <summary>
/// List of associated drivers
/// </summary>
@@ -226,12 +220,6 @@ namespace SabreTools.Library.DatItems
[JsonProperty("slots", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<ListXmlSlot> Slots { get; set; } = null;
/// <summary>
/// List of ramoptions
/// </summary>
[JsonProperty("ramoptions", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<ListXmlRamOption> RamOptions { get; set; } = null;
#endregion
#region Logiqx Fields
@@ -591,12 +579,10 @@ namespace SabreTools.Library.DatItems
DipSwitches = this.DipSwitches,
Configurations = this.Configurations,
Ports = this.Ports,
Adjusters = this.Adjusters,
Drivers = this.Drivers,
Features = this.Features,
Devices = this.Devices,
Slots = this.Slots,
RamOptions = this.RamOptions,
#endregion

View File

@@ -0,0 +1,196 @@
using System.Collections.Generic;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
{
/// <summary>
/// Represents which RAM option(s) is associated with a set
/// </summary>
[JsonObject("ramoption")]
public class RamOption : DatItem
{
#region Fields
/// <summary>
/// Determine whether the RamOption is default
/// </summary>
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool? Default { get; set; }
/// <summary>
/// Determines the content of the RamOption
/// </summary>
[JsonProperty("content", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Content { get; set; }
#endregion
#region Accessors
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
public override void SetFields(Dictionary<Field, string> mappings)
{
// Set base fields
base.SetFields(mappings);
// Handle BiosSet-specific fields
if (mappings.Keys.Contains(Field.DatItem_Default))
Default = mappings[Field.DatItem_Default].AsYesNo();
if (mappings.Keys.Contains(Field.DatItem_Content))
Content = mappings[Field.DatItem_Content];
}
#endregion
#region Constructors
/// <summary>
/// Create a default, empty RamOption object
/// </summary>
public RamOption()
{
Name = string.Empty;
ItemType = ItemType.RamOption;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new RamOption()
{
Name = this.Name,
ItemType = this.ItemType,
DupeType = this.DupeType,
AltName = this.AltName,
AltTitle = this.AltTitle,
Original = this.Original,
OpenMSXSubType = this.OpenMSXSubType,
OpenMSXType = this.OpenMSXType,
Remark = this.Remark,
Boot = this.Boot,
Part = this.Part,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
AreaWidth = this.AreaWidth,
AreaEndianness = this.AreaEndianness,
Value = this.Value,
LoadFlag = this.LoadFlag,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Default = this.Default,
Content = this.Content,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a RamOption, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a RamOption
RamOption newOther = other as RamOption;
// If the BiosSet information matches
return (Name == newOther.Name && Default == newOther.Default && Content == newOther.Content);
}
#endregion
#region Filtering
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <returns>True if the item passed the filter, false otherwise</returns>
public override bool PassesFilter(Filter filter)
{
// Check common fields first
if (!base.PassesFilter(filter))
return false;
// Filter on default
if (filter.DatItem_Default.MatchesNeutral(null, Default) == false)
return false;
// Filter on content
if (filter.DatItem_Content.MatchesPositiveSet(Content) == false)
return false;
if (filter.DatItem_Content.MatchesNegativeSet(Content) == true)
return false;
return true;
}
/// <summary>
/// Remove fields from the DatItem
/// </summary>
/// <param name="fields">List of Fields to remove</param>
public override void RemoveFields(List<Field> fields)
{
// Remove common fields first
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Default))
Default = null;
if (fields.Contains(Field.DatItem_Content))
Content = null;
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> fields)
{
// Replace common fields first
base.ReplaceFields(item, fields);
// If we don't have a BiosSet to replace from, ignore specific fields
if (item.ItemType != ItemType.RamOption)
return;
// Cast for easier access
RamOption newItem = item as RamOption;
// Replace the fields
if (fields.Contains(Field.DatItem_Default))
Default = newItem.Default;
if (fields.Contains(Field.DatItem_Content))
Content = newItem.Content;
}
#endregion
}
}