Add assert that function in InputSystem.HandleInputCommand is correct.

This commit is contained in:
Pieter-Jan Briers
2020-01-26 03:32:12 +01:00
parent 2a3624c89c
commit d3997b51e8
2 changed files with 35 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Players;
using Robust.Shared.Utility;
namespace Robust.Client.GameObjects.EntitySystems
{
@@ -43,6 +44,13 @@ namespace Robust.Client.GameObjects.EntitySystems
/// <param name="message">Arguments for this event.</param>
public void HandleInputCommand(ICommonSession session, BoundKeyFunction function, FullInputCmdMessage message)
{
#if DEBUG
var funcId = _inputManager.NetworkBindMap.KeyFunctionID(function);
DebugTools.Assert(funcId == message.InputFunctionId, "Function ID in message does not match function.");
#endif
// set state, state change is updated regardless if it is locally bound
_cmdStates.SetState(function, message.State);

View File

@@ -10,9 +10,9 @@ namespace Robust.Shared.Input
/// A networked identifier for a <see cref="BoundKeyFunction"/>.
/// </summary>
[Serializable, NetSerializable]
public struct KeyFunctionId
public readonly struct KeyFunctionId : IEquatable<KeyFunctionId>
{
private int _value;
private readonly int _value;
public KeyFunctionId(int id)
{
@@ -28,6 +28,31 @@ namespace Robust.Shared.Input
{
return _value.ToString();
}
public bool Equals(KeyFunctionId other)
{
return _value == other._value;
}
public override bool Equals(object obj)
{
return obj is KeyFunctionId other && Equals(other);
}
public override int GetHashCode()
{
return _value;
}
public static bool operator ==(KeyFunctionId left, KeyFunctionId right)
{
return left.Equals(right);
}
public static bool operator !=(KeyFunctionId left, KeyFunctionId right)
{
return !left.Equals(right);
}
}
/// <summary>