Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancellable audio #5632

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 PlayAudioAttemptEvent();
RaiseLocalEvent(uid, ref 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 PlayAudioAttemptEvent();
RaiseLocalEvent(uid, ref 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
6 changes: 6 additions & 0 deletions Robust.Shared/Audio/Components/AudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,9 @@ 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>
[ByRefEvent]
public record struct PlayAudioAttemptEvent(bool Cancelled = false);
Comment on lines +278 to +283
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clientside equivalents to PlayPvs should also be raising this as well.

Loading