Add API to change the sound of AmbientSoundComponent (#18115)

This commit is contained in:
Abbey Armbruster
2023-08-03 06:36:10 -04:00
committed by GitHub
parent 0a9164d857
commit f708a8dbf5
3 changed files with 27 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
namespace Content.Shared.Audio;
@@ -45,12 +46,23 @@ public abstract class SharedAmbientSoundSystem : EntitySystem
Dirty(ambience);
}
public virtual void SetSound(EntityUid uid, SoundSpecifier sound, AmbientSoundComponent? ambience = null)
{
if (!Resolve(uid, ref ambience, false) || ambience.Sound == sound)
return;
ambience.Sound = sound;
QueueUpdate(uid, ambience);
Dirty(ambience);
}
private void HandleCompState(EntityUid uid, AmbientSoundComponent component, ref ComponentHandleState args)
{
if (args.Current is not AmbientSoundComponentState state) return;
SetAmbience(uid, state.Enabled, component);
SetRange(uid, state.Range, component);
SetVolume(uid, state.Volume, component);
SetSound(uid, state.Sound, component);
}
private void GetCompState(EntityUid uid, AmbientSoundComponent component, ref ComponentGetState args)
@@ -60,6 +72,7 @@ public abstract class SharedAmbientSoundSystem : EntitySystem
Enabled = component.Enabled,
Range = component.Range,
Volume = component.Volume,
Sound = component.Sound,
};
}
}