Add ControlType, fix a bunch of numerics

This commit is contained in:
Matt Nadareski
2020-09-06 23:00:13 -07:00
parent aa414bc3cd
commit 5d5520dbdd
16 changed files with 323 additions and 248 deletions

View File

@@ -699,56 +699,20 @@ namespace SabreTools.Library.DatFiles
case "control":
var control = new Control
{
ControlType = reader.GetAttribute("type"),
RegButtons = reader.GetAttribute("regbuttons"),
ControlType = reader.GetAttribute("type").AsControlType(),
Player = Sanitizer.CleanLong(reader.GetAttribute("player")),
Buttons = Sanitizer.CleanLong(reader.GetAttribute("buttons")),
RequiredButtons = Sanitizer.CleanLong(reader.GetAttribute("reqbuttons")),
Minimum = Sanitizer.CleanLong(reader.GetAttribute("minimum")),
Maximum = Sanitizer.CleanLong(reader.GetAttribute("maximum")),
Sensitivity = Sanitizer.CleanLong(reader.GetAttribute("sensitivity")),
KeyDelta = Sanitizer.CleanLong(reader.GetAttribute("keydelta")),
Reverse = reader.GetAttribute("reverse").AsYesNo(),
Ways = reader.GetAttribute("ways"),
Ways2 = reader.GetAttribute("ways2"),
Ways3 = reader.GetAttribute("ways3"),
};
// Set the player
if (reader.GetAttribute("player") != null)
{
if (Int64.TryParse(reader.GetAttribute("player"), out long player))
control.Player = player;
}
// Set the buttons
if (reader.GetAttribute("buttons") != null)
{
if (Int64.TryParse(reader.GetAttribute("buttons"), out long buttons))
control.Buttons = buttons;
}
// Set the minimum
if (reader.GetAttribute("minimum") != null)
{
if (Int64.TryParse(reader.GetAttribute("minimum"), out long minimum))
control.Minimum = minimum;
}
// Set the maximum
if (reader.GetAttribute("maximum") != null)
{
if (Int64.TryParse(reader.GetAttribute("maximum"), out long maximum))
control.Maximum = maximum;
}
// Set the sensitivity
if (reader.GetAttribute("sensitivity") != null)
{
if (Int64.TryParse(reader.GetAttribute("sensitivity"), out long sensitivity))
control.Sensitivity = sensitivity;
}
// Set the keydelta
if (reader.GetAttribute("keydelta") != null)
{
if (Int64.TryParse(reader.GetAttribute("keydelta"), out long keyDelta))
control.KeyDelta = keyDelta;
}
input.Controls.Add(control);
reader.Read();
@@ -1608,10 +1572,10 @@ namespace SabreTools.Library.DatFiles
foreach (var control in input.Controls)
{
xtw.WriteStartElement("control");
xtw.WriteOptionalAttributeString("type", control.ControlType);
xtw.WriteOptionalAttributeString("type", control.ControlType.FromControlType());
xtw.WriteOptionalAttributeString("player", control.Player?.ToString());
xtw.WriteOptionalAttributeString("buttons", control.Buttons?.ToString());
xtw.WriteOptionalAttributeString("regbuttons", control.RegButtons);
xtw.WriteOptionalAttributeString("reqbuttons", control.RequiredButtons?.ToString());
xtw.WriteOptionalAttributeString("minimum", control.Minimum?.ToString());
xtw.WriteOptionalAttributeString("maximum", control.Maximum?.ToString());
xtw.WriteOptionalAttributeString("sensitivity", control.Sensitivity?.ToString());

View File

@@ -466,7 +466,7 @@ namespace SabreTools.Library.DatFiles
{
// Prepare all internal variables
string releaseNumber = string.Empty, duplicateid;
long size = -1;
long? size = null;
List<Rom> datItems = new List<Rom>();
Machine machine = new Machine();
@@ -510,9 +510,7 @@ namespace SabreTools.Library.DatFiles
break;
case "romsize":
if (!Int64.TryParse(reader.ReadElementContentAsString(), out size))
size = -1;
size = Sanitizer.CleanLong(reader.ReadElementContentAsString());
break;
case "publisher":

View File

@@ -7,6 +7,7 @@ using System.Text;
using SabreTools.Library.Data;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles
{
@@ -328,15 +329,10 @@ namespace SabreTools.Library.DatFiles
9 - merge name
*/
string[] rominfo = line.Split('¬');
// Try getting the size separately
if (!Int64.TryParse(rominfo[7], out long size))
size = 0;
Rom rom = new Rom
{
Name = rominfo[5],
Size = size,
Size = Sanitizer.CleanLong(rominfo[7]),
CRC = rominfo[6],
ItemStatus = ItemStatus.None,

View File

@@ -400,6 +400,7 @@ namespace SabreTools.Library.DatFiles
Name = reader.GetAttribute("name"),
Tag = reader.GetAttribute("tag"),
ChipType = reader.GetAttribute("chiptype").AsChipType(),
Clock = Sanitizer.CleanLong(reader.GetAttribute("clock")),
Source = new Source
{
@@ -408,13 +409,6 @@ namespace SabreTools.Library.DatFiles
},
};
// Set the clock
if (reader.GetAttribute("clock") != null)
{
if (Int64.TryParse(reader.GetAttribute("clock"), out long clock))
(datItem as Chip).Clock = clock;
}
break;
case "configuration":
@@ -1504,10 +1498,10 @@ namespace SabreTools.Library.DatFiles
foreach (var control in input.Controls)
{
xtw.WriteStartElement("control");
xtw.WriteOptionalAttributeString("type", control.ControlType);
xtw.WriteOptionalAttributeString("type", control.ControlType.FromControlType());
xtw.WriteOptionalAttributeString("player", control.Player?.ToString());
xtw.WriteOptionalAttributeString("buttons", control.Buttons?.ToString());
xtw.WriteOptionalAttributeString("regbuttons", control.RegButtons);
xtw.WriteOptionalAttributeString("reqbuttons", control.RequiredButtons?.ToString());
xtw.WriteOptionalAttributeString("minimum", control.Minimum?.ToString());
xtw.WriteOptionalAttributeString("maximum", control.Maximum?.ToString());
xtw.WriteOptionalAttributeString("sensitivity", control.Sensitivity?.ToString());

View File

@@ -255,23 +255,11 @@ namespace SabreTools.Library.DatFiles
var dataArea = new DataArea
{
Name = reader.GetAttribute("name"),
Size = Sanitizer.CleanLong(reader.GetAttribute("size")),
Width = Sanitizer.CleanLong(reader.GetAttribute("width")),
Endianness = reader.GetAttribute("endianness").AsEndianness(),
};
// Set the size
if (reader.GetAttribute("size") != null)
{
if (Int64.TryParse(reader.GetAttribute("width"), out long size))
dataArea.Size = size;
}
// Set the width
if (reader.GetAttribute("width") != null)
{
if (Int64.TryParse(reader.GetAttribute("width"), out long width))
dataArea.Width = width;
}
List<DatItem> roms = ReadDataArea(reader.ReadSubtree(), dataArea);
// If we got valid roms, add them to the list

View File

@@ -76,10 +76,7 @@ namespace SabreTools.Library.DatItems
ChipType = mappings[Field.DatItem_ChipType].AsChipType();
if (mappings.Keys.Contains(Field.DatItem_Clock))
{
if (Int64.TryParse(mappings[Field.DatItem_Clock], out long clock))
Clock = clock;
}
Clock = Sanitizer.CleanLong(mappings[Field.DatItem_Clock]);
}
#endregion
@@ -198,9 +195,11 @@ namespace SabreTools.Library.DatItems
return false;
// DatItem_Clock
if (filter.DatItem_Clock.MatchesPositive(null, Clock) == false)
if (filter.DatItem_Clock.MatchesNeutral(null, Clock) == false)
return false;
if (filter.DatItem_Clock.MatchesNegative(null, Clock) == true)
else if (filter.DatItem_Clock.MatchesPositive(null, Clock) == false)
return false;
else if (filter.DatItem_Clock.MatchesNegative(null, Clock) == false)
return false;
return true;

View File

@@ -17,56 +17,55 @@ namespace SabreTools.Library.DatItems
#region Fields
/// <summary>
/// Control type
/// General type of input
/// </summary>
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string ControlType { get; set; }
public ControlType ControlType { get; set; }
/// <summary>
/// Player ID
/// Player which the input belongs to
/// </summary>
[JsonProperty("player", DefaultValueHandling = DefaultValueHandling.Ignore)]
public long? Player { get; set; }
/// <summary>
/// Button count
/// Total number of buttons
/// </summary>
[JsonProperty("buttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
public long? Buttons { get; set; }
/// <summary>
/// Regular button count
/// Total number of non-optional buttons
/// </summary>
/// <remarks>Couldn't find this used in newest ListXML</remarks>
[JsonProperty("regbuttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string RegButtons { get; set; } // TODO: Int32?
[JsonProperty("reqbuttons", DefaultValueHandling = DefaultValueHandling.Ignore)]
public long? RequiredButtons { get; set; }
/// <summary>
/// Minimum value
/// Analog minimum value
/// </summary>
[JsonProperty("minimum", DefaultValueHandling = DefaultValueHandling.Ignore)]
public long? Minimum { get; set; }
/// <summary>
/// Maximum value
/// Analog maximum value
/// </summary>
[JsonProperty("maximum", DefaultValueHandling = DefaultValueHandling.Ignore)]
public long? Maximum { get; set; }
/// <summary>
/// Sensitivity value
/// Default analog sensitivity
/// </summary>
[JsonProperty("sensitivity", DefaultValueHandling = DefaultValueHandling.Ignore)]
public long? Sensitivity { get; set; }
/// <summary>
/// Keypress delta
/// Default analog keydelta
/// </summary>
[JsonProperty("keydelta", DefaultValueHandling = DefaultValueHandling.Ignore)]
public long? KeyDelta { get; set; }
/// <summary>
/// Determines if the control is reversed
/// Default analog reverse setting
/// </summary>
[JsonProperty("reverse", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool? Reverse { get; set; }
@@ -104,46 +103,28 @@ namespace SabreTools.Library.DatItems
// Handle Control-specific fields
if (mappings.Keys.Contains(Field.DatItem_Control_Type))
ControlType = mappings[Field.DatItem_Control_Type];
ControlType = mappings[Field.DatItem_Control_Type].AsControlType();
if (mappings.Keys.Contains(Field.DatItem_Control_Player))
{
if (Int64.TryParse(mappings[Field.DatItem_Control_Player], out long player))
Player = player;
}
Player = Sanitizer.CleanLong(mappings[Field.DatItem_Control_Player]);
if (mappings.Keys.Contains(Field.DatItem_Control_Buttons))
{
if (Int64.TryParse(mappings[Field.DatItem_Control_Buttons], out long buttons))
Buttons = buttons;
}
Buttons = Sanitizer.CleanLong(mappings[Field.DatItem_Control_Buttons]);
if (mappings.Keys.Contains(Field.DatItem_Control_RegButtons))
RegButtons = mappings[Field.DatItem_Control_RegButtons];
if (mappings.Keys.Contains(Field.DatItem_Control_RequiredButtons))
RequiredButtons = Sanitizer.CleanLong(mappings[Field.DatItem_Control_RequiredButtons]);
if (mappings.Keys.Contains(Field.DatItem_Control_Minimum))
{
if (Int64.TryParse(mappings[Field.DatItem_Control_Minimum], out long minimum))
Minimum = minimum;
}
Minimum = Sanitizer.CleanLong(mappings[Field.DatItem_Control_Minimum]);
if (mappings.Keys.Contains(Field.DatItem_Control_Maximum))
{
if (Int64.TryParse(mappings[Field.DatItem_Control_Maximum], out long maximum))
Maximum = maximum;
}
Maximum = Sanitizer.CleanLong(mappings[Field.DatItem_Control_Maximum]);
if (mappings.Keys.Contains(Field.DatItem_Control_Sensitivity))
{
if (Int64.TryParse(mappings[Field.DatItem_Control_Sensitivity], out long sensitivity))
Sensitivity = sensitivity;
}
Sensitivity = Sanitizer.CleanLong(mappings[Field.DatItem_Control_Sensitivity]);
if (mappings.Keys.Contains(Field.DatItem_Control_KeyDelta))
{
if (Int64.TryParse(mappings[Field.DatItem_Control_KeyDelta], out long keyDelta))
KeyDelta = keyDelta;
}
KeyDelta = Sanitizer.CleanLong(mappings[Field.DatItem_Control_KeyDelta]);
if (mappings.Keys.Contains(Field.DatItem_Control_Reverse))
Reverse = mappings[Field.DatItem_Control_Reverse].AsYesNo();
@@ -188,7 +169,7 @@ namespace SabreTools.Library.DatItems
ControlType = this.ControlType,
Player = this.Player,
Buttons = this.Buttons,
RegButtons = this.RegButtons,
RequiredButtons = this.RequiredButtons,
Minimum = this.Minimum,
Maximum = this.Maximum,
Sensitivity = this.Sensitivity,
@@ -217,7 +198,7 @@ namespace SabreTools.Library.DatItems
return (ControlType == newOther.ControlType
&& Player == newOther.Player
&& Buttons == newOther.Buttons
&& RegButtons == newOther.RegButtons
&& RequiredButtons == newOther.RequiredButtons
&& Minimum == newOther.Minimum
&& Maximum == newOther.Maximum
&& Sensitivity == newOther.Sensitivity
@@ -244,51 +225,65 @@ namespace SabreTools.Library.DatItems
return false;
// Filter on control type
if (filter.DatItem_Control_Type.MatchesPositiveSet(ControlType) == false)
if (filter.DatItem_Control_Type.MatchesPositive(ControlType.NULL, ControlType) == false)
return false;
if (filter.DatItem_Control_Type.MatchesNegativeSet(ControlType) == true)
if (filter.DatItem_Control_Type.MatchesNegative(ControlType.NULL, ControlType) == true)
return false;
// Filter on display type
if (filter.DatItem_Control_Player.MatchesPositive(null, Player) == false)
// Filter on player
if (filter.DatItem_Control_Player.MatchesNeutral(null, Player) == false)
return false;
if (filter.DatItem_Control_Player.MatchesNegative(null, Player) == true)
else if (filter.DatItem_Control_Player.MatchesPositive(null, Player) == false)
return false;
else if (filter.DatItem_Control_Player.MatchesNegative(null, Player) == false)
return false;
// Filter on buttons
if (filter.DatItem_Control_Buttons.MatchesPositive(null, Buttons) == false)
if (filter.DatItem_Control_Buttons.MatchesNeutral(null, Buttons) == false)
return false;
if (filter.DatItem_Control_Buttons.MatchesNegative(null, Buttons) == true)
else if (filter.DatItem_Control_Buttons.MatchesPositive(null, Buttons) == false)
return false;
else if (filter.DatItem_Control_Buttons.MatchesNegative(null, Buttons) == false)
return false;
// Filter on regbuttons
if (filter.DatItem_Control_RegButtons.MatchesPositiveSet(RegButtons) == false)
// Filter on reqbuttons
if (filter.DatItem_Control_ReqButtons.MatchesNeutral(null, RequiredButtons) == false)
return false;
if (filter.DatItem_Control_RegButtons.MatchesNegativeSet(RegButtons) == true)
else if (filter.DatItem_Control_ReqButtons.MatchesPositive(null, RequiredButtons) == false)
return false;
else if (filter.DatItem_Control_ReqButtons.MatchesNegative(null, RequiredButtons) == false)
return false;
// Filter on minimum
if (filter.DatItem_Control_Minimum.MatchesPositive(null, Minimum) == false)
if (filter.DatItem_Control_Minimum.MatchesNeutral(null, Minimum) == false)
return false;
if (filter.DatItem_Control_Minimum.MatchesNegative(null, Minimum) == true)
else if (filter.DatItem_Control_Minimum.MatchesPositive(null, Minimum) == false)
return false;
else if (filter.DatItem_Control_Minimum.MatchesNegative(null, Minimum) == false)
return false;
// Filter on maximum
if (filter.DatItem_Control_Maximum.MatchesPositive(null, Maximum) == false)
if (filter.DatItem_Control_Maximum.MatchesNeutral(null, Maximum) == false)
return false;
if (filter.DatItem_Control_Maximum.MatchesNegative(null, Maximum) == true)
else if (filter.DatItem_Control_Maximum.MatchesPositive(null, Maximum) == false)
return false;
else if (filter.DatItem_Control_Maximum.MatchesNegative(null, Maximum) == false)
return false;
// Filter on sensitivity
if (filter.DatItem_Control_Sensitivity.MatchesPositive(null, Sensitivity) == false)
if (filter.DatItem_Control_Sensitivity.MatchesNeutral(null, Sensitivity) == false)
return false;
if (filter.DatItem_Control_Sensitivity.MatchesNegative(null, Sensitivity) == true)
else if (filter.DatItem_Control_Sensitivity.MatchesPositive(null, Sensitivity) == false)
return false;
else if (filter.DatItem_Control_Sensitivity.MatchesNegative(null, Sensitivity) == false)
return false;
// Filter on keydelta
if (filter.DatItem_Control_KeyDelta.MatchesPositive(null, KeyDelta) == false)
if (filter.DatItem_Control_KeyDelta.MatchesNeutral(null, KeyDelta) == false)
return false;
if (filter.DatItem_Control_KeyDelta.MatchesNegative(null, KeyDelta) == true)
else if (filter.DatItem_Control_KeyDelta.MatchesPositive(null, KeyDelta) == false)
return false;
else if (filter.DatItem_Control_KeyDelta.MatchesNegative(null, KeyDelta) == false)
return false;
// Filter on reverse
@@ -327,7 +322,7 @@ namespace SabreTools.Library.DatItems
// Remove the fields
if (fields.Contains(Field.DatItem_Control_Type))
ControlType = null;
ControlType = ControlType.NULL;
if (fields.Contains(Field.DatItem_Control_Player))
Player = null;
@@ -335,8 +330,8 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Control_Buttons))
Buttons = null;
if (fields.Contains(Field.DatItem_Control_RegButtons))
RegButtons = null;
if (fields.Contains(Field.DatItem_Control_RequiredButtons))
RequiredButtons = null;
if (fields.Contains(Field.DatItem_Control_Minimum))
Minimum = null;
@@ -394,8 +389,8 @@ namespace SabreTools.Library.DatItems
if (fields.Contains(Field.DatItem_Control_Buttons))
Buttons = newItem.Buttons;
if (fields.Contains(Field.DatItem_Control_RegButtons))
RegButtons = newItem.RegButtons;
if (fields.Contains(Field.DatItem_Control_RequiredButtons))
RequiredButtons = newItem.RequiredButtons;
if (fields.Contains(Field.DatItem_Control_Minimum))
Minimum = newItem.Minimum;

View File

@@ -152,7 +152,7 @@ namespace SabreTools.Library.DatItems
Field.DatItem_Control_Type,
Field.DatItem_Control_Player,
Field.DatItem_Control_Buttons,
Field.DatItem_Control_RegButtons,
Field.DatItem_Control_RequiredButtons,
Field.DatItem_Control_Minimum,
Field.DatItem_Control_Maximum,
Field.DatItem_Control_Sensitivity,

View File

@@ -69,16 +69,10 @@ namespace SabreTools.Library.DatItems
Name = mappings[Field.DatItem_AreaName];
if (mappings.Keys.Contains(Field.DatItem_AreaSize))
{
if (Int64.TryParse(mappings[Field.DatItem_AreaSize], out long areaSize))
Size = areaSize;
}
Size = Sanitizer.CleanLong(mappings[Field.DatItem_AreaSize]);
if (mappings.Keys.Contains(Field.DatItem_AreaWidth))
{
if (Int64.TryParse(mappings[Field.DatItem_AreaWidth], out long areaWidth))
Width = areaWidth;
}
Width = Sanitizer.CleanLong(mappings[Field.DatItem_AreaWidth]);
if (mappings.Keys.Contains(Field.DatItem_AreaEndianness))
Endianness = mappings[Field.DatItem_AreaEndianness].AsEndianness();
@@ -196,9 +190,11 @@ namespace SabreTools.Library.DatItems
return false;
// Filter on area byte width
if (filter.DatItem_AreaWidth.MatchesPositive(null, Width) == false)
if (filter.DatItem_AreaWidth.MatchesNeutral(null, Width) == false)
return false;
if (filter.DatItem_AreaWidth.MatchesNegative(null, Width) == true)
else if (filter.DatItem_AreaWidth.MatchesPositive(null, Width) == false)
return false;
else if (filter.DatItem_AreaWidth.MatchesNegative(null, Width) == false)
return false;
// Filter on area endianness

View File

@@ -123,25 +123,16 @@ namespace SabreTools.Library.DatItems
DisplayType = mappings[Field.DatItem_DisplayType].AsDisplayType();
if (mappings.Keys.Contains(Field.DatItem_Rotate))
{
if (Int64.TryParse(mappings[Field.DatItem_Rotate], out long rotate))
Rotate = rotate;
}
Rotate = Sanitizer.CleanLong(mappings[Field.DatItem_Rotate]);
if (mappings.Keys.Contains(Field.DatItem_FlipX))
FlipX = mappings[Field.DatItem_FlipX].AsYesNo();
if (mappings.Keys.Contains(Field.DatItem_Width))
{
if (Int64.TryParse(mappings[Field.DatItem_Width], out long width))
Width = width;
}
Width = Sanitizer.CleanLong(mappings[Field.DatItem_Width]);
if (mappings.Keys.Contains(Field.DatItem_Height))
{
if (Int64.TryParse(mappings[Field.DatItem_Height], out long height))
Height = height;
}
Height = Sanitizer.CleanLong(mappings[Field.DatItem_Height]);
if (mappings.Keys.Contains(Field.DatItem_Refresh))
{
@@ -150,46 +141,25 @@ namespace SabreTools.Library.DatItems
}
if (mappings.Keys.Contains(Field.DatItem_PixClock))
{
if (Int64.TryParse(mappings[Field.DatItem_PixClock], out long pixClock))
PixClock = pixClock;
}
PixClock = Sanitizer.CleanLong(mappings[Field.DatItem_PixClock]);
if (mappings.Keys.Contains(Field.DatItem_HTotal))
{
if (Int64.TryParse(mappings[Field.DatItem_HTotal], out long hTotal))
HTotal = hTotal;
}
HTotal = Sanitizer.CleanLong(mappings[Field.DatItem_HTotal]);
if (mappings.Keys.Contains(Field.DatItem_HBEnd))
{
if (Int64.TryParse(mappings[Field.DatItem_HBEnd], out long hbEnd))
HBEnd = hbEnd;
}
HBEnd = Sanitizer.CleanLong(mappings[Field.DatItem_HBEnd]);
if (mappings.Keys.Contains(Field.DatItem_HBStart))
{
if (Int64.TryParse(mappings[Field.DatItem_HBStart], out long hbStart))
HBStart = hbStart;
}
HBStart = Sanitizer.CleanLong(mappings[Field.DatItem_HBStart]);
if (mappings.Keys.Contains(Field.DatItem_VTotal))
{
if (Int64.TryParse(mappings[Field.DatItem_VTotal], out long vTotal))
VTotal = vTotal;
}
VTotal = Sanitizer.CleanLong(mappings[Field.DatItem_VTotal]);
if (mappings.Keys.Contains(Field.DatItem_VBEnd))
{
if (Int64.TryParse(mappings[Field.DatItem_VBEnd], out long vbEnd))
VBEnd = vbEnd;
}
VBEnd = Sanitizer.CleanLong(mappings[Field.DatItem_VBEnd]);
if (mappings.Keys.Contains(Field.DatItem_VBStart))
{
if (Int64.TryParse(mappings[Field.DatItem_VBStart], out long vbStart))
VBStart = vbStart;
}
VBStart = Sanitizer.CleanLong(mappings[Field.DatItem_VBStart]);
}
#endregion
@@ -294,9 +264,11 @@ namespace SabreTools.Library.DatItems
return false;
// Filter on rotation
if (filter.DatItem_Rotate.MatchesPositive(null, Rotate) == false)
if (filter.DatItem_Rotate.MatchesNeutral(null, Rotate) == false)
return false;
if (filter.DatItem_Rotate.MatchesNegative(null, Rotate) == true)
else if (filter.DatItem_Rotate.MatchesPositive(null, Rotate) == false)
return false;
else if (filter.DatItem_Rotate.MatchesNegative(null, Rotate) == false)
return false;
// Filter on flipx
@@ -304,63 +276,83 @@ namespace SabreTools.Library.DatItems
return false;
// Filter on width
if (filter.DatItem_Width.MatchesPositiveSet(Width) == false)
if (filter.DatItem_Width.MatchesNeutral(null, Width) == false)
return false;
if (filter.DatItem_Width.MatchesNegativeSet(Width) == true)
else if (filter.DatItem_Width.MatchesPositive(null, Width) == false)
return false;
else if (filter.DatItem_Width.MatchesNegative(null, Width) == false)
return false;
// Filter on height
if (filter.DatItem_Height.MatchesPositiveSet(Height) == false)
if (filter.DatItem_Height.MatchesNeutral(null, Height) == false)
return false;
if (filter.DatItem_Height.MatchesNegativeSet(Height) == true)
else if (filter.DatItem_Height.MatchesPositive(null, Height) == false)
return false;
else if (filter.DatItem_Height.MatchesNegative(null, Height) == false)
return false;
// Filter on refresh
if (filter.DatItem_Refresh.MatchesPositive(null, Refresh) == false)
if (filter.DatItem_Refresh.MatchesNeutral(null, Refresh) == false)
return false;
if (filter.DatItem_Refresh.MatchesNegative(null, Refresh) == true)
else if (filter.DatItem_Refresh.MatchesPositive(null, Refresh) == false)
return false;
else if (filter.DatItem_Refresh.MatchesNegative(null, Refresh) == false)
return false;
// Filter on pixclock
if (filter.DatItem_PixClock.MatchesPositive(null, PixClock) == false)
if (filter.DatItem_PixClock.MatchesNeutral(null, PixClock) == false)
return false;
if (filter.DatItem_PixClock.MatchesNegative(null, PixClock) == true)
else if (filter.DatItem_PixClock.MatchesPositive(null, PixClock) == false)
return false;
else if (filter.DatItem_PixClock.MatchesNegative(null, PixClock) == false)
return false;
// Filter on htotal
if (filter.DatItem_HTotal.MatchesPositive(null, HTotal) == false)
if (filter.DatItem_HTotal.MatchesNeutral(null, HTotal) == false)
return false;
if (filter.DatItem_HTotal.MatchesNegative(null, HTotal) == true)
else if (filter.DatItem_HTotal.MatchesPositive(null, HTotal) == false)
return false;
else if (filter.DatItem_HTotal.MatchesNegative(null, HTotal) == false)
return false;
// Filter on hbend
if (filter.DatItem_HBEnd.MatchesPositive(null, HBEnd) == false)
if (filter.DatItem_HBEnd.MatchesNeutral(null, HBEnd) == false)
return false;
if (filter.DatItem_HBEnd.MatchesNegative(null, HBEnd) == true)
else if (filter.DatItem_HBEnd.MatchesPositive(null, HBEnd) == false)
return false;
else if (filter.DatItem_HBEnd.MatchesNegative(null, HBEnd) == false)
return false;
// Filter on hbstart
if (filter.DatItem_HBStart.MatchesPositive(null, HBStart) == false)
if (filter.DatItem_HBStart.MatchesNeutral(null, HBStart) == false)
return false;
if (filter.DatItem_HBStart.MatchesNegative(null, HBStart) == true)
else if (filter.DatItem_HBStart.MatchesPositive(null, HBStart) == false)
return false;
else if (filter.DatItem_HBStart.MatchesNegative(null, HBStart) == false)
return false;
// Filter on vtotal
if (filter.DatItem_VTotal.MatchesPositive(null, VTotal) == false)
if (filter.DatItem_VTotal.MatchesNeutral(null, VTotal) == false)
return false;
if (filter.DatItem_VTotal.MatchesNegative(null, VTotal) == true)
else if (filter.DatItem_VTotal.MatchesPositive(null, VTotal) == false)
return false;
else if (filter.DatItem_VTotal.MatchesNegative(null, VTotal) == false)
return false;
// Filter on vbend
if (filter.DatItem_VBEnd.MatchesPositive(null, VBEnd) == false)
if (filter.DatItem_VBEnd.MatchesNeutral(null, VBEnd) == false)
return false;
if (filter.DatItem_VBEnd.MatchesNegative(null, VBEnd) == true)
else if (filter.DatItem_VBEnd.MatchesPositive(null, VBEnd) == false)
return false;
else if (filter.DatItem_VBEnd.MatchesNegative(null, VBEnd) == false)
return false;
// Filter on vbstart
if (filter.DatItem_VBStart.MatchesPositive(null, VBStart) == false)
if (filter.DatItem_VBStart.MatchesNeutral(null, VBStart) == false)
return false;
if (filter.DatItem_VBStart.MatchesNegative(null, VBStart) == true)
else if (filter.DatItem_VBStart.MatchesPositive(null, VBStart) == false)
return false;
else if (filter.DatItem_VBStart.MatchesNegative(null, VBStart) == false)
return false;
return true;

View File

@@ -17,6 +17,34 @@ namespace SabreTools.Library.DatItems
Audio = 1 << 1,
}
/// <summary>
/// Determine the control type
/// </summary>
[Flags]
public enum ControlType
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
Joy = 1 << 0,
Stick = 1 << 1,
Paddle = 1 << 2,
Pedal = 1 << 3,
Lightgun = 1 << 4,
Positional = 1 << 5,
Dial = 1 << 6,
Trackball = 1 << 7,
Mouse = 1 << 8,
OnlyButtons = 1 << 9,
Keypad = 1 << 10,
Keyboard = 1 << 11,
Mahjong = 1 << 12,
Hanafuda = 1 << 13,
Gambling = 1 << 14,
}
/// <summary>
/// Determine the display type
/// </summary>
@@ -338,7 +366,7 @@ namespace SabreTools.Library.DatItems
DatItem_Control_Type,
DatItem_Control_Player,
DatItem_Control_Buttons,
DatItem_Control_RegButtons,
DatItem_Control_RequiredButtons,
DatItem_Control_Minimum,
DatItem_Control_Maximum,
DatItem_Control_Sensitivity,

View File

@@ -67,16 +67,10 @@ namespace SabreTools.Library.DatItems
Tilt = mappings[Field.DatItem_Tilt].AsYesNo();
if (mappings.Keys.Contains(Field.DatItem_Players))
{
if (Int64.TryParse(mappings[Field.DatItem_Players], out long players))
Players = players;
}
Players = Sanitizer.CleanLong(mappings[Field.DatItem_Players]);
if (mappings.Keys.Contains(Field.DatItem_Coins))
{
if (Int64.TryParse(mappings[Field.DatItem_Coins], out long coins))
Coins = coins;
}
Coins = Sanitizer.CleanLong(mappings[Field.DatItem_Coins]);
if (Controls != null)
{

View File

@@ -297,10 +297,7 @@ namespace SabreTools.Library.DatItems
Bios = mappings[Field.DatItem_Bios];
if (mappings.Keys.Contains(Field.DatItem_Size))
{
if (Int64.TryParse(mappings[Field.DatItem_Size], out long size))
Size = size;
}
Size = Sanitizer.CleanLong(mappings[Field.DatItem_Size]);
if (mappings.Keys.Contains(Field.DatItem_CRC))
CRC = mappings[Field.DatItem_CRC];

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
@@ -16,7 +17,7 @@ namespace SabreTools.Library.DatItems
#region Fields
/// <summary>
/// Number of channels
/// Number of speakers or channels
/// </summary>
[JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore)]
public long? Channels { get; set; }
@@ -36,10 +37,7 @@ namespace SabreTools.Library.DatItems
// Handle Sound-specific fields
if (mappings.Keys.Contains(Field.DatItem_Channels))
{
if (Int64.TryParse(mappings[Field.DatItem_Channels], out long channels))
Channels = channels;
}
Channels = Sanitizer.CleanLong(mappings[Field.DatItem_Channels]);
}
#endregion

View File

@@ -169,10 +169,10 @@ namespace SabreTools.Library.Filtering
public FilterItem<string> DatItem_Condition_Value { get; private set; } = new FilterItem<string>();
// Control
public FilterItem<string> DatItem_Control_Type { get; private set; } = new FilterItem<string>();
public FilterItem<ControlType> DatItem_Control_Type { get; private set; } = new FilterItem<ControlType>() { Positive = ControlType.NULL, Negative = ControlType.NULL };
public FilterItem<long?> DatItem_Control_Player { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
public FilterItem<long?> DatItem_Control_Buttons { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
public FilterItem<string> DatItem_Control_RegButtons { get; private set; } = new FilterItem<string>();
public FilterItem<long?> DatItem_Control_ReqButtons { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
public FilterItem<long?> DatItem_Control_Minimum { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
public FilterItem<long?> DatItem_Control_Maximum { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
public FilterItem<long?> DatItem_Control_Sensitivity { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
@@ -742,7 +742,11 @@ namespace SabreTools.Library.Filtering
// Control
case Field.DatItem_Control_Type:
SetStringFilter(DatItem_Control_Type, value, negate);
if (negate)
DatItem_Control_Type.Negative |= value.AsControlType();
else
DatItem_Control_Type.Positive |= value.AsControlType();
break;
case Field.DatItem_Control_Player:
@@ -753,8 +757,8 @@ namespace SabreTools.Library.Filtering
SetLongFilter(DatItem_Control_Buttons, value, negate);
break;
case Field.DatItem_Control_RegButtons:
SetStringFilter(DatItem_Control_RegButtons, value, negate);
case Field.DatItem_Control_RequiredButtons:
SetLongFilter(DatItem_Control_ReqButtons, value, negate);
break;
case Field.DatItem_Control_Minimum:

View File

@@ -95,6 +95,72 @@ namespace SabreTools.Library.Tools
#endif
}
/// <summary>
/// Get ControlType value from input string
/// </summary>
/// <param name="controlType">String to get value from</param>
/// <returns>ControlType value corresponding to the string</returns>
public static ControlType AsControlType(this string controlType)
{
#if NET_FRAMEWORK
switch (controlType?.ToLowerInvariant())
{
case "joy":
return ControlType.Joy;
case "stick":
return ControlType.Stick;
case "paddle":
return ControlType.Paddle;
case "pedal":
return ControlType.Pedal;
case "lightgun":
return ControlType.Lightgun;
case "positional":
return ControlType.Positional;
case "dial":
return ControlType.Dial;
case "trackball":
return ControlType.Trackball;
case "mouse":
return ControlType.Mouse;
case "only_buttons":
return ControlType.OnlyButtons;
case "keypad":
return ControlType.Keypad;
case "keyboard":
return ControlType.Keyboard;
case "mahjong":
return ControlType.Mahjong;
case "hanafuda":
return ControlType.Hanafuda;
case "gambling":
return ControlType.Gambling;
default:
return ControlType.NULL;
}
#else
return controlType?.ToLowerInvariant() switch
{
"joy" => ControlType.Joy,
"stick" => ControlType.Stick,
"paddle" => ControlType.Paddle,
"pedal" => ControlType.Pedal,
"lightgun" => ControlType.Lightgun,
"positional" => ControlType.Positional,
"dial" => ControlType.Dial,
"trackball" => ControlType.Trackball,
"mouse" => ControlType.Mouse,
"only_buttons" => ControlType.OnlyButtons,
"keypad" => ControlType.Keypad,
"keyboard" => ControlType.Keyboard,
"mahjong" => ControlType.Mahjong,
"hanafuda" => ControlType.Hanafuda,
"gambling" => ControlType.Gambling,
_ => ControlType.NULL,
};
#endif
}
/// <summary>
/// Get DatFormat value from input string
/// </summary>
@@ -956,8 +1022,8 @@ namespace SabreTools.Library.Tools
case "control_buttons":
return Field.DatItem_Control_Buttons;
case "control_regbuttons":
return Field.DatItem_Control_RegButtons;
case "control_reqbuttons":
return Field.DatItem_Control_RequiredButtons;
case "control_minimum":
return Field.DatItem_Control_Minimum;
@@ -2254,6 +2320,72 @@ namespace SabreTools.Library.Tools
#endif
}
/// <summary>
/// Get string value from input ControlType
/// </summary>
/// <param name="controlType">ControlType to get value from</param>
/// <returns>String value corresponding to the ControlType</returns>
public static string FromControlType(this ControlType controlType)
{
#if NET_FRAMEWORK
switch (controlType)
{
case ControlType.Joy:
return "joy";
case ControlType.Stick:
return "stick";
case ControlType.Paddle:
return "paddle";
case ControlType.Pedal:
return "pedal";
case ControlType.Lightgun:
return "lightgun";
case ControlType.Positional:
return "positional";
case ControlType.Dial:
return "dial";
case ControlType.Trackball:
return "trackball";
case ControlType.Mouse:
return "mouse";
case ControlType.OnlyButtons:
return "only_buttons";
case ControlType.Keypad:
return "keypad";
case ControlType.Keyboard:
return "keyboard";
case ControlType.Mahjong:
return "mahjong";
case ControlType.Hanafuda:
return "hanafuda";
case ControlType.Gambling:
return "gambling";
default:
return null;
}
#else
return controlType switch
{
ControlType.Joy => "joy",
ControlType.Stick => "stick",
ControlType.Paddle => "paddle",
ControlType.Pedal => "pedal",
ControlType.Lightgun => "lightgun",
ControlType.Positional => "positional",
ControlType.Dial => "dial",
ControlType.Trackball => "trackball",
ControlType.Mouse => "mouse",
ControlType.OnlyButtons => "only_buttons",
ControlType.Keypad => "keypad",
ControlType.Keyboard => "keyboard",
ControlType.Mahjong => "mahjong",
ControlType.Hanafuda => "hanafuda",
ControlType.Gambling => "gambling",
_ => null,
};
#endif
}
/// <summary>
/// Get string value from input DisplayType
/// </summary>