Puddles & spreader refactor (#15191)
This commit is contained in:
17
Content.Shared/Movement/Events/GetFootstepSoundEvent.cs
Normal file
17
Content.Shared/Movement/Events/GetFootstepSoundEvent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Shared.Movement.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised directed on an entity when trying to get a relevant footstep sound
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct GetFootstepSoundEvent(EntityUid User)
|
||||
{
|
||||
public readonly EntityUid User = User;
|
||||
|
||||
/// <summary>
|
||||
/// Set the sound to specify a footstep sound and mark as handled.
|
||||
/// </summary>
|
||||
public SoundSpecifier? Sound;
|
||||
}
|
||||
@@ -466,10 +466,9 @@ namespace Content.Shared.Movement.Systems
|
||||
private bool TryGetFootstepSound(TransformComponent xform, bool haveShoes, [NotNullWhen(true)] out SoundSpecifier? sound)
|
||||
{
|
||||
sound = null;
|
||||
MapGridComponent? grid;
|
||||
|
||||
// Fallback to the map?
|
||||
if (xform.GridUid == null)
|
||||
if (!_mapManager.TryGetGrid(xform.GridUid, out var grid))
|
||||
{
|
||||
if (TryComp<FootstepModifierComponent>(xform.MapUid, out var modifier))
|
||||
{
|
||||
@@ -480,8 +479,8 @@ namespace Content.Shared.Movement.Systems
|
||||
return false;
|
||||
}
|
||||
|
||||
grid = _mapManager.GetGrid(xform.GridUid.Value);
|
||||
var position = grid.LocalToTile(xform.Coordinates);
|
||||
var soundEv = new GetFootstepSoundEvent(xform.Owner);
|
||||
|
||||
// If the coordinates have a FootstepModifier component
|
||||
// i.e. component that emit sound on footsteps emit that sound
|
||||
@@ -489,6 +488,14 @@ namespace Content.Shared.Movement.Systems
|
||||
|
||||
while (anchored.MoveNext(out var maybeFootstep))
|
||||
{
|
||||
RaiseLocalEvent(maybeFootstep.Value, ref soundEv);
|
||||
|
||||
if (soundEv.Sound != null)
|
||||
{
|
||||
sound = soundEv.Sound;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TryComp<FootstepModifierComponent>(maybeFootstep, out var footstep))
|
||||
{
|
||||
sound = footstep.Sound;
|
||||
|
||||
Reference in New Issue
Block a user