Fix sound-on-use spam (#7342)
This commit is contained in:
@@ -9,5 +9,16 @@ namespace Content.Server.Interaction.Components
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class EmitSoundOnUseComponent : BaseEmitSoundComponent
|
public sealed class EmitSoundOnUseComponent : BaseEmitSoundComponent
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not to mark an interaction as handled after playing the sound. Useful if this component is
|
||||||
|
/// used to play sound for some other component with on-use functionality
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// If false, you should be confident that the interaction will also be handled by some other system, as
|
||||||
|
/// otherwise this might enable sound spamming, as use-delays are only initiated if the interaction was
|
||||||
|
/// handled.
|
||||||
|
/// </remarks>
|
||||||
|
[DataField("handle")]
|
||||||
|
public bool Handle = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,16 @@ namespace Content.Server.Sound.Components
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class EmitSoundOnActivateComponent : BaseEmitSoundComponent
|
public sealed class EmitSoundOnActivateComponent : BaseEmitSoundComponent
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not to mark an interaction as handled after playing the sound. Useful if this component is
|
||||||
|
/// used to play sound for some other component with activation functionality.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// If false, you should be confident that the interaction will also be handled by some other system, as
|
||||||
|
/// otherwise this might enable sound spamming, as use-delays are only initiated if the interaction was
|
||||||
|
/// handled.
|
||||||
|
/// </remarks>
|
||||||
|
[DataField("handle")]
|
||||||
|
public bool Handle = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,10 +41,13 @@ namespace Content.Server.Sound
|
|||||||
TryEmitSound(component);
|
TryEmitSound(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleEmitSoundOnUseInHand(EntityUid eUI, BaseEmitSoundComponent component, UseInHandEvent arg)
|
private void HandleEmitSoundOnUseInHand(EntityUid eUI, EmitSoundOnUseComponent component, UseInHandEvent arg)
|
||||||
{
|
{
|
||||||
// Intentionally not handling interaction. This component is an easy way to add sounds in addition to other behavior.
|
// Intentionally not checking whether the interaction has already been handled.
|
||||||
TryEmitSound(component);
|
TryEmitSound(component);
|
||||||
|
|
||||||
|
if (component.Handle)
|
||||||
|
arg.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleEmitSoundOnThrown(EntityUid eUI, BaseEmitSoundComponent component, ThrownEvent arg)
|
private void HandleEmitSoundOnThrown(EntityUid eUI, BaseEmitSoundComponent component, ThrownEvent arg)
|
||||||
@@ -52,10 +55,13 @@ namespace Content.Server.Sound
|
|||||||
TryEmitSound(component);
|
TryEmitSound(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleEmitSoundOnActivateInWorld(EntityUid eUI, BaseEmitSoundComponent component, ActivateInWorldEvent arg)
|
private void HandleEmitSoundOnActivateInWorld(EntityUid eUI, EmitSoundOnActivateComponent component, ActivateInWorldEvent arg)
|
||||||
{
|
{
|
||||||
// Intentionally not handling interaction. This component is an easy way to add sounds in addition to other behavior.
|
// Intentionally not checking whether the interaction has already been handled.
|
||||||
TryEmitSound(component);
|
TryEmitSound(component);
|
||||||
|
|
||||||
|
if (component.Handle)
|
||||||
|
arg.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TryEmitSound(BaseEmitSoundComponent component)
|
private void TryEmitSound(BaseEmitSoundComponent component)
|
||||||
|
|||||||
Reference in New Issue
Block a user