diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index 4fa8fe40..8d857a10 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -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) diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs index a2667248..cecdea8b 100644 --- a/SabreTools.Library/DatFiles/SabreDat.cs +++ b/SabreTools.Library/DatFiles/SabreDat.cs @@ -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) diff --git a/SabreTools.Library/DatItems/Condition.cs b/SabreTools.Library/DatItems/Condition.cs index e2c6d84a..27024aae 100644 --- a/SabreTools.Library/DatItems/Condition.cs +++ b/SabreTools.Library/DatItems/Condition.cs @@ -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)) diff --git a/SabreTools.Library/DatItems/DipSwitch.cs b/SabreTools.Library/DatItems/DipSwitch.cs index f453a4ef..7fd27c03 100644 --- a/SabreTools.Library/DatItems/DipSwitch.cs +++ b/SabreTools.Library/DatItems/DipSwitch.cs @@ -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 } diff --git a/SabreTools.Library/DatItems/Disk.cs b/SabreTools.Library/DatItems/Disk.cs index 123e630a..9bf68118 100644 --- a/SabreTools.Library/DatItems/Disk.cs +++ b/SabreTools.Library/DatItems/Disk.cs @@ -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 } diff --git a/SabreTools.Library/DatItems/Input.cs b/SabreTools.Library/DatItems/Input.cs index 4344d7ec..133dd50b 100644 --- a/SabreTools.Library/DatItems/Input.cs +++ b/SabreTools.Library/DatItems/Input.cs @@ -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 /// [JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)] - public string Players { get; set; } // TODO: Int32? + public long? Players { get; set; } /// /// Number of coins required /// [JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore)] - public string Coins { get; set; } // TODO: Int32? + public long? Coins { get; set; } /// /// 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; diff --git a/SabreTools.Library/DatItems/Rom.cs b/SabreTools.Library/DatItems/Rom.cs index a6ecb513..138476c2 100644 --- a/SabreTools.Library/DatItems/Rom.cs +++ b/SabreTools.Library/DatItems/Rom.cs @@ -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]; diff --git a/SabreTools.Library/Filtering/Filter.cs b/SabreTools.Library/Filtering/Filter.cs index 239efac3..c51a07b0 100644 --- a/SabreTools.Library/Filtering/Filter.cs +++ b/SabreTools.Library/Filtering/Filter.cs @@ -227,8 +227,8 @@ namespace SabreTools.Library.Filtering // Input public FilterItem DatItem_Service { get; private set; } = new FilterItem() { Neutral = null }; public FilterItem DatItem_Tilt { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem DatItem_Players { get; private set; } = new FilterItem(); - public FilterItem DatItem_Coins { get; private set; } = new FilterItem(); + public FilterItem DatItem_Players { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; + public FilterItem DatItem_Coins { get; private set; } = new FilterItem() { Positive = null, Negative = null, Neutral = null }; // Instance public FilterItem DatItem_Instance_Name { get; private set; } = new FilterItem(); @@ -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