Files
tbd-station-14/Content.Client/Doors/TurnstileSystem.cs
Nemanja 712954f1c4 Turnstiles (#36313)
* construction rotation fix

* Turnstiles

* renaming

* review-slarticodefast-1

* mild attempts to fix (sorry sloth)

* move some more shit

* Remove engine dependency

* grid agnostic

* remove debug string

* fix json

* Update Content.Shared/Movement/Pulling/Systems/PullingSystem.cs

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>

* Update Content.Shared/Movement/Pulling/Systems/PullingSystem.cs

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>

* remove pass delay for mispredict reasons.

* most minor of changes

* Give directional indicator on examine

---------

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
2025-04-24 13:39:40 +02:00

76 lines
2.4 KiB
C#

using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Examine;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Client.Doors;
/// <inheritdoc/>
public sealed class TurnstileSystem : SharedTurnstileSystem
{
[Dependency] private readonly AnimationPlayerSystem _animationPlayer = default!;
private static EntProtoId _examineArrow = "TurnstileArrow";
private const string AnimationKey = "Turnstile";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TurnstileComponent, AnimationCompletedEvent>(OnAnimationCompleted);
SubscribeLocalEvent<TurnstileComponent, ExaminedEvent>(OnExamined);
}
private void OnAnimationCompleted(Entity<TurnstileComponent> ent, ref AnimationCompletedEvent args)
{
if (args.Key != AnimationKey)
return;
if (!TryComp<SpriteComponent>(ent, out var sprite))
return;
sprite.LayerSetState(TurnstileVisualLayers.Base, new RSI.StateId(ent.Comp.DefaultState));
}
private void OnExamined(Entity<TurnstileComponent> ent, ref ExaminedEvent args)
{
Spawn(_examineArrow, new EntityCoordinates(ent, 0, 0));
}
protected override void PlayAnimation(EntityUid uid, string stateId)
{
if (!TryComp<AnimationPlayerComponent>(uid, out var animation) || !TryComp<SpriteComponent>(uid, out var sprite))
return;
var ent = (uid, animation);
if (_animationPlayer.HasRunningAnimation(animation, AnimationKey))
_animationPlayer.Stop(ent, AnimationKey);
if (sprite.BaseRSI == null || !sprite.BaseRSI.TryGetState(stateId, out var state))
return;
var animLength = state.AnimationLength;
var anim = new Animation
{
AnimationTracks =
{
new AnimationTrackSpriteFlick
{
LayerKey = TurnstileVisualLayers.Base,
KeyFrames =
{
new AnimationTrackSpriteFlick.KeyFrame(state.StateId, 0f),
},
},
},
Length = TimeSpan.FromSeconds(animLength),
};
_animationPlayer.Play(ent, anim, AnimationKey);
}
}