using System; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Serialization; using Robust.Shared.Timing; namespace Robust.Shared.Input { /// /// Abstract class that all Input Commands derive from. /// [Serializable, NetSerializable] public abstract class InputCmdMessage : EntityEventArgs, IComparable { /// /// Client tick this was created. /// public GameTick Tick { get; } /// /// How far into the tick this event was fired. /// /// public ushort SubTick { get; } /// /// The function this command is changing. /// public KeyFunctionId InputFunctionId { get; } /// /// Sequence number of this input command. /// public uint InputSequence { get; set; } /// /// Creates an instance of . /// /// Client tick this was created. /// Function this command is changing. public InputCmdMessage(GameTick tick, ushort subTick, KeyFunctionId inputFunctionId) { Tick = tick; SubTick = subTick; InputFunctionId = inputFunctionId; } public int CompareTo(InputCmdMessage? other) { if (other == null) { return 1; } if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; return InputSequence.CompareTo(other.InputSequence); } /// public override string ToString() { return $"tick={Tick}, subTick={SubTick}, seq={InputSequence} func={InputFunctionId}"; } } /// /// An Input Command for a function that has a state. /// [Serializable, NetSerializable] public sealed class StateInputCmdMessage : InputCmdMessage { /// /// New state of the Input Function. /// public BoundKeyState State { get; } /// /// Creates an instance of . /// /// Client tick this was created. /// Function this command is changing. /// New state of the Input Function. public StateInputCmdMessage(GameTick tick, ushort subTick, KeyFunctionId inputFunctionId, BoundKeyState state) : base(tick, subTick, inputFunctionId) { State = state; } } /// /// A OneShot Input Command that does not have a state. /// [Serializable, NetSerializable] [Virtual] public class EventInputCmdMessage : InputCmdMessage { /// /// Creates an instance of . /// /// Client tick this was created. /// Function this command is changing. public EventInputCmdMessage(GameTick tick, ushort subTick, KeyFunctionId inputFunctionId) : base(tick, subTick, inputFunctionId) { } } /// /// A OneShot Input Command that also contains pointer info. /// [Serializable, NetSerializable] public sealed class PointerInputCmdMessage : EventInputCmdMessage { /// /// Local Coordinates of the pointer when the command was created. /// public NetCoordinates Coordinates { get; } /// /// Entity that was under the pointer when the command was created (if any). /// public NetEntity Uid { get; } /// /// Creates an instance of . /// /// Client tick this was created. /// Function this command is changing. /// Local Coordinates of the pointer when the command was created. public PointerInputCmdMessage(GameTick tick, ushort subTick, KeyFunctionId inputFunctionId, NetCoordinates coordinates) : this(tick, subTick, inputFunctionId, coordinates, NetEntity.Invalid) { } /// /// Creates an instance of with an optional Entity reference. /// /// Client tick this was created. /// Function this command is changing. /// Local Coordinates of the pointer when the command was created. /// Entity that was under the pointer when the command was created. public PointerInputCmdMessage(GameTick tick, ushort subTick, KeyFunctionId inputFunctionId, NetCoordinates coordinates, NetEntity uid) : base(tick, subTick, inputFunctionId) { Coordinates = coordinates; Uid = uid; } } /// /// Handles inputs clientside. This is used so the client can still interact with client-only entities without relying on /// . /// public sealed class ClientFullInputCmdMessage : InputCmdMessage, IFullInputCmdMessage { /// /// New state of the Input Function. /// public BoundKeyState State { get; init; } /// /// Local Coordinates of the pointer when the command was created. /// public EntityCoordinates Coordinates { get; init; } /// /// Screen Coordinates of the pointer when the command was created. /// public ScreenCoordinates ScreenCoordinates { get; init; } /// /// Entity that was under the pointer when the command was created (if any). /// public EntityUid Uid { get; init; } public ClientFullInputCmdMessage(GameTick tick, ushort subTick, KeyFunctionId inputFunctionId) : base(tick, subTick, inputFunctionId) { } public ClientFullInputCmdMessage( GameTick tick, ushort subTick, KeyFunctionId inputFunctionId, EntityCoordinates coordinates, ScreenCoordinates screenCoordinates, BoundKeyState state, EntityUid uid) : base(tick, subTick, inputFunctionId) { Coordinates = coordinates; ScreenCoordinates = screenCoordinates; State = state; Uid = uid; } } [NotContentImplementable] public interface IFullInputCmdMessage { GameTick Tick { get; } BoundKeyState State { get; } KeyFunctionId InputFunctionId { get; } ushort SubTick { get; } uint InputSequence { get; set; } } /// /// An input command that has both state and pointer info. /// [Serializable, NetSerializable] public sealed class FullInputCmdMessage : InputCmdMessage, IFullInputCmdMessage { /// /// New state of the Input Function. /// public BoundKeyState State { get; } /// /// Local Coordinates of the pointer when the command was created. /// public NetCoordinates Coordinates { get; } /// /// Screen Coordinates of the pointer when the command was created. /// public ScreenCoordinates ScreenCoordinates { get; } /// /// Entity that was under the pointer when the command was created (if any). /// public NetEntity Uid { get; init; } /// /// Creates an instance of . /// /// Client tick this was created. /// /// Function this command is changing. /// New state of the Input Function. /// Local Coordinates of the pointer when the command was created. /// public FullInputCmdMessage(GameTick tick, ushort subTick, int inputSequence, KeyFunctionId inputFunctionId, BoundKeyState state, NetCoordinates coordinates, ScreenCoordinates screenCoordinates) : this(tick, subTick, inputFunctionId, state, coordinates, screenCoordinates, NetEntity.Invalid) { } /// /// Creates an instance of with an optional Entity reference. /// /// Client tick this was created. /// Function this command is changing. /// New state of the Input Function. /// Local Coordinates of the pointer when the command was created. /// /// Entity that was under the pointer when the command was created. public FullInputCmdMessage(GameTick tick, ushort subTick, KeyFunctionId inputFunctionId, BoundKeyState state, NetCoordinates coordinates, ScreenCoordinates screenCoordinates, NetEntity uid) : base(tick, subTick, inputFunctionId) { State = state; Coordinates = coordinates; ScreenCoordinates = screenCoordinates; Uid = uid; } } }