[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
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Interactable.Tools;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Construction;
|
||||
@@ -28,7 +29,6 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
|
||||
SpriteComponent Sprite;
|
||||
ITransformComponent Transform;
|
||||
AudioSystem AudioSystem;
|
||||
Random random;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -38,7 +38,6 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
Sprite = Owner.GetComponent<SpriteComponent>();
|
||||
Transform = Owner.GetComponent<ITransformComponent>();
|
||||
var systemman = IoCManager.Resolve<IEntitySystemManager>();
|
||||
AudioSystem = systemman.GetEntitySystem<AudioSystem>();
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
@@ -95,6 +94,8 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
|
||||
bool TryProcessStep(ConstructionStep step, IEntity slapped)
|
||||
{
|
||||
var sound = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>();
|
||||
|
||||
switch (step)
|
||||
{
|
||||
case ConstructionStepMaterial matStep:
|
||||
@@ -105,9 +106,9 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
return false;
|
||||
}
|
||||
if (matStep.Material == MaterialType.Cable)
|
||||
AudioSystem.Play("/Audio/items/zip.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/zip.ogg", Transform.GridPosition);
|
||||
else
|
||||
AudioSystem.Play("/Audio/items/deconstruct.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/deconstruct.ogg", Transform.GridPosition);
|
||||
return true;
|
||||
case ConstructionStepTool toolStep:
|
||||
switch (toolStep.Tool)
|
||||
@@ -115,7 +116,7 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
case ToolType.Crowbar:
|
||||
if (slapped.HasComponent<CrowbarComponent>())
|
||||
{
|
||||
AudioSystem.Play("/Audio/items/crowbar.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/crowbar.ogg", Transform.GridPosition);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -123,16 +124,16 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
if (slapped.TryGetComponent(out WelderComponent welder) && welder.TryUse(toolStep.Amount))
|
||||
{
|
||||
if (random.NextDouble() > 0.5)
|
||||
AudioSystem.Play("/Audio/items/welder.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/welder.ogg", Transform.GridPosition);
|
||||
else
|
||||
AudioSystem.Play("/Audio/items/welder2.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/welder2.ogg", Transform.GridPosition);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case ToolType.Wrench:
|
||||
if (slapped.HasComponent<WrenchComponent>())
|
||||
{
|
||||
AudioSystem.Play("/Audio/items/ratchet.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/ratchet.ogg", Transform.GridPosition);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -140,16 +141,16 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
if (slapped.HasComponent<ScrewdriverComponent>())
|
||||
{
|
||||
if (random.NextDouble() > 0.5)
|
||||
AudioSystem.Play("/Audio/items/screwdriver.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/screwdriver.ogg", Transform.GridPosition);
|
||||
else
|
||||
AudioSystem.Play("/Audio/items/screwdriver2.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/screwdriver2.ogg", Transform.GridPosition);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case ToolType.Wirecutters:
|
||||
if (slapped.HasComponent<WirecutterComponent>())
|
||||
{
|
||||
AudioSystem.Play("/Audio/items/wirecutter.ogg", Transform.GridPosition);
|
||||
sound.Play("/Audio/items/wirecutter.ogg", Transform.GridPosition);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Materials;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Construction;
|
||||
@@ -75,8 +76,7 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
|
||||
// OK WE'RE GOOD CONSTRUCTION STARTED.
|
||||
var entMgr = IoCManager.Resolve<IServerEntityManager>();
|
||||
var AudioSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>();
|
||||
AudioSystem.Play("/Audio/items/deconstruct.ogg", loc);
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().Play("/Audio/items/deconstruct.ogg", loc);
|
||||
if (prototype.Stages.Count == 2)
|
||||
{
|
||||
// Exactly 2 stages, so don't make an intermediate frame.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameObjects.Components.UserInterface;
|
||||
@@ -118,8 +119,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
|
||||
private void _clickSound()
|
||||
{
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>()
|
||||
.Play("/Audio/machines/machine_switch.ogg", Owner, AudioParams.Default.WithVolume(-2f));
|
||||
Owner.GetComponent<SoundComponent>().Play("/Audio/machines/machine_switch.ogg", AudioParams.Default.WithVolume(-2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
@@ -150,8 +151,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
if (time > _lastThunk + _thunkDelay)
|
||||
{
|
||||
_lastThunk = time;
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>()
|
||||
.Play("/Audio/machines/light_tube_on.ogg", Owner, AudioParams.Default.WithVolume(-10f));
|
||||
Owner.GetComponent<SoundComponent>().Play("/Audio/machines/light_tube_on.ogg", AudioParams.Default.WithVolume(-10f));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Sound;
|
||||
using SS14.Server.GameObjects.EntitySystems;
|
||||
using SS14.Shared.Audio;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.Network;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.Map;
|
||||
using SS14.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Sound
|
||||
{
|
||||
public class SoundComponent : SharedSoundComponent
|
||||
{
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ using SS14.Shared.Maths;
|
||||
using SS14.Shared.Physics;
|
||||
using SS14.Shared.Serialization;
|
||||
using System;
|
||||
using SS14.Shared.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using SS14.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
|
||||
{
|
||||
@@ -81,7 +82,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
|
||||
};
|
||||
var mgr = IoCManager.Resolve<IEntitySystemManager>();
|
||||
mgr.GetEntitySystem<EffectSystem>().CreateParticle(message);
|
||||
mgr.GetEntitySystem<AudioSystem>().Play("/Audio/laser.ogg", Owner, AudioParams.Default.WithVolume(-5));
|
||||
Owner.GetComponent<SoundComponent>().Play("/Audio/laser.ogg", AudioParams.Default.WithVolume(-5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
||||
@@ -110,8 +111,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
|
||||
if (_magInSound != null)
|
||||
{
|
||||
var audioSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>();
|
||||
audioSystem.Play(_magInSound, Owner);
|
||||
Owner.GetComponent<SoundComponent>().Play(_magInSound);
|
||||
}
|
||||
|
||||
component.OnAmmoCountChanged += _magazineAmmoCountChanged;
|
||||
@@ -142,8 +142,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
entity.Transform.GridPosition = Owner.Transform.GridPosition;
|
||||
if (_magOutSound != null)
|
||||
{
|
||||
var audioSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>();
|
||||
audioSystem.Play(_magOutSound, Owner);
|
||||
Owner.GetComponent<SoundComponent>().Play(_magOutSound);
|
||||
}
|
||||
|
||||
_updateAppearance();
|
||||
@@ -163,9 +162,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
var entity = RemoveFromChamber(chamber);
|
||||
entity.Transform.GridPosition = Owner.Transform.GridPosition;
|
||||
entity.Transform.LocalRotation = _bulletDropRandom.Pick(_randomBulletDirs).ToAngle();
|
||||
var audioSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>();
|
||||
var effect = $"/Audio/items/weapons/casingfall{_bulletDropRandom.Next(1, 4)}.ogg";
|
||||
audioSystem.Play(effect, entity, AudioParams.Default.WithVolume(-3));
|
||||
Owner.GetComponent<SoundComponent>().Play(effect, AudioParams.Default.WithVolume(-3));
|
||||
|
||||
if (Magazine != null)
|
||||
{
|
||||
@@ -181,7 +179,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
EjectMagazine();
|
||||
if (_autoEjectSound != null)
|
||||
{
|
||||
audioSystem.Play(_autoEjectSound, Owner, AudioParams.Default.WithVolume(-5));
|
||||
Owner.GetComponent<SoundComponent>().Play(_autoEjectSound, AudioParams.Default.WithVolume(-5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Interactable;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Shared.GameObjects;
|
||||
using SS14.Server.Chat;
|
||||
using SS14.Server.GameObjects.Components.Container;
|
||||
@@ -69,8 +70,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
{
|
||||
if (_soundGunEmpty != null)
|
||||
{
|
||||
var audioSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>();
|
||||
audioSystem.Play(_soundGunEmpty, Owner);
|
||||
Owner.GetComponent<SoundComponent>().Play(_soundGunEmpty);
|
||||
}
|
||||
}
|
||||
var chambered = GetChambered(0);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Projectiles;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameObjects.EntitySystems;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
@@ -90,7 +91,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
projectile.Transform.LocalRotation = angle.Theta;
|
||||
|
||||
// Sound!
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().Play("/Audio/gunshot_c20.ogg", user);
|
||||
Owner.GetComponent<SoundComponent>().Play("/Audio/gunshot_c20.ogg");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user