mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using Content.Shared.Movement.Components;
|
|
using Content.Shared.Movement.Events;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Movement.Systems;
|
|
|
|
/// <summary>
|
|
/// Plays a sound on MoveInputEvent.
|
|
/// </summary>
|
|
public sealed partial class MovementSoundSystem : EntitySystem
|
|
{
|
|
[Dependency] private IGameTiming _timing = default!;
|
|
[Dependency] private SharedAudioSystem _audio = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<MovementSoundComponent, MoveInputEvent>(OnMoveInput);
|
|
}
|
|
|
|
private void OnMoveInput(Entity<MovementSoundComponent> ent, ref MoveInputEvent args)
|
|
{
|
|
if (!_timing.IsFirstTimePredicted)
|
|
return;
|
|
|
|
var oldMoving = (SharedMoverController.GetNormalizedMovement(args.OldMovement) & MoveButtons.AnyDirection) != MoveButtons.None;
|
|
var moving = (SharedMoverController.GetNormalizedMovement(args.Entity.Comp.HeldMoveButtons) & MoveButtons.AnyDirection) != MoveButtons.None;
|
|
|
|
if (oldMoving == moving)
|
|
return;
|
|
|
|
if (moving)
|
|
{
|
|
DebugTools.Assert(ent.Comp.SoundEntity == null);
|
|
ent.Comp.SoundEntity = _audio.PlayPredicted(ent.Comp.Sound, ent.Owner, ent.Owner)?.Entity;
|
|
}
|
|
else
|
|
{
|
|
ent.Comp.SoundEntity = _audio.Stop(ent.Comp.SoundEntity);
|
|
}
|
|
}
|
|
}
|