Skip to content

Commit

Permalink
cancellable audio
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryImMouse committed Jan 24, 2025
1 parent e03aec4 commit 891255c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Robust.Server/Audio/AudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string?
if (TerminatingOrDeleted(uid))
return null;

var ev = new AudioPlayAttempt();
RaiseLocalEvent(uid, ev, false);
if (ev.Cancelled)
return null;

var entity = SetupAudio(filename, audioParams);
// Move it after setting it up
XformSystem.SetCoordinates(entity, new EntityCoordinates(uid, Vector2.Zero));
Expand All @@ -118,6 +123,11 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? fi
if (TerminatingOrDeleted(uid))
return null;

var ev = new AudioPlayAttempt();
RaiseLocalEvent(uid, ev, false);
if (ev.Cancelled)
return null;

var entity = SetupAudio(filename, audioParams);
XformSystem.SetCoordinates(entity, new EntityCoordinates(uid, Vector2.Zero));

Expand Down Expand Up @@ -162,6 +172,7 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? fi
if (!coordinates.IsValid(EntityManager))
return null;


// TODO: Transform TryFindGridAt mess + optimisation required.
var entity = SetupAudio(filename, audioParams);
XformSystem.SetCoordinates(entity, coordinates);
Expand Down
5 changes: 5 additions & 0 deletions Robust.Shared/Audio/Components/AudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,8 @@ public enum AudioFlags : byte

NoOcclusion = 1 << 1,
}

/// <summary>
/// Raised directed at an entity, which is emitting the audio. Raised only when audio played at the entity itself, not the coordinates.
/// </summary>
public sealed class AudioPlayAttempt : CancellableEntityEventArgs;

0 comments on commit 891255c

Please sign in to comment.