mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Promote Analog early, promot Configuration
This commit is contained in:
173
SabreTools.Library/DatItems/Analog.cs
Normal file
173
SabreTools.Library/DatItems/Analog.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a single analog item
|
||||
/// </summary>
|
||||
[JsonObject("analog")]
|
||||
public class Analog : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Analog mask value
|
||||
/// </summary>
|
||||
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Mask { 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 Analog-specific fields
|
||||
if (mappings.Keys.Contains(Field.DatItem_Mask))
|
||||
Mask = mappings[Field.DatItem_Mask];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty Analog object
|
||||
/// </summary>
|
||||
public Analog()
|
||||
{
|
||||
ItemType = ItemType.Analog;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new Analog()
|
||||
{
|
||||
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,
|
||||
|
||||
Mask = this.Mask,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
public override bool Equals(DatItem other)
|
||||
{
|
||||
// If we don't have a Analog, return false
|
||||
if (ItemType != other.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Analog
|
||||
Analog newOther = other as Analog;
|
||||
|
||||
// If the Feature information matches
|
||||
return (Mask == newOther.Mask);
|
||||
}
|
||||
|
||||
#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 mask
|
||||
if (filter.DatItem_Mask.MatchesPositiveSet(Mask) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == 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_Mask))
|
||||
Mask = 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 Analog to replace from, ignore specific fields
|
||||
if (item.ItemType != ItemType.Analog)
|
||||
return;
|
||||
|
||||
// Cast for easier access
|
||||
Analog newItem = item as Analog;
|
||||
|
||||
// Replace the fields
|
||||
if (fields.Contains(Field.DatItem_Mask))
|
||||
Mask = newItem.Mask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
@@ -12,77 +15,87 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
#region ListXML
|
||||
|
||||
/// <summary>
|
||||
/// Represents one ListXML analog
|
||||
/// </summary>
|
||||
[JsonObject("analog")]
|
||||
public class Analog
|
||||
{
|
||||
[JsonProperty("mask")]
|
||||
public string Mask { get; set; }
|
||||
}
|
||||
|
||||
/// <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 Condition
|
||||
{
|
||||
[JsonProperty("tag")]
|
||||
public string Tag { get; set; }
|
||||
|
||||
[JsonProperty("mask")]
|
||||
public string Mask { get; set; }
|
||||
|
||||
[JsonProperty("relation")]
|
||||
public string Relation { get; set; } // TODO: (eq|ne|gt|le|lt|ge)
|
||||
|
||||
[JsonProperty("value")]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents one ListXML control
|
||||
/// </summary>
|
||||
[JsonObject("control")]
|
||||
public class Control
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Control type
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonProperty("player")]
|
||||
/// <summary>
|
||||
/// Player ID
|
||||
/// </summary>
|
||||
[JsonProperty("player", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Player { get; set; } // TODO: Int32?
|
||||
|
||||
[JsonProperty("buttons")]
|
||||
/// <summary>
|
||||
/// Button count
|
||||
/// </summary>
|
||||
[JsonProperty("buttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Buttons { get; set; } // TODO: Int32?
|
||||
|
||||
[JsonProperty("regbuttons")]
|
||||
/// <summary>
|
||||
/// Regular button count
|
||||
/// </summary>
|
||||
[JsonProperty("regbuttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string RegButtons { get; set; } // TODO: Int32?
|
||||
|
||||
[JsonProperty("minimum")]
|
||||
/// <summary>
|
||||
/// Minimum value
|
||||
/// </summary>
|
||||
[JsonProperty("minimum", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Minimum { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("maximum")]
|
||||
/// <summary>
|
||||
/// Maximum value
|
||||
/// </summary>
|
||||
[JsonProperty("maximum", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Maximum { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("sensitivity")]
|
||||
/// <summary>
|
||||
/// Sensitivity value
|
||||
/// </summary>
|
||||
[JsonProperty("sensitivity", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Sensitivity { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("keydelta")]
|
||||
/// <summary>
|
||||
/// Keypress delta
|
||||
/// </summary>
|
||||
[JsonProperty("keydelta", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string KeyDelta { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("reverse")]
|
||||
/// <summary>
|
||||
/// Determines if the control is reversed
|
||||
/// </summary>
|
||||
[JsonProperty("reverse", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Reverse { get; set; }
|
||||
|
||||
[JsonProperty("ways")]
|
||||
/// <summary>
|
||||
/// First set of ways
|
||||
/// </summary>
|
||||
[JsonProperty("ways", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Ways { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("ways2")]
|
||||
/// <summary>
|
||||
/// Second set of ways
|
||||
/// </summary>
|
||||
[JsonProperty("ways2", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Ways2 { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("ways3")]
|
||||
/// <summary>
|
||||
/// Third set of ways
|
||||
/// </summary>
|
||||
[JsonProperty("ways3", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Ways3 { get; set; } // TODO: Int32? Float?
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,26 +105,51 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("device")]
|
||||
public class Device
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Device type
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonProperty("tag")]
|
||||
/// <summary>
|
||||
/// Device tag
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Tag { get; set; }
|
||||
|
||||
[JsonProperty("fixed_image")]
|
||||
/// <summary>
|
||||
/// Fixed image format
|
||||
/// </summary>
|
||||
[JsonProperty("fixed_image", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string FixedImage { get; set; }
|
||||
|
||||
[JsonProperty("mandatory")]
|
||||
/// <summary>
|
||||
/// Determines if the devices is mandatory
|
||||
/// </summary>
|
||||
[JsonProperty("mandatory", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Mandatory { get; set; } // TODO: bool?
|
||||
|
||||
[JsonProperty("interface")]
|
||||
/// <summary>
|
||||
/// Device interface
|
||||
/// </summary>
|
||||
[JsonProperty("interface", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Interface { get; set; }
|
||||
|
||||
[JsonProperty("instances")]
|
||||
/// <summary>
|
||||
/// Device instances
|
||||
/// </summary>
|
||||
[JsonProperty("instances", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Instance> Instances { get; set; }
|
||||
|
||||
[JsonProperty("extensions")]
|
||||
/// <summary>
|
||||
/// Device extensions
|
||||
/// </summary>
|
||||
[JsonProperty("extensions", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Extension> Extensions { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -121,47 +159,93 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("display")]
|
||||
public class Display
|
||||
{
|
||||
[JsonProperty("tag")]
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Display tag
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Tag { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
/// <summary>
|
||||
/// Display type
|
||||
/// </summary>
|
||||
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Type { get; set; } // TODO: (raster|vector|lcd|svg|unknown)
|
||||
|
||||
[JsonProperty("rotate")]
|
||||
/// <summary>
|
||||
/// Display rotation
|
||||
/// </summary>
|
||||
[JsonProperty("rotate", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Rotate { get; set; } // TODO: (0|90|180|270) Int32?
|
||||
|
||||
[JsonProperty("flipx")]
|
||||
/// <summary>
|
||||
/// Determines if display is flipped in the X-coordinates
|
||||
/// </summary>
|
||||
[JsonProperty("flipx", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? FlipX { get; set; }
|
||||
|
||||
[JsonProperty("width")]
|
||||
/// <summary>
|
||||
/// Display width
|
||||
/// </summary>
|
||||
[JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Width { get; set; } // TODO: Int32?
|
||||
|
||||
[JsonProperty("height")]
|
||||
/// <summary>
|
||||
/// Display height
|
||||
/// </summary>
|
||||
[JsonProperty("height", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Height { get; set; } // TODO: Int32?
|
||||
|
||||
[JsonProperty("refresh")]
|
||||
/// <summary>
|
||||
/// Refresh rate
|
||||
/// </summary>
|
||||
[JsonProperty("refresh", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Refresh { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("pixclock")]
|
||||
/// <summary>
|
||||
/// Pixel clock timer
|
||||
/// </summary>
|
||||
[JsonProperty("pixclock", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string PixClock { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("htotal")]
|
||||
/// <summary>
|
||||
/// Total horizontal lines
|
||||
/// </summary>
|
||||
[JsonProperty("htotal", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string HTotal { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("hbend")]
|
||||
/// <summary>
|
||||
/// Horizontal blank end
|
||||
/// </summary>
|
||||
[JsonProperty("hbend", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string HBEnd { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("hbstart")]
|
||||
/// <summary>
|
||||
/// Horizontal blank start
|
||||
/// </summary>
|
||||
[JsonProperty("hbstart", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string HBStart { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("vtotal")]
|
||||
/// <summary>
|
||||
/// Total vertical lines
|
||||
/// </summary>
|
||||
[JsonProperty("vtotal", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string VTotal { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("vbend")]
|
||||
/// <summary>
|
||||
/// Vertical blank end
|
||||
/// </summary>
|
||||
[JsonProperty("vbend", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string VBEnd { get; set; } // TODO: Int32? Float?
|
||||
|
||||
[JsonProperty("vbstart")]
|
||||
/// <summary>
|
||||
/// Vertical blank start
|
||||
/// </summary>
|
||||
[JsonProperty("vbstart", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string VBStart { get; set; } // TODO: Int32? Float?
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -170,8 +254,15 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("extension")]
|
||||
public class Extension
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Extension name
|
||||
/// </summary>
|
||||
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Name { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -181,20 +272,39 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("input")]
|
||||
public class Input
|
||||
{
|
||||
[JsonProperty("service")]
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Input service ID
|
||||
/// </summary>
|
||||
[JsonProperty("service", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Service { get; set; }
|
||||
|
||||
[JsonProperty("tilt")]
|
||||
/// <summary>
|
||||
/// Determins if this has a tilt sensor
|
||||
/// </summary>
|
||||
[JsonProperty("tilt", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Tilt { get; set; }
|
||||
|
||||
[JsonProperty("players")]
|
||||
/// <summary>
|
||||
/// Number of players on the input
|
||||
/// </summary>
|
||||
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Players { get; set; } // TODO: Int32?
|
||||
|
||||
[JsonProperty("coins")]
|
||||
/// <summary>
|
||||
/// Number of coins required
|
||||
/// </summary>
|
||||
[JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Coins { get; set; } // TODO: Int32?
|
||||
|
||||
[JsonProperty("controls")]
|
||||
/// <summary>
|
||||
/// Set of controls for the input
|
||||
/// </summary>
|
||||
[JsonProperty("controls", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Control> Controls { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -203,11 +313,21 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("instance")]
|
||||
public class Instance
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Name of the instance
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("briefname")]
|
||||
/// <summary>
|
||||
/// Short name for the instance
|
||||
/// </summary>
|
||||
[JsonProperty("briefname", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string BriefName { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -216,14 +336,27 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("location")]
|
||||
public class Location
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Location name
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("number")]
|
||||
/// <summary>
|
||||
/// Location ID
|
||||
/// </summary>
|
||||
[JsonProperty("number", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Number { get; set; }
|
||||
|
||||
[JsonProperty("inverted")]
|
||||
/// <summary>
|
||||
/// Determines if location is inverted or not
|
||||
/// </summary>
|
||||
[JsonProperty("inverted", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Inverted { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -233,11 +366,21 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("port")]
|
||||
public class Port
|
||||
{
|
||||
[JsonProperty("tag")]
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Tag for the port
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Tag { get; set; }
|
||||
|
||||
[JsonProperty("analogs")]
|
||||
/// <summary>
|
||||
/// List of analogs on the port
|
||||
/// </summary>
|
||||
[JsonProperty("analogs", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Analog> Analogs { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -246,17 +389,33 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("setting")]
|
||||
public class Setting
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Setting name
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("value")]
|
||||
/// <summary>
|
||||
/// Setting value
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Value { get; set; }
|
||||
|
||||
[JsonProperty("default")]
|
||||
/// <summary>
|
||||
/// Determines if the setting is default or not
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Default { get; set; }
|
||||
|
||||
[JsonProperty("conditions")]
|
||||
/// <summary>
|
||||
/// List of conditions on the setting
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Condition> Conditions { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -265,14 +424,27 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonObject("slotoption")]
|
||||
public class SlotOption
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Slot option name
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Referenced device name
|
||||
/// </summary>
|
||||
[JsonProperty("devname")]
|
||||
public string DeviceName { get; set; }
|
||||
|
||||
[JsonProperty("default")]
|
||||
/// <summary>
|
||||
/// Determines if this slot option is default or not
|
||||
/// </summary>
|
||||
[JsonProperty("default", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public bool? Default { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
246
SabreTools.Library/DatItems/Condition.cs
Normal file
246
SabreTools.Library/DatItems/Condition.cs
Normal file
@@ -0,0 +1,246 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
/// <summary>
|
||||
/// This holds all of the auxiliary types needed for proper parsing
|
||||
/// </summary>
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a condition on a machine or other item
|
||||
/// </summary>
|
||||
[JsonObject("condition")]
|
||||
public class Condition : DatItem
|
||||
{
|
||||
// TODO: Handle obscure field mappings due to this being used *under* other items as well
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Condition tag value
|
||||
/// </summary>
|
||||
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Tag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Condition mask
|
||||
/// </summary>
|
||||
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Mask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Condition relationship
|
||||
/// </summary>
|
||||
[JsonProperty("relation", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Relation { get; set; } // TODO: (eq|ne|gt|le|lt|ge)
|
||||
|
||||
/// <summary>
|
||||
/// Condition value
|
||||
/// </summary>
|
||||
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string ConditionValue { 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 Condition-specific fields
|
||||
if (mappings.Keys.Contains(Field.DatItem_Tag))
|
||||
Tag = mappings[Field.DatItem_Tag];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_Mask))
|
||||
Mask = mappings[Field.DatItem_Mask];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_Relation))
|
||||
Relation = mappings[Field.DatItem_Relation];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_ConditionValue))
|
||||
ConditionValue = mappings[Field.DatItem_ConditionValue];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty Condition object
|
||||
/// </summary>
|
||||
public Condition()
|
||||
{
|
||||
ItemType = ItemType.Condition;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new Condition()
|
||||
{
|
||||
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,
|
||||
|
||||
Tag = this.Tag,
|
||||
Mask = this.Mask,
|
||||
Relation = this.Relation,
|
||||
ConditionValue = this.ConditionValue,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
public override bool Equals(DatItem other)
|
||||
{
|
||||
// If we don't have a Condition, return false
|
||||
if (ItemType != other.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Condition
|
||||
Condition newOther = other as Condition;
|
||||
|
||||
// If the Feature information matches
|
||||
return (Tag == newOther.Tag
|
||||
&& Mask == newOther.Mask
|
||||
&& Relation == newOther.Relation
|
||||
&& ConditionValue == newOther.ConditionValue);
|
||||
}
|
||||
|
||||
#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 tag
|
||||
if (filter.DatItem_Tag.MatchesPositiveSet(Tag) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Tag.MatchesNegativeSet(Tag) == true)
|
||||
return false;
|
||||
|
||||
// Filter on mask
|
||||
if (filter.DatItem_Mask.MatchesPositiveSet(Mask) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true)
|
||||
return false;
|
||||
|
||||
// Filter on mask
|
||||
if (filter.DatItem_Relation.MatchesPositiveSet(Relation) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Relation.MatchesNegativeSet(Relation) == true)
|
||||
return false;
|
||||
|
||||
// Filter on value
|
||||
if (filter.DatItem_ConditionValue.MatchesPositiveSet(ConditionValue) == false)
|
||||
return false;
|
||||
if (filter.DatItem_ConditionValue.MatchesNegativeSet(ConditionValue) == 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_Tag))
|
||||
Tag = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Mask))
|
||||
Mask = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Relation))
|
||||
Relation = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_ConditionValue))
|
||||
ConditionValue = 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 Condition to replace from, ignore specific fields
|
||||
if (item.ItemType != ItemType.Condition)
|
||||
return;
|
||||
|
||||
// Cast for easier access
|
||||
Condition newItem = item as Condition;
|
||||
|
||||
// Replace the fields
|
||||
if (fields.Contains(Field.DatItem_Tag))
|
||||
Tag = newItem.Tag;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Mask))
|
||||
Mask = newItem.Mask;
|
||||
|
||||
if (fields.Contains(Field.DatItem_Relation))
|
||||
Relation = newItem.Relation;
|
||||
|
||||
if (fields.Contains(Field.DatItem_ConditionValue))
|
||||
ConditionValue = newItem.ConditionValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -458,6 +458,9 @@ namespace SabreTools.Library.DatItems
|
||||
case ItemType.Adjuster:
|
||||
return new Adjuster();
|
||||
|
||||
case ItemType.Analog:
|
||||
return new Analog();
|
||||
|
||||
case ItemType.Archive:
|
||||
return new Archive();
|
||||
|
||||
@@ -470,6 +473,9 @@ namespace SabreTools.Library.DatItems
|
||||
case ItemType.Chip:
|
||||
return new Chip();
|
||||
|
||||
case ItemType.Condition:
|
||||
return new Condition();
|
||||
|
||||
case ItemType.Configuration:
|
||||
return new Configuration();
|
||||
|
||||
@@ -519,10 +525,12 @@ namespace SabreTools.Library.DatItems
|
||||
return itemType switch
|
||||
{
|
||||
ItemType.Adjuster => new Adjuster(),
|
||||
ItemType.Analog => new Analog(),
|
||||
ItemType.Archive => new Archive(),
|
||||
ItemType.BiosSet => new BiosSet(),
|
||||
ItemType.Blank => new Blank(),
|
||||
ItemType.Chip => new Chip(),
|
||||
ItemType.Condition => new Condition(),
|
||||
ItemType.Configuration => new Configuration(),
|
||||
ItemType.DeviceReference => new DeviceReference(),
|
||||
ItemType.DipSwitch => new DipSwitch(),
|
||||
|
||||
@@ -203,13 +203,6 @@ namespace SabreTools.Library.DatItems
|
||||
Machine_Display_VBEnd,
|
||||
Machine_Display_VBStart,
|
||||
|
||||
// Conditions
|
||||
Machine_Conditions,
|
||||
Machine_Condition_Tag,
|
||||
Machine_Condition_Mask,
|
||||
Machine_Condition_Relation,
|
||||
Machine_Condition_Value,
|
||||
|
||||
// Inputs
|
||||
Machine_Inputs,
|
||||
Machine_Input_Service,
|
||||
@@ -393,6 +386,9 @@ namespace SabreTools.Library.DatItems
|
||||
DatItem_Condition_Relation,
|
||||
DatItem_Condition_Value,
|
||||
|
||||
// Analog
|
||||
DatItem_Mask,
|
||||
|
||||
// BiosSet
|
||||
DatItem_Description,
|
||||
|
||||
@@ -401,8 +397,9 @@ namespace SabreTools.Library.DatItems
|
||||
DatItem_ChipType,
|
||||
DatItem_Clock,
|
||||
|
||||
// Configuration
|
||||
DatItem_Mask,
|
||||
// Condition
|
||||
DatItem_ConditionValue,
|
||||
DatItem_Relation,
|
||||
|
||||
// Configuration.Locations
|
||||
DatItem_Locations,
|
||||
@@ -489,9 +486,11 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
// "Auxiliary" item types
|
||||
Adjuster,
|
||||
Analog,
|
||||
Archive,
|
||||
BiosSet,
|
||||
Chip,
|
||||
Condition,
|
||||
Configuration,
|
||||
DeviceReference,
|
||||
DipSwitch,
|
||||
|
||||
@@ -158,12 +158,6 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonProperty("displays", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Display> Displays { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// List of associated conditions
|
||||
/// </summary>
|
||||
[JsonProperty("conditions", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Condition> Conditions { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// List of associated inputs
|
||||
/// </summary>
|
||||
@@ -535,7 +529,6 @@ namespace SabreTools.Library.DatItems
|
||||
SourceFile = this.SourceFile,
|
||||
Runnable = this.Runnable,
|
||||
Displays = this.Displays,
|
||||
Conditions = this.Conditions,
|
||||
Inputs = this.Inputs,
|
||||
Ports = this.Ports,
|
||||
Devices = this.Devices,
|
||||
@@ -1018,105 +1011,13 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
#endregion
|
||||
|
||||
#region Conditions
|
||||
|
||||
// Machine_Conditions
|
||||
if (filter.Machine_Conditions.MatchesNeutral(null, Conditions?.Any() ?? null) == false)
|
||||
return false;
|
||||
|
||||
// Machine_Condition_Tag
|
||||
if (Conditions?.Any() == true)
|
||||
{
|
||||
bool anyPositive = false;
|
||||
bool anyNegative = false;
|
||||
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
if (filter.Machine_Condition_Tag.MatchesPositiveSet(condition?.Tag) != false)
|
||||
anyPositive = true;
|
||||
if (filter.Machine_Condition_Tag.MatchesNegativeSet(condition?.Tag) == true)
|
||||
anyNegative = true;
|
||||
}
|
||||
|
||||
if (!anyPositive)
|
||||
return false;
|
||||
if (anyNegative)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Machine_Condition_Mask
|
||||
if (Conditions?.Any() == true)
|
||||
{
|
||||
bool anyPositive = false;
|
||||
bool anyNegative = false;
|
||||
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
if (filter.Machine_Condition_Mask.MatchesPositiveSet(condition?.Mask) != false)
|
||||
anyPositive = true;
|
||||
if (filter.Machine_Condition_Mask.MatchesNegativeSet(condition?.Mask) == true)
|
||||
anyNegative = true;
|
||||
}
|
||||
|
||||
if (!anyPositive)
|
||||
return false;
|
||||
if (anyNegative)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Machine_Condition_Relation
|
||||
if (Conditions?.Any() == true)
|
||||
{
|
||||
bool anyPositive = false;
|
||||
bool anyNegative = false;
|
||||
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
if (filter.Machine_Condition_Relation.MatchesPositiveSet(condition?.Relation) != false)
|
||||
anyPositive = true;
|
||||
if (filter.Machine_Condition_Relation.MatchesNegativeSet(condition?.Relation) == true)
|
||||
anyNegative = true;
|
||||
}
|
||||
|
||||
if (!anyPositive)
|
||||
return false;
|
||||
if (anyNegative)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Machine_Condition_Value
|
||||
if (Conditions?.Any() == true)
|
||||
{
|
||||
bool anyPositive = false;
|
||||
bool anyNegative = false;
|
||||
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
if (filter.Machine_Condition_Value.MatchesPositiveSet(condition?.Value) != false)
|
||||
anyPositive = true;
|
||||
if (filter.Machine_Condition_Value.MatchesNegativeSet(condition?.Value) == true)
|
||||
anyNegative = true;
|
||||
}
|
||||
|
||||
if (!anyPositive)
|
||||
return false;
|
||||
if (anyNegative)
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// TODO: Inputs
|
||||
// TODO: Inputs.Controls
|
||||
// TODO: Ports
|
||||
// TODO: Ports.Analogs
|
||||
// TODO: Drivers
|
||||
// TODO: Features
|
||||
// TODO: Devices
|
||||
// TODO: Devices.Instances
|
||||
// TODO: Devices.Extensions
|
||||
// TODO: Slots
|
||||
// TODO: Slots.SlotOptions
|
||||
|
||||
#endregion // ListXML
|
||||
|
||||
|
||||
Reference in New Issue
Block a user