Wire up a whole bunch of stuff on read

This commit is contained in:
Matt Nadareski
2020-08-23 21:10:29 -07:00
parent 79e7446266
commit a1d81a8e5f
13 changed files with 470 additions and 271 deletions

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;
/// <summary>
/// This holds all of the auxiliary types needed for proper parsing
/// </summary>
@@ -12,151 +14,248 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one ListXML adjuster
/// </summary>
[JsonObject("adjuster")]
public class ListXmlAdjuster
{
[JsonProperty("name")]
public string Name { get; set; }
public bool? Default { get; set; }
public List<ListXmlCondition> Conditions { get; set; }
public ListXmlAdjuster()
{
Conditions = new List<ListXmlCondition>();
}
[JsonProperty("default")]
public bool? Default { get; set; }
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; }
}
/// <summary>
/// Represents one ListXML analog
/// </summary>
[JsonObject("analog")]
public class ListXmlAnalog
{
[JsonProperty("mask")]
public string Mask { get; set; }
}
/// <summary>
/// Represents one ListXML chip
/// </summary>
[JsonObject("chip")]
public class ListXmlChip
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("tag")]
public string Tag { get; set; }
[JsonProperty("type")]
public string Type { get; set; } // TODO: (cpu|audio)
[JsonProperty("clock")]
public string Clock { get; set; }
}
/// <summary>
/// Represents one ListXML condition
/// </summary>
[JsonObject("condition")]
public class ListXmlCondition
{
[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 configuration
/// </summary>
[JsonObject("configuration")]
public class ListXmlConfiguration
{
[JsonProperty("name")]
public string Name { get; set; }
public string Tag { get; set; }
public string Mask { get; set; }
public List<ListXmlConfLocation> Locations { get; set; }
public List<ListXmlConfSetting> Settings { get; set; }
public ListXmlConfiguration()
{
Locations = new List<ListXmlConfLocation>();
Settings = new List<ListXmlConfSetting>();
}
[JsonProperty("tag")]
public string Tag { get; set; }
[JsonProperty("mask")]
public string Mask { get; set; }
[JsonProperty("locations")]
public List<ListXmlConfLocation> Locations { get; set; }
[JsonProperty("settings")]
public List<ListXmlConfSetting> Settings { get; set; }
}
/// <summary>
/// Represents one ListXML conflocation
/// </summary>
[JsonObject("conflocation")]
public class ListXmlConfLocation
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("number")]
public string Number { get; set; }
[JsonProperty("inverted")]
public bool? Inverted { get; set; }
}
/// <summary>
/// Represents one ListXML confsetting
/// </summary>
[JsonObject("confsetting")]
public class ListXmlConfSetting
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
[JsonProperty("default")]
public bool? Default { get; set; }
}
/// <summary>
/// Represents one ListXML control
/// </summary>
[JsonObject("control")]
public class ListXmlControl
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("player")]
public string Player { get; set; } // TODO: Int32?
[JsonProperty("buttons")]
public string Buttons { get; set; } // TODO: Int32?
[JsonProperty("regbuttons")]
public string RegButtons { get; set; } // TODO: Int32?
[JsonProperty("minimum")]
public string Minimum { get; set; } // TODO: Int32? Float?
[JsonProperty("maximum")]
public string Maximum { get; set; } // TODO: Int32? Float?
[JsonProperty("sensitivity")]
public string Sensitivity { get; set; } // TODO: Int32? Float?
[JsonProperty("keydelta")]
public string KeyDelta { get; set; } // TODO: Int32? Float?
[JsonProperty("reverse")]
public bool? Reverse { get; set; }
[JsonProperty("ways")]
public string Ways { get; set; } // TODO: Int32? Float?
[JsonProperty("ways2")]
public string Ways2 { get; set; } // TODO: Int32? Float?
[JsonProperty("ways3")]
public string Ways3 { get; set; } // TODO: Int32? Float?
}
/// <summary>
/// Represents one ListXML device
/// </summary>
[JsonObject("device")]
public class ListXmlDevice
{
[JsonProperty("type")]
public string Type { get; set; }
public string Tag { get; set; }
public string FixedImage { get; set; }
public string Mandatory { get; set; } // TODO: bool?
public string Interface { get; set; }
public List<ListXmlInstance> Instances { get; set; }
public List<ListXmlExtension> Extensions { get; set; }
public ListXmlDevice()
{
Instances = new List<ListXmlInstance>();
Extensions = new List<ListXmlExtension>();
}
[JsonProperty("tag")]
public string Tag { get; set; }
[JsonProperty("fixed_image")]
public string FixedImage { get; set; }
[JsonProperty("mandatory")]
public string Mandatory { get; set; } // TODO: bool?
[JsonProperty("interface")]
public string Interface { get; set; }
[JsonProperty("instances")]
public List<ListXmlInstance> Instances { get; set; }
[JsonProperty("extensions")]
public List<ListXmlExtension> Extensions { get; set; }
}
/// <summary>
/// Represents one ListXML deviceref
/// </summary>
[JsonObject("deviceref")]
public class ListXmlDeviceReference
{
[JsonProperty("name")]
public string Name { get; set; }
}
/// <summary>
/// Represents one ListXML display
/// </summary>
[JsonObject("display")]
public class ListXmlDisplay
{
[JsonProperty("tag")]
public string Tag { get; set; }
[JsonProperty("type")]
public string Type { get; set; } // TODO: (raster|vector|lcd|svg|unknown)
[JsonProperty("rotate")]
public string Rotate { get; set; } // TODO: (0|90|180|270) Int32?
[JsonProperty("flipx")]
public bool? FlipX { get; set; }
[JsonProperty("width")]
public string Width { get; set; } // TODO: Int32?
[JsonProperty("height")]
public string Height { get; set; } // TODO: Int32?
[JsonProperty("refresh")]
public string Refresh { get; set; } // TODO: Int32? Float?
[JsonProperty("pixclock")]
public string PixClock { get; set; } // TODO: Int32? Float?
[JsonProperty("htotal")]
public string HTotal { get; set; } // TODO: Int32? Float?
[JsonProperty("hbend")]
public string HBend { get; set; } // TODO: Int32? Float?
[JsonProperty("hstart")]
public string HStart { get; set; } // TODO: Int32? Float?
[JsonProperty("vtotal")]
public string VTotal { get; set; } // TODO: Int32? Float?
[JsonProperty("vbend")]
public string VBend { get; set; } // TODO: Int32? Float?
[JsonProperty("vstart")]
public string VStart { get; set; } // TODO: Int32? Float?
}
@@ -164,28 +263,38 @@ namespace SabreTools.Library.DatItems
/// Represents one ListXML dipswitch
/// </summary>
/// <remarks>Also used by SoftwareList</remarks>
[JsonObject("dipswitch")]
public class ListXmlDipSwitch
{
[JsonProperty("name")]
public string Name { get; set; }
public string Tag { get; set; }
public string Mask { get; set; }
public List<ListXmlDipLocation> Locations { get; set; }
public List<ListXmlDipValue> Values { get; set; }
public ListXmlDipSwitch()
{
Locations = new List<ListXmlDipLocation>();
Values = new List<ListXmlDipValue>();
}
[JsonProperty("tag")]
public string Tag { get; set; }
[JsonProperty("tag")]
public string Mask { get; set; }
[JsonProperty("locations")]
public List<ListXmlDipLocation> Locations { get; set; }
[JsonProperty("values")]
public List<ListXmlDipValue> Values { get; set; }
}
/// <summary>
/// Represents one ListXML diplocation
/// </summary>
[JsonObject("diplocation")]
public class ListXmlDipLocation
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("number")]
public string Number { get; set; }
[JsonProperty("inverted")]
public bool? Inverted { get; set; }
}
@@ -193,138 +302,187 @@ namespace SabreTools.Library.DatItems
/// Represents one ListXML dipvalue
/// </summary>
/// <remarks>Also used by SoftwareList</remarks>
[JsonObject("dipvalue")]
public class ListXmlDipValue
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
[JsonProperty("default")]
public bool? Default { get; set; }
}
/// <summary>
/// Represents one ListXML driver
/// </summary>
[JsonObject("driver")]
public class ListXmlDriver
{
[JsonProperty("status")]
public string Status { get; set; } // TODO: (good|imperfect|preliminary)
[JsonProperty("emulation")]
public string Emulation { get; set; } // TODO: (good|imperfect|preliminary)
[JsonProperty("cocktail")]
public string Cocktail { get; set; } // TODO: bool? (good|imperfect|preliminary)?
[JsonProperty("savestate")]
public string SaveState { get; set; } // TODO: (supported|unsupported)
}
/// <summary>
/// Represents one ListXML extension
/// </summary>
[JsonObject("extension")]
public class ListXmlExtension
{
[JsonProperty("name")]
public string Name { get; set; }
}
/// <summary>
/// Represents one ListXML feature
/// </summary>
[JsonObject("feature")]
public class ListXmlFeature
{
[JsonProperty("type")]
public string Type { get; set; } // TODO: (protection|palette|graphics|sound|controls|keyboard|mouse|microphone|camera|disk|printer|lan|wan|timing)
[JsonProperty("status")]
public string Status { get; set; } // TODO: (unemulated|imperfect)
[JsonProperty("overall")]
public string Overall { get; set; } // TODO: (unemulated|imperfect)
}
/// <summary>
/// Represents one ListXML info
/// </summary>
[JsonObject("info")]
public class ListXmlInfo
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
}
/// <summary>
/// Represents one ListXML input
/// </summary>
[JsonObject("input")]
public class ListXmlInput
{
[JsonProperty("service")]
public bool? Service { get; set; }
public bool? Tilt { get; set; }
public string Players { get; set; } // TODO: Int32?
public string Coins { get; set; } // TODO: Int32?
public List<ListXmlControl> Controls { get; set; }
public ListXmlInput()
{
Controls = new List<ListXmlControl>();
}
[JsonProperty("tilt")]
public bool? Tilt { get; set; }
[JsonProperty("players")]
public string Players { get; set; } // TODO: Int32?
[JsonProperty("coins")]
public string Coins { get; set; } // TODO: Int32?
[JsonProperty("controls")]
public List<ListXmlControl> Controls { get; set; }
}
/// <summary>
/// Represents one ListXML instance
/// </summary>
[JsonObject("instance")]
public class ListXmlInstance
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("briefname")]
public string BriefName { get; set; }
}
/// <summary>
/// Represents one ListXML port
/// </summary>
[JsonObject("port")]
public class ListXmlPort
{
[JsonProperty("tag")]
public string Tag { get; set; }
public List<ListXmlAnalog> Analogs { get; set; }
public ListXmlPort()
{
Analogs = new List<ListXmlAnalog>();
}
[JsonProperty("analogs")]
public List<ListXmlAnalog> Analogs { get; set; }
}
/// <summary>
/// Represents one ListXML ramoption
/// </summary>
[JsonObject("ramoption")]
public class ListXmlRamOption
{
[JsonProperty("default")]
public bool? Default { get; set; }
}
/// <summary>
/// Represents one ListXML slot
/// </summary>
[JsonObject("slot")]
public class ListXmlSlot
{
[JsonProperty("name")]
public string Name { get; set; }
public List<ListXmlSlotOption> SlotOptions { get; set; }
public ListXmlSlot()
{
SlotOptions = new List<ListXmlSlotOption>();
}
[JsonProperty("slotoptions")]
public List<ListXmlSlotOption> SlotOptions { get; set; }
}
/// <summary>
/// Represents one ListXML slotoption
/// </summary>
[JsonObject("slotoption")]
public class ListXmlSlotOption
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("devname")]
public string DeviceName { get; set; }
[JsonProperty("default")]
public bool? Default { get; set; }
}
/// <summary>
/// Represents one ListXML softwarelist
/// </summary>
[JsonObject("softwarelist")]
public class ListXmlSoftwareList
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("status")]
public string Status { get; set; } // TODO: (original|compatible)
[JsonProperty("filter")]
public string Filter { get; set; }
}
/// <summary>
/// Represents one ListXML sound
/// </summary>
[JsonObject("sound")]
public class ListXmlSound
{
[JsonProperty("channels")]
public string Channels { get; set; } // TODO: Int32?
}
@@ -335,10 +493,14 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents the OpenMSX original value
/// </summary>
[JsonObject("original")]
public class OpenMSXOriginal
{
public string Name { get; set; }
[JsonProperty("value")]
public bool? Value { get; set; }
[JsonProperty("content")]
public string Content { get; set; }
}
#endregion
@@ -348,16 +510,14 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one SoftwareList shared feature object
/// </summary>
[JsonObject("sharedfeat")]
public class SoftwareListSharedFeature
{
[JsonProperty("name")]
public string Name { get; set; }
public string Value { get; set; }
public SoftwareListSharedFeature(string name, string value)
{
Name = name;
Value = value;
}
[JsonProperty("value")]
public string Value { get; set; }
}
#endregion
@@ -371,16 +531,14 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one SoftwareList feature object
/// </summary>
[JsonObject("feature")]
public class SoftwareListFeature
{
[JsonProperty("name")]
public string Name { get; set; }
public string Value { get; set; }
public SoftwareListFeature(string name, string value)
{
Name = name;
Value = value;
}
[JsonProperty("value")]
public string Value { get; set; }
}
#endregion

View File

@@ -276,8 +276,8 @@ namespace SabreTools.Library.DatItems
// ListXML
Field.SourceFile,
Field.Runnable,
Field.Devices,
Field.SlotOptions,
Field.DeviceReferences,
Field.Slots,
Field.Infos,
// Logiqx
@@ -352,7 +352,7 @@ namespace SabreTools.Library.DatItems
#region OpenMSX
case Field.Original:
fieldValue = Original.Name;
fieldValue = Original.Content;
break;
case Field.OpenMSXSubType:
fieldValue = OpenMSXSubType.ToString();
@@ -442,7 +442,7 @@ namespace SabreTools.Library.DatItems
#region OpenMSX
if (mappings.Keys.Contains(Field.Original))
Original = new OpenMSXOriginal() { Name = mappings[Field.Original] };
Original = new OpenMSXOriginal() { Content = mappings[Field.Original] };
if (mappings.Keys.Contains(Field.OpenMSXSubType))
OpenMSXSubType = mappings[Field.OpenMSXSubType].AsOpenMSXSubType();
@@ -475,7 +475,12 @@ namespace SabreTools.Library.DatItems
foreach (string pair in pairs)
{
string[] split = pair.Split('=');
Features.Add(new SoftwareListFeature(split[0], split[1]));
var feature = new SoftwareListFeature();
feature.Name = split[0];
feature.Value = split[1];
Features.Add(feature);
}
}
@@ -725,9 +730,9 @@ namespace SabreTools.Library.DatItems
#region OpenMSX
// Filter on original
if (filter.Original.MatchesPositiveSet(Original.Name) == false)
if (filter.Original.MatchesPositiveSet(Original.Content) == false)
return false;
if (filter.Original.MatchesNegativeSet(Original.Name) == true)
if (filter.Original.MatchesNegativeSet(Original.Content) == true)
return false;
// Filter on OpenMSX subtype

View File

@@ -60,8 +60,12 @@ namespace SabreTools.Library.DatItems
SourceFile,
Runnable,
Devices,
SlotOptions,
DeviceReferences, // TODO: Double-check DeviceReferences usage
Chips, // TODO: Implement Chips usage
Displays, // TODO: Implement Displays usage
Sounds, // TODO: Implement Sounds usage
Conditions, // TODO: Implement Conditions usage
Slots, // TODO: Fix Slots usage
Infos,
#endregion

View File

@@ -155,12 +155,55 @@ namespace SabreTools.Library.DatItems
[JsonProperty("devices")]
public List<ListXmlDeviceReference> DeviceReferences { get; set; } = null;
/// <summary>
/// List of associated chips
/// </summary>
[JsonProperty("chips")]
public List<ListXmlChip> Chips { get; set; } = null;
/// <summary>
/// List of associated displays
/// </summary>
[JsonProperty("displays")]
public List<ListXmlDisplay> Displays { get; set; } = null;
/// <summary>
/// List of associated sounds
/// </summary>
[JsonProperty("sounds")]
public List<ListXmlSound> Sounds { get; set; } = null;
/// <summary>
/// List of associated conditions
/// </summary>
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; } = null;
/// <summary>
/// List of associated inputs
/// </summary>
[JsonProperty("inputs")]
public List<ListXmlInput> Inputs { get; set; } = null;
/// <summary>
/// List of associated dipswitches
/// </summary>
/// <remarks>Also in SoftwareList</remarks>
/// TODO: Order ListXML and SoftwareList outputs by area names
[JsonProperty("dipswitches")]
public List<ListXmlDipSwitch> DipSwitches { get; set; } = null;
/// <summary>
/// List of associated configurations
/// </summary>
[JsonProperty("configurations")]
public List<ListXmlConfiguration> Configurations { get; set; } = null;
/// <summary>
/// List of slot options
/// </summary>
/// TODO: Use ListXmlSlot for this...
[JsonProperty("slotoptions")]
public List<string> SlotOptions { get; set; } = null;
[JsonProperty("slots")]
public List<ListXmlSlot> Slots { get; set; } = null;
/// <summary>
/// List of info items
@@ -281,15 +324,6 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sharedfeat")]
public List<SoftwareListSharedFeature> SharedFeatures { get; set; } = null;
/// <summary>
/// List of shared feature items
/// </summary>
/// <remarks>Also in SoftwareList</remarks>
/// TODO: Move to ListXML section
/// TODO: Order ListXML and SoftwareList outputs by area names
[JsonProperty("dipswitches")]
public List<ListXmlDipSwitch> DipSwitches { get; set; } = null;
#endregion
#endregion
@@ -380,11 +414,11 @@ namespace SabreTools.Library.DatItems
case Field.Runnable:
fieldValue = Runnable.ToString();
break;
case Field.Devices:
case Field.DeviceReferences:
fieldValue = string.Join(";", DeviceReferences ?? new List<ListXmlDeviceReference>());
break;
case Field.SlotOptions:
fieldValue = string.Join(";", SlotOptions ?? new List<string>());
case Field.Slots:
fieldValue = string.Join(";", Slots ?? new List<ListXmlSlot>());
break;
case Field.Infos:
fieldValue = string.Join(";", (Infos ?? new List<ListXmlInfo>()).Select(i => $"{i.Name}={i.Value}"));
@@ -551,23 +585,16 @@ namespace SabreTools.Library.DatItems
if (mappings.Keys.Contains(Field.Runnable))
Runnable = mappings[Field.Runnable].AsRunnable();
if (mappings.Keys.Contains(Field.Devices))
if (mappings.Keys.Contains(Field.DeviceReferences))
{
if (DeviceReferences == null)
DeviceReferences = new List<ListXmlDeviceReference>();
var devices = mappings[Field.Devices].Split(';').Select(d => new ListXmlDeviceReference() { Name = d, });
var devices = mappings[Field.DeviceReferences].Split(';').Select(d => new ListXmlDeviceReference() { Name = d, });
DeviceReferences.AddRange(devices);
}
if (mappings.Keys.Contains(Field.SlotOptions))
{
if (SlotOptions == null)
SlotOptions = new List<string>();
string[] slotOptions = mappings[Field.SlotOptions].Split(';');
SlotOptions.AddRange(slotOptions);
}
// TODO: Add Field.Slot
if (mappings.Keys.Contains(Field.Infos))
{
@@ -657,7 +684,12 @@ namespace SabreTools.Library.DatItems
foreach (string pair in pairs)
{
string[] split = pair.Split('=');
SharedFeatures.Add(new SoftwareListSharedFeature(split[0], split[1]));
var sharedFeature = new SoftwareListSharedFeature();
sharedFeature.Name = split[0];
sharedFeature.Value = split[1];
SharedFeatures.Add(sharedFeature);
}
}
@@ -738,7 +770,7 @@ namespace SabreTools.Library.DatItems
SourceFile = this.SourceFile,
Runnable = this.Runnable,
DeviceReferences = this.DeviceReferences,
SlotOptions = this.SlotOptions,
Slots = this.Slots,
Infos = this.Infos,
MachineType = this.MachineType,
@@ -946,20 +978,7 @@ namespace SabreTools.Library.DatItems
return false;
}
// Filter on slot options
if (SlotOptions != null && SlotOptions.Any())
{
bool anyPositiveSlotOption = false;
bool anyNegativeSlotOption = false;
foreach (string slotOption in SlotOptions)
{
anyPositiveSlotOption |= filter.SlotOptions.MatchesPositiveSet(slotOption) != false;
anyNegativeSlotOption |= filter.SlotOptions.MatchesNegativeSet(slotOption) == false;
}
if (!anyPositiveSlotOption || anyNegativeSlotOption)
return false;
}
// TODO: Add Slot filter
// Filter on machine type
if (filter.MachineTypes.MatchesPositive(MachineType.NULL, MachineType) == false)
@@ -1152,11 +1171,11 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.Runnable))
Runnable = Runnable.NULL;
if (fields.Contains(Field.Devices))
if (fields.Contains(Field.DeviceReferences))
DeviceReferences = null;
if (fields.Contains(Field.SlotOptions))
SlotOptions = null;
if (fields.Contains(Field.Slots))
Slots = null;
if (fields.Contains(Field.Infos))
Infos = null;
@@ -1316,11 +1335,11 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.Runnable))
Runnable = machine.Runnable;
if (fields.Contains(Field.Devices))
if (fields.Contains(Field.DeviceReferences))
DeviceReferences = machine.DeviceReferences;
if (fields.Contains(Field.SlotOptions))
SlotOptions = machine.SlotOptions;
if (fields.Contains(Field.Slots))
Slots = machine.Slots;
if (fields.Contains(Field.Infos))
Infos = machine.Infos;