From 11dbf50ed62040c832941f3c46fc159497eca525 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 24 Nov 2024 03:52:58 +1100 Subject: [PATCH] Add delay to AutoOrient (#33479) It functions identically to how V1 of orientation worked and it's incredibly annoying. --- Content.Shared/CCVar/CCVars.Shuttle.cs | 6 +++ .../Components/AutoOrientComponent.cs | 5 +- .../Movement/Systems/AutoOrientSystem.cs | 51 +++++++++++++++++++ .../Systems/SharedMoverController.Input.cs | 7 --- 4 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 Content.Shared/Movement/Systems/AutoOrientSystem.cs diff --git a/Content.Shared/CCVar/CCVars.Shuttle.cs b/Content.Shared/CCVar/CCVars.Shuttle.cs index f66fe9ca598d..caf7f81b0e13 100644 --- a/Content.Shared/CCVar/CCVars.Shuttle.cs +++ b/Content.Shared/CCVar/CCVars.Shuttle.cs @@ -4,6 +4,12 @@ namespace Content.Shared.CCVar; public sealed partial class CCVars { + /// + /// Delay for auto-orientation. Used for people arriving via arrivals. + /// + public static readonly CVarDef AutoOrientDelay = + CVarDef.Create("shuttle.auto_orient_delay", 2.0, CVar.SERVER | CVar.REPLICATED); + /// /// If true then the camera will match the grid / map and is unchangeable. /// - When traversing grids it will snap to 0 degrees rotation. diff --git a/Content.Shared/Movement/Components/AutoOrientComponent.cs b/Content.Shared/Movement/Components/AutoOrientComponent.cs index 4b89b0cbf427..1031425c7172 100644 --- a/Content.Shared/Movement/Components/AutoOrientComponent.cs +++ b/Content.Shared/Movement/Components/AutoOrientComponent.cs @@ -5,8 +5,9 @@ namespace Content.Shared.Movement.Components; /// /// Automatically rotates eye upon grid traversals. /// -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause] public sealed partial class AutoOrientComponent : Component { - + [DataField, AutoNetworkedField, AutoPausedField] + public TimeSpan? NextChange; } diff --git a/Content.Shared/Movement/Systems/AutoOrientSystem.cs b/Content.Shared/Movement/Systems/AutoOrientSystem.cs new file mode 100644 index 000000000000..3bbd715df508 --- /dev/null +++ b/Content.Shared/Movement/Systems/AutoOrientSystem.cs @@ -0,0 +1,51 @@ +using Content.Shared.CCVar; +using Content.Shared.Movement.Components; +using Robust.Shared.Configuration; +using Robust.Shared.Timing; + +namespace Content.Shared.Movement.Systems; + +public sealed class AutoOrientSystem : EntitySystem +{ + [Dependency] private readonly IConfigurationManager _cfgManager = default!; + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly SharedMoverController _mover = default!; + + private TimeSpan _delay = TimeSpan.Zero; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnEntParentChanged); + + Subs.CVar(_cfgManager, CCVars.AutoOrientDelay, OnAutoOrient, true); + } + + private void OnAutoOrient(double obj) + { + _delay = TimeSpan.FromSeconds(obj); + } + + private void OnEntParentChanged(Entity ent, ref EntParentChangedMessage args) + { + ent.Comp.NextChange = _timing.CurTime + _delay; + Dirty(ent); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var query = EntityQueryEnumerator(); + + while (query.MoveNext(out var uid, out var comp)) + { + if (comp.NextChange <= _timing.CurTime) + { + comp.NextChange = null; + Dirty(uid, comp); + _mover.ResetCamera(uid); + } + } + } +} diff --git a/Content.Shared/Movement/Systems/SharedMoverController.Input.cs b/Content.Shared/Movement/Systems/SharedMoverController.Input.cs index c11df709f631..1fe38b6cdf1b 100644 --- a/Content.Shared/Movement/Systems/SharedMoverController.Input.cs +++ b/Content.Shared/Movement/Systems/SharedMoverController.Input.cs @@ -57,8 +57,6 @@ private void InitializeInput() SubscribeLocalEvent(OnMoverHandleState); SubscribeLocalEvent(OnInputParentChange); - SubscribeLocalEvent(OnAutoParentChange); - SubscribeLocalEvent(OnFollowedParentChange); Subs.CVar(_configManager, CCVars.CameraRotationLocked, obj => CameraRotationLocked = obj, true); @@ -146,11 +144,6 @@ private void ShutdownInput() protected virtual void HandleShuttleInput(EntityUid uid, ShuttleButtons button, ushort subTick, bool state) {} - private void OnAutoParentChange(Entity entity, ref EntParentChangedMessage args) - { - ResetCamera(entity.Owner); - } - public void RotateCamera(EntityUid uid, Angle angle) { if (CameraRotationLocked || !MoverQuery.TryGetComponent(uid, out var mover))