mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
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:
@@ -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 =>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user