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

142 lines
4.4 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;
2024-03-05 01:42:42 -05:00
using SabreTools.Filter;
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-09-04 23:51:37 -04:00
get => _internal.ReadBool(Models.Metadata.Input.ServiceKey);
set => _internal[Models.Metadata.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-09-04 23:51:37 -04:00
get => _internal.ReadBool(Models.Metadata.Input.TiltKey);
set => _internal[Models.Metadata.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-09-04 23:51:37 -04:00
get => _internal.ReadLong(Models.Metadata.Input.PlayersKey);
set => _internal[Models.Metadata.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-09-04 23:51:37 -04:00
get => _internal.ReadLong(Models.Metadata.Input.CoinsKey);
set => _internal[Models.Metadata.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-09-04 23:51:37 -04:00
get => _internal.Read<Control[]>(Models.Metadata.Input.ControlKey)?.ToList();
set => _internal[Models.Metadata.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-09-04 23:51:37 -04:00
_internal = new Models.Metadata.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,
2024-02-28 19:19:50 -05:00
_internal = this._internal?.Clone() as Models.Metadata.Input ?? [],
2020-09-02 21:59:26 -07:00
};
}
#endregion
2024-03-05 01:42:42 -05:00
#region Manipulation
2024-03-05 02:20:12 -05:00
/// <inheritdoc/>
public override bool SetField(DatItemField datItemField, string value)
{
// Get the correct internal field name
string? fieldName = datItemField switch
{
DatItemField.Coins => Models.Metadata.Input.CoinsKey,
DatItemField.Players => Models.Metadata.Input.PlayersKey,
DatItemField.Service => Models.Metadata.Input.ServiceKey,
DatItemField.Tilt => Models.Metadata.Input.TiltKey,
_ => null,
};
// Set the field and return
return FieldManipulator.SetField(_internal, fieldName, value);
}
2024-03-05 01:42:42 -05:00
#endregion
2020-09-02 21:59:26 -07:00
}
}