#4219 some small project tweaks

This commit is contained in:
Galactic Chimp
2021-06-27 21:55:18 +02:00
parent 4a2b9832ce
commit 6cae00bb13
9 changed files with 8 additions and 66 deletions

View File

@@ -0,0 +1,18 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Sound.Components
{
/// <summary>
/// Base sound emitter which defines most of the data fields.
/// Default behavior is to first try to play the sound collection,
/// and if one isn't assigned, then try to play the single sound.
/// </summary>
public abstract class BaseEmitSoundComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)] [DataField("sound")] public string? SoundName { get; set; } = default!;
[ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float PitchVariation { get; set; } = 0.0f;
[ViewVariables(VVAccess.ReadWrite)] [DataField("soundCollection")] public string? SoundCollectionName { get; set; } = default!;
}
}

View File

@@ -0,0 +1,14 @@
using Robust.Shared.GameObjects;
namespace Content.Server.Sound.Components
{
/// <summary>
/// Simple sound emitter that emits sound on ActivateInWorld
/// </summary>
[RegisterComponent]
public class EmitSoundOnActivateComponent : BaseEmitSoundComponent
{
/// <inheritdoc />
public override string Name => "EmitSoundOnActivate";
}
}

View File

@@ -0,0 +1,14 @@
using Robust.Shared.GameObjects;
namespace Content.Server.Sound.Components
{
/// <summary>
/// Simple sound emitter that emits sound on LandEvent
/// </summary>
[RegisterComponent]
public class EmitSoundOnLandComponent : BaseEmitSoundComponent
{
/// <inheritdoc />
public override string Name => "EmitSoundOnLand";
}
}

View File

@@ -0,0 +1,67 @@
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Network;
namespace Content.Server.Sound.Components
{
[RegisterComponent]
public class LoopingLoopingSoundComponent : SharedLoopingSoundComponent
{
/// <summary>
/// Stops all sounds.
/// </summary>
/// <param name="channel">User that will be affected.</param>
public void StopAllSounds(INetChannel? channel)
{
SendNetworkMessage(new StopAllSoundsMessage(), channel);
}
/// <summary>
/// Stops a certain scheduled sound from playing.
/// </summary>
/// <param name="channel">User that will be affected.</param>
public void StopScheduledSound(string filename, INetChannel? channel)
{
SendNetworkMessage(new StopSoundScheduleMessage() {Filename = filename}, channel);
}
/// <summary>
/// Adds an scheduled sound to be played.
/// </summary>
/// <param name="channel">User that will be affected.</param>
public void AddScheduledSound(ScheduledSound schedule, INetChannel? channel)
{
SendNetworkMessage(new ScheduledSoundMessage() {Schedule = schedule}, channel);
}
public override void StopAllSounds()
{
StopAllSounds(null);
}
public override void StopScheduledSound(string filename)
{
StopScheduledSound(filename, null);
}
public override void AddScheduledSound(ScheduledSound schedule)
{
AddScheduledSound(schedule, null);
}
/// <summary>
/// Play an audio file following the entity.
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="channel">User that will be affected.</param>
public void Play(string filename, AudioParams? audioParams = null, INetChannel? channel = null)
{
AddScheduledSound(new ScheduledSound()
{
Filename = filename,
AudioParams = audioParams,
}, channel);
}
}
}