forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MovementSound (space-wizards#31313)
Mainly useful for medicalborg so you can get a looping sound and not footsteps playing over and over. Didn't actually update medborg because footsteps need updating. Not needed for AI.
- Loading branch information
1 parent
864c225
commit a2912e3
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Content.Shared/Movement/Components/MovementSoundComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Robust.Shared.Audio; | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.Movement.Components; | ||
|
||
/// <summary> | ||
/// Plays a sound whenever InputMover is running. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
public sealed partial class MovementSoundComponent : Component | ||
{ | ||
/// <summary> | ||
/// Sound to play when InputMover has inputs. | ||
/// </summary> | ||
[DataField(required: true), AutoNetworkedField] | ||
public SoundSpecifier? Sound; | ||
|
||
[DataField, AutoNetworkedField] | ||
public EntityUid? SoundEntity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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 class MovementSoundSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly 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); | ||
} | ||
} | ||
} |