[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:
Víctor Aguilera Puerto
2019-03-28 14:31:49 +01:00
committed by Pieter-Jan Briers
parent 8926669f3a
commit d090e98bd4
21 changed files with 350 additions and 31 deletions

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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);

View File

@@ -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>