Skip to content

Commit

Permalink
Add delay to AutoOrient (#33479)
Browse files Browse the repository at this point in the history
It functions identically to how V1 of orientation worked and it's incredibly annoying.
  • Loading branch information
metalgearsloth authored Nov 23, 2024
1 parent 8522ffe commit 11dbf50
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Content.Shared/CCVar/CCVars.Shuttle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ namespace Content.Shared.CCVar;

public sealed partial class CCVars
{
/// <summary>
/// Delay for auto-orientation. Used for people arriving via arrivals.
/// </summary>
public static readonly CVarDef<double> AutoOrientDelay =
CVarDef.Create("shuttle.auto_orient_delay", 2.0, CVar.SERVER | CVar.REPLICATED);

/// <summary>
/// If true then the camera will match the grid / map and is unchangeable.
/// - When traversing grids it will snap to 0 degrees rotation.
Expand Down
5 changes: 3 additions & 2 deletions Content.Shared/Movement/Components/AutoOrientComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ namespace Content.Shared.Movement.Components;
/// <summary>
/// Automatically rotates eye upon grid traversals.
/// </summary>
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
public sealed partial class AutoOrientComponent : Component
{

[DataField, AutoNetworkedField, AutoPausedField]
public TimeSpan? NextChange;
}
51 changes: 51 additions & 0 deletions Content.Shared/Movement/Systems/AutoOrientSystem.cs
Original file line number Diff line number Diff line change
@@ -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<AutoOrientComponent, EntParentChangedMessage>(OnEntParentChanged);

Subs.CVar(_cfgManager, CCVars.AutoOrientDelay, OnAutoOrient, true);
}

private void OnAutoOrient(double obj)
{
_delay = TimeSpan.FromSeconds(obj);
}

private void OnEntParentChanged(Entity<AutoOrientComponent> ent, ref EntParentChangedMessage args)
{
ent.Comp.NextChange = _timing.CurTime + _delay;
Dirty(ent);
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<AutoOrientComponent>();

while (query.MoveNext(out var uid, out var comp))
{
if (comp.NextChange <= _timing.CurTime)
{
comp.NextChange = null;
Dirty(uid, comp);
_mover.ResetCamera(uid);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ private void InitializeInput()
SubscribeLocalEvent<InputMoverComponent, ComponentHandleState>(OnMoverHandleState);
SubscribeLocalEvent<InputMoverComponent, EntParentChangedMessage>(OnInputParentChange);

SubscribeLocalEvent<AutoOrientComponent, EntParentChangedMessage>(OnAutoParentChange);

SubscribeLocalEvent<FollowedComponent, EntParentChangedMessage>(OnFollowedParentChange);

Subs.CVar(_configManager, CCVars.CameraRotationLocked, obj => CameraRotationLocked = obj, true);
Expand Down Expand Up @@ -146,11 +144,6 @@ private void ShutdownInput()

protected virtual void HandleShuttleInput(EntityUid uid, ShuttleButtons button, ushort subTick, bool state) {}

private void OnAutoParentChange(Entity<AutoOrientComponent> entity, ref EntParentChangedMessage args)
{
ResetCamera(entity.Owner);
}

public void RotateCamera(EntityUid uid, Angle angle)
{
if (CameraRotationLocked || !MoverQuery.TryGetComponent(uid, out var mover))
Expand Down

0 comments on commit 11dbf50

Please sign in to comment.