mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Input players and coins to numbers
This commit is contained in:
@@ -424,8 +424,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
{
|
{
|
||||||
Service = reader.GetAttribute("service").AsYesNo(),
|
Service = reader.GetAttribute("service").AsYesNo(),
|
||||||
Tilt = reader.GetAttribute("tilt").AsYesNo(),
|
Tilt = reader.GetAttribute("tilt").AsYesNo(),
|
||||||
Players = reader.GetAttribute("players"),
|
|
||||||
Coins = reader.GetAttribute("coins"),
|
|
||||||
|
|
||||||
Source = new Source
|
Source = new Source
|
||||||
{
|
{
|
||||||
@@ -434,6 +432,20 @@ namespace SabreTools.Library.DatFiles
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set the players count
|
||||||
|
if (reader.GetAttribute("players") != null)
|
||||||
|
{
|
||||||
|
if (Int64.TryParse(reader.GetAttribute("players"), out long players))
|
||||||
|
input.Players = players;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the coins count
|
||||||
|
if (reader.GetAttribute("coins") != null)
|
||||||
|
{
|
||||||
|
if (Int64.TryParse(reader.GetAttribute("coins"), out long coins))
|
||||||
|
input.Coins = coins;
|
||||||
|
}
|
||||||
|
|
||||||
// Now read the internal tags
|
// Now read the internal tags
|
||||||
ReadInput(reader.ReadSubtree(), input);
|
ReadInput(reader.ReadSubtree(), input);
|
||||||
|
|
||||||
@@ -464,6 +476,22 @@ namespace SabreTools.Library.DatFiles
|
|||||||
reader.Skip();
|
reader.Skip();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "ramoption":
|
||||||
|
datItems.Add(new RamOption
|
||||||
|
{
|
||||||
|
Name = reader.GetAttribute("name"),
|
||||||
|
Default = reader.GetAttribute("default").AsYesNo(),
|
||||||
|
Content = reader.ReadElementContentAsString(),
|
||||||
|
|
||||||
|
Source = new Source
|
||||||
|
{
|
||||||
|
Index = indexId,
|
||||||
|
Name = filename,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case "rom":
|
case "rom":
|
||||||
datItems.Add(new Rom
|
datItems.Add(new Rom
|
||||||
{
|
{
|
||||||
@@ -488,22 +516,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ramoption":
|
|
||||||
datItems.Add(new RamOption
|
|
||||||
{
|
|
||||||
Name = reader.GetAttribute("name"),
|
|
||||||
Default = reader.GetAttribute("default").AsYesNo(),
|
|
||||||
Content = reader.ReadElementContentAsString(),
|
|
||||||
|
|
||||||
Source = new Source
|
|
||||||
{
|
|
||||||
Index = indexId,
|
|
||||||
Name = filename,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "sample":
|
case "sample":
|
||||||
datItems.Add(new Sample
|
datItems.Add(new Sample
|
||||||
{
|
{
|
||||||
@@ -1551,8 +1563,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
xtw.WriteStartElement("input");
|
xtw.WriteStartElement("input");
|
||||||
xtw.WriteOptionalAttributeString("service", input.Service.FromYesNo());
|
xtw.WriteOptionalAttributeString("service", input.Service.FromYesNo());
|
||||||
xtw.WriteOptionalAttributeString("tilt", input.Tilt.FromYesNo());
|
xtw.WriteOptionalAttributeString("tilt", input.Tilt.FromYesNo());
|
||||||
xtw.WriteOptionalAttributeString("players", input.Players);
|
xtw.WriteOptionalAttributeString("players", input.Players?.ToString());
|
||||||
xtw.WriteOptionalAttributeString("coins", input.Coins);
|
xtw.WriteOptionalAttributeString("coins", input.Coins?.ToString());
|
||||||
if (input.Controls != null)
|
if (input.Controls != null)
|
||||||
{
|
{
|
||||||
foreach (var control in input.Controls)
|
foreach (var control in input.Controls)
|
||||||
|
|||||||
@@ -1488,8 +1488,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
xtw.WriteAttributeString("type", "input");
|
xtw.WriteAttributeString("type", "input");
|
||||||
xtw.WriteOptionalAttributeString("service", input.Service.FromYesNo());
|
xtw.WriteOptionalAttributeString("service", input.Service.FromYesNo());
|
||||||
xtw.WriteOptionalAttributeString("tilt", input.Tilt.FromYesNo());
|
xtw.WriteOptionalAttributeString("tilt", input.Tilt.FromYesNo());
|
||||||
xtw.WriteOptionalAttributeString("players", input.Players);
|
xtw.WriteOptionalAttributeString("players", input.Players?.ToString());
|
||||||
xtw.WriteOptionalAttributeString("coins", input.Coins);
|
xtw.WriteOptionalAttributeString("coins", input.Coins?.ToString());
|
||||||
if (input.Controls != null)
|
if (input.Controls != null)
|
||||||
{
|
{
|
||||||
foreach (var control in input.Controls)
|
foreach (var control in input.Controls)
|
||||||
|
|||||||
@@ -303,7 +303,6 @@ namespace SabreTools.Library.DatItems
|
|||||||
Condition newItem = item as Condition;
|
Condition newItem = item as Condition;
|
||||||
|
|
||||||
// Replace the fields
|
// Replace the fields
|
||||||
// TODO: Would this ever make sense to have these `else` statements?
|
|
||||||
if (fields.Contains(Field.DatItem_Tag))
|
if (fields.Contains(Field.DatItem_Tag))
|
||||||
Tag = newItem.Tag;
|
Tag = newItem.Tag;
|
||||||
else if (fields.Contains(Field.DatItem_Condition_Tag))
|
else if (fields.Contains(Field.DatItem_Condition_Tag))
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ namespace SabreTools.Library.DatItems
|
|||||||
Part.Interface = mappings[Field.DatItem_Part_Interface];
|
Part.Interface = mappings[Field.DatItem_Part_Interface];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle DatItem_Feature*
|
// TODO: Handle DatItem_Part_Feature*
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -349,7 +349,7 @@ namespace SabreTools.Library.DatItems
|
|||||||
if (filter.DatItem_Part_Interface.MatchesNegativeSet(Part?.Interface) == true)
|
if (filter.DatItem_Part_Interface.MatchesNegativeSet(Part?.Interface) == true)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO: Handle DatItem_Feature*
|
// TODO: Handle DatItem_Part_Feature*
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -412,7 +412,7 @@ namespace SabreTools.Library.DatItems
|
|||||||
if (fields.Contains(Field.DatItem_Part_Interface) && Part != null)
|
if (fields.Contains(Field.DatItem_Part_Interface) && Part != null)
|
||||||
Part.Interface = null;
|
Part.Interface = null;
|
||||||
|
|
||||||
// TODO: Handle DatItem_Feature*
|
// TODO: Handle DatItem_Part_Feature*
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ namespace SabreTools.Library.DatItems
|
|||||||
Part.Interface = mappings[Field.DatItem_Part_Interface];
|
Part.Interface = mappings[Field.DatItem_Part_Interface];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle DatItem_Feature*
|
// TODO: Handle DatItem_Part_Feature*
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -492,7 +492,7 @@ namespace SabreTools.Library.DatItems
|
|||||||
if (filter.DatItem_Part_Interface.MatchesNegativeSet(Part?.Interface) == true)
|
if (filter.DatItem_Part_Interface.MatchesNegativeSet(Part?.Interface) == true)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO: Handle DatItem_Feature*
|
// TODO: Handle DatItem_Part_Feature*
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -555,7 +555,7 @@ namespace SabreTools.Library.DatItems
|
|||||||
if (fields.Contains(Field.DatItem_Part_Interface) && Part != null)
|
if (fields.Contains(Field.DatItem_Part_Interface) && Part != null)
|
||||||
Part.Interface = null;
|
Part.Interface = null;
|
||||||
|
|
||||||
// TODO: Handle DatItem_Feature*
|
// TODO: Handle DatItem_Part_Feature*
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using SabreTools.Library.Filtering;
|
using SabreTools.Library.Filtering;
|
||||||
@@ -31,13 +32,13 @@ namespace SabreTools.Library.DatItems
|
|||||||
/// Number of players on the input
|
/// Number of players on the input
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
public string Players { get; set; } // TODO: Int32?
|
public long? Players { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of coins required
|
/// Number of coins required
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
[JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
public string Coins { get; set; } // TODO: Int32?
|
public long? Coins { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set of controls for the input
|
/// Set of controls for the input
|
||||||
@@ -66,10 +67,16 @@ namespace SabreTools.Library.DatItems
|
|||||||
Tilt = mappings[Field.DatItem_Tilt].AsYesNo();
|
Tilt = mappings[Field.DatItem_Tilt].AsYesNo();
|
||||||
|
|
||||||
if (mappings.Keys.Contains(Field.DatItem_Players))
|
if (mappings.Keys.Contains(Field.DatItem_Players))
|
||||||
Players = mappings[Field.DatItem_Players];
|
{
|
||||||
|
if (Int64.TryParse(mappings[Field.DatItem_Players], out long players))
|
||||||
|
Players = players;
|
||||||
|
}
|
||||||
|
|
||||||
if (mappings.Keys.Contains(Field.DatItem_Coins))
|
if (mappings.Keys.Contains(Field.DatItem_Coins))
|
||||||
Coins = mappings[Field.DatItem_Coins];
|
{
|
||||||
|
if (Int64.TryParse(mappings[Field.DatItem_Coins], out long coins))
|
||||||
|
Coins = coins;
|
||||||
|
}
|
||||||
|
|
||||||
if (Controls != null)
|
if (Controls != null)
|
||||||
{
|
{
|
||||||
@@ -172,15 +179,19 @@ namespace SabreTools.Library.DatItems
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Filter on players
|
// Filter on players
|
||||||
if (filter.DatItem_Players.MatchesPositiveSet(Players) == false)
|
if (filter.DatItem_Players.MatchesNeutral(null, Players) == false)
|
||||||
return false;
|
return false;
|
||||||
if (filter.DatItem_Players.MatchesNegativeSet(Players) == true)
|
else if (filter.DatItem_Players.MatchesPositive(null, Players) == false)
|
||||||
|
return false;
|
||||||
|
else if (filter.DatItem_Players.MatchesNegative(null, Players) == false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Filter on coins
|
// Filter on coins
|
||||||
if (filter.DatItem_Coins.MatchesPositiveSet(Coins) == false)
|
if (filter.DatItem_Coins.MatchesNeutral(null, Coins) == false)
|
||||||
return false;
|
return false;
|
||||||
if (filter.DatItem_Coins.MatchesNegativeSet(Coins) == true)
|
else if (filter.DatItem_Coins.MatchesPositive(null, Coins) == false)
|
||||||
|
return false;
|
||||||
|
else if (filter.DatItem_Coins.MatchesNegative(null, Coins) == false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Filter on individual controls
|
// Filter on individual controls
|
||||||
@@ -213,7 +224,7 @@ namespace SabreTools.Library.DatItems
|
|||||||
Tilt = null;
|
Tilt = null;
|
||||||
|
|
||||||
if (fields.Contains(Field.DatItem_Players))
|
if (fields.Contains(Field.DatItem_Players))
|
||||||
Players = null;
|
Players = 0;
|
||||||
|
|
||||||
if (fields.Contains(Field.DatItem_Coins))
|
if (fields.Contains(Field.DatItem_Coins))
|
||||||
Coins = null;
|
Coins = null;
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ namespace SabreTools.Library.DatItems
|
|||||||
Part.Interface = mappings[Field.DatItem_Part_Interface];
|
Part.Interface = mappings[Field.DatItem_Part_Interface];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle DatItem_Feature*
|
// TODO: Handle DatItem_Part_Feature*
|
||||||
|
|
||||||
if (mappings.Keys.Contains(Field.DatItem_Value))
|
if (mappings.Keys.Contains(Field.DatItem_Value))
|
||||||
Value = mappings[Field.DatItem_Value];
|
Value = mappings[Field.DatItem_Value];
|
||||||
|
|||||||
@@ -227,8 +227,8 @@ namespace SabreTools.Library.Filtering
|
|||||||
// Input
|
// Input
|
||||||
public FilterItem<bool?> DatItem_Service { get; private set; } = new FilterItem<bool?>() { Neutral = null };
|
public FilterItem<bool?> DatItem_Service { get; private set; } = new FilterItem<bool?>() { Neutral = null };
|
||||||
public FilterItem<bool?> DatItem_Tilt { get; private set; } = new FilterItem<bool?>() { Neutral = null };
|
public FilterItem<bool?> DatItem_Tilt { get; private set; } = new FilterItem<bool?>() { Neutral = null };
|
||||||
public FilterItem<string> DatItem_Players { get; private set; } = new FilterItem<string>();
|
public FilterItem<long?> DatItem_Players { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
|
||||||
public FilterItem<string> DatItem_Coins { get; private set; } = new FilterItem<string>();
|
public FilterItem<long?> DatItem_Coins { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
|
||||||
|
|
||||||
// Instance
|
// Instance
|
||||||
public FilterItem<string> DatItem_Instance_Name { get; private set; } = new FilterItem<string>();
|
public FilterItem<string> DatItem_Instance_Name { get; private set; } = new FilterItem<string>();
|
||||||
@@ -650,51 +650,51 @@ namespace SabreTools.Library.Filtering
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Field.DatItem_Size:
|
case Field.DatItem_Size:
|
||||||
bool? sOperation = null;
|
bool? sizeOperation = null;
|
||||||
if (value.StartsWith(">"))
|
if (value.StartsWith(">"))
|
||||||
sOperation = true;
|
sizeOperation = true;
|
||||||
else if (value.StartsWith("<"))
|
else if (value.StartsWith("<"))
|
||||||
sOperation = false;
|
sizeOperation = false;
|
||||||
else if (value.StartsWith("="))
|
else if (value.StartsWith("="))
|
||||||
sOperation = null;
|
sizeOperation = null;
|
||||||
|
|
||||||
string sizeString = value.TrimStart('>', '<', '=');
|
string sizeString = value.TrimStart('>', '<', '=');
|
||||||
if (!Int64.TryParse(sizeString, out long size))
|
if (!Int64.TryParse(sizeString, out long size))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Equal
|
// Equal
|
||||||
if (sOperation == null && !negate)
|
if (sizeOperation == null && !negate)
|
||||||
{
|
{
|
||||||
DatItem_Size.Neutral = size;
|
DatItem_Size.Neutral = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not Equal
|
// Not Equal
|
||||||
else if (sOperation == null && negate)
|
else if (sizeOperation == null && negate)
|
||||||
{
|
{
|
||||||
DatItem_Size.Negative = size - 1;
|
DatItem_Size.Negative = size - 1;
|
||||||
DatItem_Size.Positive = size + 1;
|
DatItem_Size.Positive = size + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greater Than or Equal
|
// Greater Than or Equal
|
||||||
else if (sOperation == true && !negate)
|
else if (sizeOperation == true && !negate)
|
||||||
{
|
{
|
||||||
DatItem_Size.Positive = size;
|
DatItem_Size.Positive = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strictly Less Than
|
// Strictly Less Than
|
||||||
else if (sOperation == true && negate)
|
else if (sizeOperation == true && negate)
|
||||||
{
|
{
|
||||||
DatItem_Size.Negative = size - 1;
|
DatItem_Size.Negative = size - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Less Than or Equal
|
// Less Than or Equal
|
||||||
else if (sOperation == false && !negate)
|
else if (sizeOperation == false && !negate)
|
||||||
{
|
{
|
||||||
DatItem_Size.Negative = size;
|
DatItem_Size.Negative = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strictly Greater Than
|
// Strictly Greater Than
|
||||||
else if (sOperation == false && negate)
|
else if (sizeOperation == false && negate)
|
||||||
{
|
{
|
||||||
DatItem_Size.Positive = size + 1;
|
DatItem_Size.Positive = size + 1;
|
||||||
}
|
}
|
||||||
@@ -1357,17 +1357,107 @@ namespace SabreTools.Library.Filtering
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Field.DatItem_Players:
|
case Field.DatItem_Players:
|
||||||
if (negate)
|
bool? playersOperation = null;
|
||||||
DatItem_Players.NegativeSet.Add(value);
|
if (value.StartsWith(">"))
|
||||||
else
|
playersOperation = true;
|
||||||
DatItem_Players.PositiveSet.Add(value);
|
else if (value.StartsWith("<"))
|
||||||
|
playersOperation = false;
|
||||||
|
else if (value.StartsWith("="))
|
||||||
|
playersOperation = null;
|
||||||
|
|
||||||
|
string playersString = value.TrimStart('>', '<', '=');
|
||||||
|
if (!Int64.TryParse(playersString, out long players))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Equal
|
||||||
|
if (playersOperation == null && !negate)
|
||||||
|
{
|
||||||
|
DatItem_Players.Neutral = players;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not Equal
|
||||||
|
else if (playersOperation == null && negate)
|
||||||
|
{
|
||||||
|
DatItem_Players.Negative = players - 1;
|
||||||
|
DatItem_Players.Positive = players + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Greater Than or Equal
|
||||||
|
else if (playersOperation == true && !negate)
|
||||||
|
{
|
||||||
|
DatItem_Players.Positive = players;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strictly Less Than
|
||||||
|
else if (playersOperation == true && negate)
|
||||||
|
{
|
||||||
|
DatItem_Players.Negative = players - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Less Than or Equal
|
||||||
|
else if (playersOperation == false && !negate)
|
||||||
|
{
|
||||||
|
DatItem_Players.Negative = players;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strictly Greater Than
|
||||||
|
else if (playersOperation == false && negate)
|
||||||
|
{
|
||||||
|
DatItem_Players.Positive = players + 1;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Field.DatItem_Coins:
|
case Field.DatItem_Coins:
|
||||||
if (negate)
|
bool? coinsOperation = null;
|
||||||
DatItem_Coins.NegativeSet.Add(value);
|
if (value.StartsWith(">"))
|
||||||
else
|
coinsOperation = true;
|
||||||
DatItem_Coins.PositiveSet.Add(value);
|
else if (value.StartsWith("<"))
|
||||||
|
coinsOperation = false;
|
||||||
|
else if (value.StartsWith("="))
|
||||||
|
coinsOperation = null;
|
||||||
|
|
||||||
|
string coinsString = value.TrimStart('>', '<', '=');
|
||||||
|
if (!Int64.TryParse(coinsString, out long coins))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Equal
|
||||||
|
if (coinsOperation == null && !negate)
|
||||||
|
{
|
||||||
|
DatItem_Coins.Neutral = coins;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not Equal
|
||||||
|
else if (coinsOperation == null && negate)
|
||||||
|
{
|
||||||
|
DatItem_Coins.Negative = coins - 1;
|
||||||
|
DatItem_Coins.Positive = coins + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Greater Than or Equal
|
||||||
|
else if (coinsOperation == true && !negate)
|
||||||
|
{
|
||||||
|
DatItem_Coins.Positive = coins;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strictly Less Than
|
||||||
|
else if (coinsOperation == true && negate)
|
||||||
|
{
|
||||||
|
DatItem_Coins.Negative = coins - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Less Than or Equal
|
||||||
|
else if (coinsOperation == false && !negate)
|
||||||
|
{
|
||||||
|
DatItem_Coins.Negative = coins;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strictly Greater Than
|
||||||
|
else if (coinsOperation == false && negate)
|
||||||
|
{
|
||||||
|
DatItem_Coins.Positive = coins + 1;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Instance
|
// Instance
|
||||||
|
|||||||
Reference in New Issue
Block a user