Adds config options for diagonal movement (#684)
* Adds config options for diagonal movement * Addresses comment
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
||||
|
||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
@@ -8,6 +9,9 @@ using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Configuration;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Movement
|
||||
{
|
||||
@@ -18,6 +22,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
[ComponentReference(typeof(IMoverComponent))]
|
||||
public class PlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial
|
||||
{
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private bool _movingUp;
|
||||
private bool _movingDown;
|
||||
private bool _movingLeft;
|
||||
@@ -54,6 +63,17 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
|
||||
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 />
|
||||
public override void OnAdd()
|
||||
{
|
||||
@@ -110,8 +130,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
x += _movingRight ? 1 : 0;
|
||||
|
||||
var y = 0;
|
||||
if (DiagonalMovementEnabled || x == 0)
|
||||
{
|
||||
y -= _movingDown ? 1 : 0;
|
||||
y += _movingUp ? 1 : 0;
|
||||
}
|
||||
|
||||
VelocityDir = new Vector2(x, y);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user