Rename SoundComponent and refactor its wrong usages. (#1036)

* Rename `SoundComponent` and refactor its wrong usages.

* Replace verbose IoC grabs with EntitySysetm.Get

* unused depend

Co-authored-by: FL-OZ <anotherscuffed@gmail.com>
Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
FL-OZ
2020-05-31 12:40:36 -05:00
committed by GitHub
parent 8db5adb387
commit 53900b79e9
30 changed files with 137 additions and 97 deletions

View File

@@ -6,6 +6,7 @@ using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Items;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Physics;
@@ -109,7 +110,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
if(OnHitEntities(hitEntities)) return;
var audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>();
var audioSystem = EntitySystem.Get<AudioSystem>();
var emitter = hitEntities.Count == 0 ? eventArgs.User : hitEntities[0];
audioSystem.Play(hitEntities.Count > 0 ? _hitSound : "/Audio/weapons/punchmiss.ogg", emitter);

View File

@@ -11,6 +11,7 @@ using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
@@ -86,7 +87,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
if (!Activated || entities.Count == 0 || cell == null || !cell.CanDeductCharge(EnergyPerUse))
return false;
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/weapons/egloves.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
EntitySystem.Get<AudioSystem>().Play("/Audio/weapons/egloves.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
foreach (var entity in entities)
{
@@ -101,7 +102,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
cell.DeductCharge(EnergyPerUse);
if(cell.Charge < EnergyPerUse)
{
_entitySystemManager.GetEntitySystem<AudioSystem>().Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
EntitySystem.Get<AudioSystem>().Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
TurnOff();
}
@@ -132,7 +133,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
var sprite = Owner.GetComponent<SpriteComponent>();
var item = Owner.GetComponent<ItemComponent>();
_entitySystemManager.GetEntitySystem<AudioSystem>().Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
EntitySystem.Get<AudioSystem>().Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
item.EquippedPrefix = "off";
sprite.LayerSetState(0, "stunbaton_off");
@@ -152,7 +153,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
if (cell == null)
{
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/machines/button.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
EntitySystem.Get<AudioSystem>().Play("/Audio/machines/button.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
_notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Cell missing..."));
return;
@@ -160,12 +161,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
if (cell.Charge < EnergyPerUse)
{
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/machines/button.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
EntitySystem.Get<AudioSystem>().Play("/Audio/machines/button.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
_notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Dead cell..."));
return;
}
_entitySystemManager.GetEntitySystem<AudioSystem>().Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
EntitySystem.Get<AudioSystem>().Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
item.EquippedPrefix = "on";
sprite.LayerSetState(0, "stunbaton_on");
@@ -192,7 +193,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
return false;
}
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/items/weapons/pistol_magin.ogg");
EntitySystem.Get<AudioSystem>().Play("/Audio/items/weapons/pistol_magin.ogg");
Dirty();
@@ -223,7 +224,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
cell.Owner.Transform.GridPosition = user.Transform.GridPosition;
}
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/items/weapons/pistol_magout.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
EntitySystem.Get<AudioSystem>().Play("/Audio/items/weapons/pistol_magout.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
}
public void Examine(FormattedMessage message)

View File

@@ -27,6 +27,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
[RegisterComponent]
public class HitscanWeaponComponent : Component, IInteractUsing
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
private const float MaxLength = 20;
public override string Name => "HitscanWeapon";
@@ -134,7 +137,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
Shaded = false
};
EntitySystem.Get<EffectSystem>().CreateParticle(message);
Owner.GetComponent<SoundComponent>().Play(_fireSound, AudioParams.Default.WithVolume(-5));
EntitySystem.Get<AudioSystem>().Play(_fireSound, Owner, AudioParams.Default.WithVolume(-5));
}
}
}

View File

@@ -8,9 +8,11 @@ using Content.Shared.GameObjects.Components.Weapons.Ranged;
using Content.Shared.Interfaces;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
@@ -28,6 +30,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
[RegisterComponent]
public class BallisticMagazineWeaponComponent : BallisticWeaponComponent, IUse, IInteractUsing, IMapInit
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
private const float BulletOffset = 0.2f;
public override string Name => "BallisticMagazineWeapon";
@@ -105,7 +111,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
}
if (_magInSound != null && playSound)
{
Owner.GetComponent<SoundComponent>().Play(_magInSound);
EntitySystem.Get<AudioSystem>().Play(_magInSound, Owner);
}
magazinetype.OnAmmoCountChanged += MagazineAmmoCountChanged;
if (GetChambered(0) == null)
@@ -134,7 +140,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
entity.Transform.GridPosition = Owner.Transform.GridPosition;
if (_magOutSound != null && playSound)
{
Owner.GetComponent<SoundComponent>().Play(_magOutSound, AudioParams.Default.WithVolume(20));
EntitySystem.Get<AudioSystem>().Play(_magOutSound, Owner, AudioParams.Default.WithVolume(20));
}
UpdateAppearance();
Dirty();
@@ -160,7 +166,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
entity.Transform.GridPosition = Owner.Transform.GridPosition.Offset(offsetPos);
entity.Transform.LocalRotation = _bulletDropRandom.Pick(RandomBulletDirs).ToAngle();
var effect = $"/Audio/Guns/Casings/casingfall{_bulletDropRandom.Next(1, 4)}.ogg";
Owner.GetComponent<SoundComponent>().Play(effect, AudioParams.Default.WithVolume(-3));
EntitySystem.Get<AudioSystem>().Play(effect, Owner, AudioParams.Default.WithVolume(-3));
if (Magazine != null)
{
@@ -191,7 +197,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
EjectMagazine();
if (_autoEjectSound != null)
{
Owner.GetComponent<SoundComponent>().Play(_autoEjectSound, AudioParams.Default.WithVolume(-5));
EntitySystem.Get<AudioSystem>().Play(_autoEjectSound, Owner, AudioParams.Default.WithVolume(-5));
}
Dirty();
}

View File

@@ -5,6 +5,9 @@ using Robust.Shared.Map;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
{
@@ -13,6 +16,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
/// </summary>
public abstract class BallisticWeaponComponent : BaseProjectileWeaponComponent
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
private Chamber[] _chambers;
/// <summary>
@@ -132,7 +139,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
return true;
}
private void PlayEmptySound() => Owner.GetComponent<SoundComponent>().Play(_soundGunEmpty);
private void PlayEmptySound() => EntitySystem.Get<AudioSystem>().Play(_soundGunEmpty, Owner);
protected sealed class Chamber
{

View File

@@ -1,6 +1,5 @@
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Projectiles;
using Content.Server.GameObjects.Components.Sound;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
@@ -12,6 +11,8 @@ using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System.Collections.Generic;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
@@ -28,6 +29,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
#pragma warning disable 649
[Dependency] private IRobustRandom _spreadRandom;
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
public override void ExposeData(ObjectSerializer serializer)
@@ -75,7 +77,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
}
}
private void PlayFireSound() => Owner.GetComponent<SoundComponent>().Play(_soundGunshot);
private void PlayFireSound() => EntitySystem.Get<AudioSystem>().Play(_soundGunshot, Owner);
/// <summary>
/// Gets the angle from an entity to a coordinate.