Add keybind for swapping hands in the other direction (#37588)

add swap hands reverse
This commit is contained in:
slarticodefast
2025-05-19 03:17:35 +02:00
committed by GitHub
parent f62f0fbae9
commit f3c4ff8a2a
6 changed files with 33 additions and 12 deletions

View File

@@ -31,6 +31,7 @@ public abstract partial class SharedHandsSystem : EntitySystem
.Bind(ContentKeyFunctions.UseItemInHand, InputCmdHandler.FromDelegate(HandleUseItem, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.AltUseItemInHand, InputCmdHandler.FromDelegate(HandleAltUseInHand, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(SwapHandsPressed, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.SwapHandsReverse, InputCmdHandler.FromDelegate(SwapHandsReversePressed, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed))
.Register<SharedHandsSystem>();
}
@@ -79,6 +80,16 @@ public abstract partial class SharedHandsSystem : EntitySystem
}
private void SwapHandsPressed(ICommonSession? session)
{
SwapHands(session, false);
}
private void SwapHandsReversePressed(ICommonSession? session)
{
SwapHands(session, true);
}
private void SwapHands(ICommonSession? session, bool reverse)
{
if (!TryComp(session?.AttachedEntity, out HandsComponent? component))
return;
@@ -89,8 +100,9 @@ public abstract partial class SharedHandsSystem : EntitySystem
if (component.ActiveHand == null || component.Hands.Count < 2)
return;
var newActiveIndex = component.SortedHands.IndexOf(component.ActiveHand.Name) + 1;
var nextHand = component.SortedHands[newActiveIndex % component.Hands.Count];
var currentIndex = component.SortedHands.IndexOf(component.ActiveHand.Name);
var newActiveIndex = (currentIndex + (reverse ? -1 : 1) + component.Hands.Count) % component.Hands.Count;
var nextHand = component.SortedHands[newActiveIndex];
TrySetActiveHand(session.AttachedEntity.Value, nextHand, component);
}