From b4b0f6e04bc34ccb92fc0ac044c783775f5bc516 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Thu, 13 Feb 2020 14:10:09 +0000 Subject: [PATCH] Adds config options for diagonal movement (#684) * Adds config options for diagonal movement * Addresses comment --- .../Movement/PlayerInputMoverComponent.cs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Content.Server/GameObjects/Components/Movement/PlayerInputMoverComponent.cs b/Content.Server/GameObjects/Components/Movement/PlayerInputMoverComponent.cs index 1d80e1c9d5..3b4708eec4 100644 --- a/Content.Server/GameObjects/Components/Movement/PlayerInputMoverComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/PlayerInputMoverComponent.cs @@ -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; } + /// + /// Whether or not the player can move diagonally. + /// + [ViewVariables] public bool DiagonalMovementEnabled => _configurationManager.GetCVar("game.diagonalmovement"); + + public override void Initialize() + { + base.Initialize(); + _configurationManager.RegisterCVar("game.diagonalmovement", true, CVar.ARCHIVE); + } + /// public override void OnAdd() { @@ -110,8 +130,11 @@ namespace Content.Server.GameObjects.Components.Movement x += _movingRight ? 1 : 0; var y = 0; - y -= _movingDown ? 1 : 0; - y += _movingUp ? 1 : 0; + if (DiagonalMovementEnabled || x == 0) + { + y -= _movingDown ? 1 : 0; + y += _movingUp ? 1 : 0; + } VelocityDir = new Vector2(x, y);