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