Command handlers now return a boolean signaling if the command was "handled" or not. This allows clientside handlers to intercept input commands and optionally handle them before they are sent to the server. Previously, registering a clientside handler would completely block the input command from being sent to the server.

This commit is contained in:
Acruid
2019-09-17 16:04:26 -07:00
parent 5d5b897a9b
commit 81641f49dc
3 changed files with 16 additions and 12 deletions

View File

@@ -217,13 +217,13 @@ namespace Robust.Client.Placement
(session, coords, uid) =>
{
if (!IsActive)
return;
return false;
if (Eraser)
{
if (uid == EntityUid.Invalid)
{
return;
return false;
}
HandleDeletion(_entityManager.GetEntity(uid));
}
@@ -231,17 +231,20 @@ namespace Robust.Client.Placement
{
_placenextframe = true;
}
return true;
},
(session, coords, uid) =>
{
if (!IsActive || Eraser || !_placenextframe)
return;
return false;
//Places objects for non-tile entities
if (!CurrentPermission.IsTile)
HandlePlacement();
_placenextframe = false;
return true;
}));
inputSys.BindMap.BindFunction(EngineKeyFunctions.EditorRotateObject, InputCmdHandler.FromDelegate(
session =>

View File

@@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
using Robust.Shared.Serialization;
namespace Robust.Shared.GameObjects
@@ -68,11 +69,13 @@ namespace Robust.Shared.GameObjects
/// Checks if the ID value is valid. Does not check if it identifies
/// a valid Entity.
/// </summary>
[Pure]
public bool IsValid()
{
return _uid > 0;
}
[Pure]
public bool IsClientSide()
{
return (_uid & (2 << 29)) != 0;

View File

@@ -71,18 +71,17 @@ namespace Robust.Shared.Input
}
}
public delegate void PointerInputCmdDelegate(ICommonSession session, GridCoordinates coords, EntityUid uid);
public delegate bool PointerInputCmdDelegate(ICommonSession session, GridCoordinates coords, EntityUid uid);
public delegate void PointerInputCmdDelegate2(in PointerInputCmdHandler.PointerInputCmdArgs args);
public delegate bool PointerInputCmdDelegate2(in PointerInputCmdHandler.PointerInputCmdArgs args);
public class PointerInputCmdHandler : InputCmdHandler
{
private PointerInputCmdDelegate2 _callback;
public PointerInputCmdHandler(PointerInputCmdDelegate callback) : this((in PointerInputCmdArgs args) =>
callback(args.Session, args.Coordinates, args.EntityUid))
{
}
public PointerInputCmdHandler(PointerInputCmdDelegate callback)
: this((in PointerInputCmdArgs args) =>
callback(args.Session, args.Coordinates, args.EntityUid)) { }
public PointerInputCmdHandler(PointerInputCmdDelegate2 callback)
{
@@ -94,9 +93,8 @@ namespace Robust.Shared.Input
if (!(message is FullInputCmdMessage msg) || msg.State != BoundKeyState.Down)
return false;
_callback?.Invoke(new PointerInputCmdArgs(session, msg.Coordinates, msg.ScreenCoordinates, msg.Uid));
return true;
var handled = _callback?.Invoke(new PointerInputCmdArgs(session, msg.Coordinates, msg.ScreenCoordinates, msg.Uid));
return handled.HasValue && handled.Value;
}
public readonly struct PointerInputCmdArgs