[Ready] SoundComponent (#164)
Requires https://github.com/space-wizards/space-station-14/pull/768 - [x] Play sounds - [x] SoundSchedules actually work - [x] Send sound to specific users - [x] Make existing components use SoundComponent - [x] Add ScheduledSounds from prototypes - [x] Add Play methods equivalent to those of AudioSystem. - [x] Document most code.
This commit is contained in:
committed by
Pieter-Jan Briers
parent
8926669f3a
commit
d090e98bd4
@@ -72,6 +72,7 @@
|
||||
<Compile Include="GameObjects\Components\Mobs\SharedCameraRecoilComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Power\PowerShared.cs" />
|
||||
<Compile Include="GameObjects\Components\Power\SharedPowerCellComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Sound\SharedSoundComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Storage\SharedStorageComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Weapons\Ranged\SharedBallisticMagazineComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Weapons\Ranged\SharedBallisticMagazineWeaponComponent.cs" />
|
||||
@@ -126,4 +127,4 @@
|
||||
<Compile Include="Construction\ConstructionPrototype.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Content.Shared.GameObjects;
|
||||
using SS14.Shared.Audio;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.Serialization;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Map;
|
||||
using SS14.Shared.Serialization;
|
||||
using SS14.Shared.Timers;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Sound
|
||||
{
|
||||
public class SharedSoundComponent : Component
|
||||
{
|
||||
public override string Name => "Sound";
|
||||
public override uint? NetID => ContentNetIDs.SOUND;
|
||||
|
||||
/// <summary>
|
||||
/// Stops all sounds.
|
||||
/// </summary>
|
||||
public virtual void StopAllSounds()
|
||||
{}
|
||||
|
||||
/// <summary>
|
||||
/// Stops a certain scheduled sound from playing.
|
||||
/// </summary>
|
||||
public virtual void StopScheduledSound(string filename)
|
||||
{}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an scheduled sound to be played.
|
||||
/// </summary>
|
||||
public virtual void AddScheduledSound(ScheduledSound scheduledSound)
|
||||
{}
|
||||
|
||||
/// <summary>
|
||||
/// Play an audio file following the entity.
|
||||
/// </summary>
|
||||
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
||||
public void Play(string filename, AudioParams? audioParams = null)
|
||||
{
|
||||
AddScheduledSound(new ScheduledSound()
|
||||
{
|
||||
Filename = filename,
|
||||
AudioParams = audioParams,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class ScheduledSoundMessage : ComponentMessage
|
||||
{
|
||||
public ScheduledSound Schedule;
|
||||
public ScheduledSoundMessage()
|
||||
{
|
||||
Directed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class StopSoundScheduleMessage : ComponentMessage
|
||||
{
|
||||
public string Filename;
|
||||
public StopSoundScheduleMessage()
|
||||
{
|
||||
Directed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class StopAllSoundsMessage : ComponentMessage
|
||||
{
|
||||
public StopAllSoundsMessage()
|
||||
{
|
||||
Directed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class ScheduledSound : IExposeData
|
||||
{
|
||||
public string Filename = "";
|
||||
|
||||
/// <summary>
|
||||
/// The parameters to play the sound with.
|
||||
/// </summary>
|
||||
public AudioParams? AudioParams;
|
||||
|
||||
/// <summary>
|
||||
/// Delay in milliseconds before playing the sound,
|
||||
/// and delay between repetitions if Times is not 0.
|
||||
/// </summary>
|
||||
public uint Delay = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of milliseconds to add to the delay randomly.
|
||||
/// Useful for random ambience noises. Generated value differs from client to client.
|
||||
/// </summary>
|
||||
public uint RandomDelay = 0;
|
||||
|
||||
/// <summary>
|
||||
/// How many times to repeat the sound. If it's 0, it will play the sound once.
|
||||
/// If it's less than 0, it will repeat the sound indefinitely.
|
||||
/// If it's greater than 0, it will play the sound n+1 times.
|
||||
/// </summary>
|
||||
public int Times = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the sound will play or not.
|
||||
/// </summary>
|
||||
public bool Play = true;
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
Filename = serializer.ReadDataField("filename", "");
|
||||
Delay = serializer.ReadDataField("delay", 0u);
|
||||
RandomDelay = serializer.ReadDataField("randomdelay", 0u);
|
||||
Times = serializer.ReadDataField("times", 0);
|
||||
AudioParams = serializer.ReadDataField("audioparams", SS14.Shared.Audio.AudioParams.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,6 @@
|
||||
public const uint SPECIES = 1009;
|
||||
public const uint RANGED_WEAPON = 1010;
|
||||
public const uint CAMERA_RECOIL = 1011;
|
||||
public const uint SOUND = 1012;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user