Use entity queries in ambient sound & power receiver systems (#26410)

This commit is contained in:
Leon Friedrich
2024-03-25 11:52:05 +11:00
committed by GitHub
parent 451890b85b
commit 31d70db547
2 changed files with 18 additions and 10 deletions

View File

@@ -5,16 +5,19 @@ namespace Content.Shared.Audio;
public abstract class SharedAmbientSoundSystem : EntitySystem
{
private EntityQuery<AmbientSoundComponent> _query;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AmbientSoundComponent, ComponentGetState>(GetCompState);
SubscribeLocalEvent<AmbientSoundComponent, ComponentHandleState>(HandleCompState);
_query = GetEntityQuery<AmbientSoundComponent>();
}
public virtual void SetAmbience(EntityUid uid, bool value, AmbientSoundComponent? ambience = null)
{
if (!Resolve(uid, ref ambience, false) || ambience.Enabled == value)
if (!_query.Resolve(uid, ref ambience, false) || ambience.Enabled == value)
return;
ambience.Enabled = value;
@@ -24,7 +27,7 @@ public abstract class SharedAmbientSoundSystem : EntitySystem
public virtual void SetRange(EntityUid uid, float value, AmbientSoundComponent? ambience = null)
{
if (!Resolve(uid, ref ambience, false) || MathHelper.CloseToPercent(ambience.Range, value))
if (!_query.Resolve(uid, ref ambience, false) || MathHelper.CloseToPercent(ambience.Range, value))
return;
ambience.Range = value;
@@ -39,7 +42,7 @@ public abstract class SharedAmbientSoundSystem : EntitySystem
public virtual void SetVolume(EntityUid uid, float value, AmbientSoundComponent? ambience = null)
{
if (!Resolve(uid, ref ambience, false) || MathHelper.CloseToPercent(ambience.Volume, value))
if (!_query.Resolve(uid, ref ambience, false) || MathHelper.CloseToPercent(ambience.Volume, value))
return;
ambience.Volume = value;
@@ -48,7 +51,7 @@ public abstract class SharedAmbientSoundSystem : EntitySystem
public virtual void SetSound(EntityUid uid, SoundSpecifier sound, AmbientSoundComponent? ambience = null)
{
if (!Resolve(uid, ref ambience, false) || ambience.Sound == sound)
if (!_query.Resolve(uid, ref ambience, false) || ambience.Sound == sound)
return;
ambience.Sound = sound;