Files
SabreTools/SabreTools.DatItems/Formats/Input.cs

120 lines
3.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-09-03 13:20:56 -07:00
using Newtonsoft.Json;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2020-09-02 21:59:26 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
2020-09-02 21:59:26 -07:00
{
/// <summary>
/// Represents one ListXML input
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("input"), XmlRoot("input")]
2020-09-02 21:59:26 -07:00
public class Input : DatItem
{
#region Fields
/// <summary>
/// Input service ID
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("service", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("service")]
public bool? Service
{
2023-08-14 22:33:05 -04:00
get => _internal.ReadBool(Models.Internal.Input.ServiceKey);
set => _internal[Models.Internal.Input.ServiceKey] = value;
}
2020-09-02 21:59:26 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ServiceSpecified { get { return Service != null; } }
2020-09-02 21:59:26 -07:00
/// <summary>
/// Determins if this has a tilt sensor
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("tilt", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tilt")]
public bool? Tilt
{
2023-08-14 22:33:05 -04:00
get => _internal.ReadBool(Models.Internal.Input.TiltKey);
set => _internal[Models.Internal.Input.TiltKey] = value;
}
2020-09-02 21:59:26 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool TiltSpecified { get { return Tilt != null; } }
2020-09-02 21:59:26 -07:00
/// <summary>
/// Number of players on the input
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("players", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("players")]
public long? Players
{
2023-08-14 22:33:05 -04:00
get => _internal.ReadLong(Models.Internal.Input.PlayersKey);
set => _internal[Models.Internal.Input.PlayersKey] = value;
}
2020-09-02 21:59:26 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool PlayersSpecified { get { return Players != null; } }
2020-09-02 21:59:26 -07:00
/// <summary>
/// Number of coins required
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("coins", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("coins")]
public long? Coins
{
2023-08-14 22:33:05 -04:00
get => _internal.ReadLong(Models.Internal.Input.CoinsKey);
set => _internal[Models.Internal.Input.CoinsKey] = value;
}
2020-09-02 21:59:26 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool CoinsSpecified { get { return Coins != null; } }
2020-09-02 21:59:26 -07:00
/// <summary>
/// Set of controls for the input
/// </summary>
2022-11-03 12:22:17 -07:00
[JsonProperty("controls", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("controls")]
public List<Control>? Controls
{
2023-08-14 22:33:05 -04:00
get => _internal.Read<Control[]>(Models.Internal.Input.ControlKey)?.ToList();
set => _internal[Models.Internal.Input.ControlKey] = value?.ToArray();
}
2020-09-02 21:59:26 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool ControlsSpecified { get { return Controls != null && Controls.Count > 0; } }
2020-09-02 21:59:26 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Input object
/// </summary>
public Input()
{
2023-08-14 22:33:05 -04:00
_internal = new Models.Internal.Input();
2023-08-15 01:38:01 -04:00
Machine = new Machine();
2020-09-02 21:59:26 -07:00
ItemType = ItemType.Input;
}
#endregion
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-09-02 21:59:26 -07:00
public override object Clone()
{
return new Input()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
2023-08-15 01:38:01 -04:00
Machine = this.Machine.Clone() as Machine ?? new Machine(),
Source = this.Source?.Clone() as Source,
2020-09-02 21:59:26 -07:00
Remove = this.Remove,
2023-08-14 22:33:05 -04:00
_internal = this._internal?.Clone() as Models.Internal.Input ?? new Models.Internal.Input(),
2020-09-02 21:59:26 -07:00
};
}
#endregion
}
}