Adds config options for diagonal movement (#684)

* Adds config options for diagonal movement

* Addresses comment
This commit is contained in:
Daniel Thompson
2020-02-13 14:10:09 +00:00
committed by GitHub
parent f8a64bcd5c
commit b4b0f6e04b

View File

@@ -1,4 +1,5 @@
using Content.Server.Interfaces.GameObjects.Components.Movement; 
using Content.Server.Interfaces.GameObjects.Components.Movement;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components;
@@ -8,6 +9,9 @@ using Robust.Shared.Maths;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using Robust.Shared.IoC;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.Configuration;
namespace Content.Server.GameObjects.Components.Movement namespace Content.Server.GameObjects.Components.Movement
{ {
@@ -18,6 +22,11 @@ namespace Content.Server.GameObjects.Components.Movement
[ComponentReference(typeof(IMoverComponent))] [ComponentReference(typeof(IMoverComponent))]
public class PlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial public class PlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial
{ {
#pragma warning disable 649
[Dependency] private readonly IConfigurationManager _configurationManager;
#pragma warning restore 649
private bool _movingUp; private bool _movingUp;
private bool _movingDown; private bool _movingDown;
private bool _movingLeft; private bool _movingLeft;
@@ -54,6 +63,17 @@ namespace Content.Server.GameObjects.Components.Movement
public float StepSoundDistance { get; set; } public float StepSoundDistance { get; set; }
/// <summary>
/// Whether or not the player can move diagonally.
/// </summary>
[ViewVariables] public bool DiagonalMovementEnabled => _configurationManager.GetCVar<bool>("game.diagonalmovement");
public override void Initialize()
{
base.Initialize();
_configurationManager.RegisterCVar("game.diagonalmovement", true, CVar.ARCHIVE);
}
/// <inheritdoc /> /// <inheritdoc />
public override void OnAdd() public override void OnAdd()
{ {
@@ -110,8 +130,11 @@ namespace Content.Server.GameObjects.Components.Movement
x += _movingRight ? 1 : 0; x += _movingRight ? 1 : 0;
var y = 0; var y = 0;
if (DiagonalMovementEnabled || x == 0)
{
y -= _movingDown ? 1 : 0; y -= _movingDown ? 1 : 0;
y += _movingUp ? 1 : 0; y += _movingUp ? 1 : 0;
}
VelocityDir = new Vector2(x, y); VelocityDir = new Vector2(x, y);