HandsSystem now uses InputSystem. (#95)

Fixed TemperatureSystem namespace.
This commit is contained in:
Acruid
2018-08-18 15:28:02 -07:00
committed by GitHub
parent ce5760d46c
commit edb3eb5b2e
4 changed files with 91 additions and 43 deletions

View File

@@ -94,11 +94,12 @@
<Compile Include="GameObjects\EntitySystems\Click\ExamineSystem.cs" />
<Compile Include="GameObjects\EntitySystems\Click\InteractionSystem.cs" />
<Compile Include="GameObjects\EntitySystems\DoorSystem.cs" />
<Compile Include="GameObjects\EntitySystems\HandsSystem.cs" />
<Compile Include="GameObjects\EntitySystems\PowerApcSystem.cs" />
<Compile Include="GameObjects\EntitySystems\PowerSmesSystem.cs" />
<Compile Include="GameObjects\EntitySystems\PowerSystem.cs" />
<Compile Include="GameObjects\EntitySystems\WelderSystem.cs" />
<Compile Include="GameObjects\TemperatureSystem.cs" />
<Compile Include="GameObjects\EntitySystems\TemperatureSystem.cs" />
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
<Compile Include="GameObjects\Components\GUI\ServerHandsComponent.cs" />
<Compile Include="GameObjects\Components\GUI\InventoryComponent.cs" />

View File

@@ -13,7 +13,6 @@ using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.GameObjects.Components;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.IoC;
using SS14.Shared.Players;
using SS14.Shared.Serialization;
namespace Content.Server.GameObjects
@@ -43,10 +42,6 @@ namespace Content.Server.GameObjects
// Mostly arbitrary.
public const float PICKUP_RANGE = 2;
private InputCmdHandler _swapHandsCmdHandler;
private InputCmdHandler _dropCmdHandler;
private InputCmdHandler _activateItemInHandCmdHandler;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -251,7 +246,7 @@ namespace Content.Server.GameObjects
return new HandsComponentState(dict, ActiveIndex);
}
private void SwapHands(ICommonSession channel)
public void SwapHands()
{
var index = orderedHands.FindIndex(x => x == ActiveIndex);
index++;
@@ -263,6 +258,15 @@ namespace Content.Server.GameObjects
ActiveIndex = orderedHands[index];
}
public void ActivateItem()
{
var used = GetActiveHand?.Owner;
if (used != null)
{
InteractionSystem.TryUseInteraction(Owner, used);
}
}
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
{
base.HandleMessage(message, netChannel, component);
@@ -294,42 +298,7 @@ namespace Content.Server.GameObjects
}
break;
}
//Boundkeychangedmsg only works for the player entity and doesn't need any extra verification
case PlayerAttachedMsg msg:
InitInputCommands();
input = msg.NewPlayer.Input;
input.SetCommand(ContentKeyFunctions.SwapHands, _swapHandsCmdHandler);
input.SetCommand(ContentKeyFunctions.Drop, _dropCmdHandler);
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, _activateItemInHandCmdHandler);
break;
case PlayerDetachedMsg msg:
input = msg.OldPlayer.Input;
input.SetCommand(ContentKeyFunctions.SwapHands, null);
input.SetCommand(ContentKeyFunctions.Drop, null);
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, null);
break;
}
}
private void InitInputCommands()
{
if (_swapHandsCmdHandler != null)
{
return;
}
_swapHandsCmdHandler = InputCmdHandler.FromDelegate(SwapHands);
_dropCmdHandler = InputCmdHandler.FromDelegate(session => Drop(ActiveIndex));
_activateItemInHandCmdHandler = InputCmdHandler.FromDelegate(session =>
{
var used = GetActiveHand?.Owner;
if (used != null)
{
InteractionSystem.TryUseInteraction(Owner, used);
}
});
}
}
}

View File

@@ -0,0 +1,78 @@
using Content.Shared.Input;
using SS14.Server.GameObjects.EntitySystems;
using SS14.Server.Interfaces.Player;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Systems;
using SS14.Shared.Input;
using SS14.Shared.Players;
namespace Content.Server.GameObjects.EntitySystems
{
internal class HandsSystem : EntitySystem
{
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
var input = EntitySystemManager.GetEntitySystem<InputSystem>();
input.BindMap.BindFunction(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(HandleSwapHands));
input.BindMap.BindFunction(ContentKeyFunctions.Drop, InputCmdHandler.FromDelegate(HandleDrop));
input.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem));
}
/// <inheritdoc />
public override void Shutdown()
{
if (EntitySystemManager.TryGetEntitySystem(out InputSystem input))
{
input.BindMap.UnbindFunction(ContentKeyFunctions.SwapHands);
input.BindMap.UnbindFunction(ContentKeyFunctions.Drop);
input.BindMap.UnbindFunction(ContentKeyFunctions.ActivateItemInHand);
}
base.Shutdown();
}
private static bool TryGetAttachedComponent<T>(IPlayerSession session, out T component)
where T : Component
{
component = default(T);
var ent = session.AttachedEntity;
if (ent == null || !ent.IsValid())
return false;
if (!ent.TryGetComponent(out T comp))
return false;
component = comp;
return true;
}
private static void HandleSwapHands(ICommonSession session)
{
if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp))
return;
handsComp.SwapHands();
}
private static void HandleDrop(ICommonSession session)
{
if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp))
return;
handsComp.Drop(handsComp.ActiveIndex);
}
private static void HandleActivateItem(ICommonSession session)
{
if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp))
return;
handsComp.ActivateItem();
}
}
}

View File

@@ -1,7 +1,7 @@
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects
namespace Content.Server.GameObjects.EntitySystems
{
class TemperatureSystem : EntitySystem
{