using System.Collections.Generic; using System.Linq; using SabreTools.Library.Filtering; using Newtonsoft.Json; using SabreTools.Library.Tools; namespace SabreTools.Library.DatItems { /// /// Represents one ListXML input /// [JsonObject("input")] public class Input : DatItem { #region Fields /// /// Input service ID /// [JsonProperty("service", DefaultValueHandling = DefaultValueHandling.Ignore)] public bool? Service { get; set; } /// /// Determins if this has a tilt sensor /// [JsonProperty("tilt", DefaultValueHandling = DefaultValueHandling.Ignore)] public bool? Tilt { get; set; } /// /// Number of players on the input /// [JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore)] public string Players { get; set; } // TODO: Int32? /// /// Number of coins required /// [JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore)] public string Coins { get; set; } // TODO: Int32? /// /// Set of controls for the input /// [JsonProperty("controls", DefaultValueHandling = DefaultValueHandling.Ignore)] public List Controls { get; set; } #endregion #region Accessors /// /// Set fields with given values /// /// Mappings dictionary public override void SetFields(Dictionary mappings) { // Set base fields base.SetFields(mappings); // Handle Input-specific fields if (mappings.Keys.Contains(Field.DatItem_Service)) Service = mappings[Field.DatItem_Service].AsYesNo(); if (mappings.Keys.Contains(Field.DatItem_Tilt)) Tilt = mappings[Field.DatItem_Tilt].AsYesNo(); if (mappings.Keys.Contains(Field.DatItem_Players)) Players = mappings[Field.DatItem_Players]; if (mappings.Keys.Contains(Field.DatItem_Coins)) Coins = mappings[Field.DatItem_Coins]; // TODO: Handle DatItem_Control* } #endregion #region Constructors /// /// Create a default, empty Input object /// public Input() { ItemType = ItemType.Input; } #endregion #region Cloning Methods public override object Clone() { return new Input() { ItemType = this.ItemType, DupeType = this.DupeType, AltName = this.AltName, AltTitle = this.AltTitle, Original = this.Original, OpenMSXSubType = this.OpenMSXSubType, OpenMSXType = this.OpenMSXType, Remark = this.Remark, Boot = this.Boot, LoadFlag = this.LoadFlag, Machine = this.Machine.Clone() as Machine, Source = this.Source.Clone() as Source, Remove = this.Remove, Service = this.Service, Tilt = this.Tilt, Players = this.Players, Coins = this.Coins, Controls = this.Controls, }; } #endregion #region Comparision Methods public override bool Equals(DatItem other) { // If we don't have a Input, return false if (ItemType != other.ItemType) return false; // Otherwise, treat it as a Input Input newOther = other as Input; // If the Input information matches return (Service == newOther.Service && Tilt == newOther.Tilt && Players == newOther.Players && Coins == newOther.Coins); // TODO: Handle DatItem_Control* } #endregion #region Filtering /// /// Check to see if a DatItem passes the filter /// /// Filter to check against /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { // Check common fields first if (!base.PassesFilter(filter)) return false; // Filter on service if (filter.DatItem_Service.MatchesNeutral(null, Service) == false) return false; // Filter on tilt if (filter.DatItem_Tilt.MatchesNeutral(null, Tilt) == false) return false; // Filter on players if (filter.DatItem_Players.MatchesPositiveSet(Players) == false) return false; if (filter.DatItem_Players.MatchesNegativeSet(Players) == true) return false; // Filter on coins if (filter.DatItem_Coins.MatchesPositiveSet(Coins) == false) return false; if (filter.DatItem_Coins.MatchesNegativeSet(Coins) == true) return false; // TODO: Handle DatItem_Control* return true; } /// /// Remove fields from the DatItem /// /// List of Fields to remove public override void RemoveFields(List fields) { // Remove common fields first base.RemoveFields(fields); // Remove the fields if (fields.Contains(Field.DatItem_Service)) Service = null; if (fields.Contains(Field.DatItem_Tilt)) Tilt = null; if (fields.Contains(Field.DatItem_Players)) Players = null; if (fields.Contains(Field.DatItem_Coins)) Coins = null; if (fields.Contains(Field.DatItem_Controls)) Controls = null; // TODO: Handle DatItem_Control* } #endregion #region Sorting and Merging /// /// Replace fields from another item /// /// DatItem to pull new information from /// List of Fields representing what should be updated public override void ReplaceFields(DatItem item, List fields) { // Replace common fields first base.ReplaceFields(item, fields); // If we don't have a Input to replace from, ignore specific fields if (item.ItemType != ItemType.Input) return; // Cast for easier access Input newItem = item as Input; // Replace the fields if (fields.Contains(Field.DatItem_Service)) Service = newItem.Service; if (fields.Contains(Field.DatItem_Tilt)) Tilt = newItem.Tilt; if (fields.Contains(Field.DatItem_Players)) Players = newItem.Players; if (fields.Contains(Field.DatItem_Coins)) Coins = newItem.Coins; if (fields.Contains(Field.DatItem_Controls)) Controls = newItem.Controls; // TODO: Handle DatItem_Control* } #endregion } }