replacing sound (collection) names with SoundSpecifier - part 1

This commit is contained in:
Galactic Chimp
2021-07-10 17:35:33 +02:00
parent 4500b66f28
commit ce3c59e0e6
131 changed files with 934 additions and 587 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Content.Shared.Interaction;
using Content.Shared.NetIDs;
using Content.Shared.Sound;
using Content.Shared.Tool;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
@@ -32,13 +33,10 @@ namespace Content.Server.Tools.Components
public string Sprite { get; } = string.Empty;
[DataField("useSound")]
public string Sound { get; } = string.Empty;
[DataField("useSoundCollection")]
public string SoundCollection { get; } = string.Empty;
public SoundSpecifier Sound { get; } = default!;
[DataField("changeSound")]
public string ChangeSound { get; } = string.Empty;
public SoundSpecifier ChangeSound { get; } = default!;
}
public override string Name => "MultiTool";
@@ -62,8 +60,8 @@ namespace Content.Server.Tools.Components
_currentTool = (_currentTool + 1) % _tools.Count;
SetTool();
var current = _tools[_currentTool];
if(!string.IsNullOrEmpty(current.ChangeSound))
SoundSystem.Play(Filter.Pvs(Owner), current.ChangeSound, Owner);
if(current.ChangeSound.TryGetSound(out var changeSound))
SoundSystem.Play(Filter.Pvs(Owner), changeSound, Owner);
}
private void SetTool()
@@ -73,7 +71,6 @@ namespace Content.Server.Tools.Components
var current = _tools[_currentTool];
_tool.UseSound = current.Sound;
_tool.UseSoundCollection = current.SoundCollection;
_tool.Qualities = current.Behavior;
if (_sprite == null) return;

View File

@@ -4,6 +4,7 @@ using Content.Server.DoAfter;
using Content.Shared.ActionBlocker;
using Content.Shared.Audio;
using Content.Shared.Interaction.Events;
using Content.Shared.Sound;
using Content.Shared.Tool;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
@@ -44,10 +45,7 @@ namespace Content.Server.Tools.Components
public float SpeedModifier { get; set; } = 1;
[DataField("useSound")]
public string? UseSound { get; set; }
[DataField("useSoundCollection")]
public string? UseSoundCollection { get; set; }
public SoundSpecifier UseSound { get; set; } = default!;
public void AddQuality(ToolQuality quality)
{
@@ -96,30 +94,10 @@ namespace Content.Server.Tools.Components
return true;
}
protected void PlaySoundCollection(string? name, float volume = -5f)
public void PlayUseSound(float volume = -5f)
{
if (string.IsNullOrEmpty(name))
{
return;
}
var file = AudioHelpers.GetRandomFileFromSoundCollection(name);
SoundSystem.Play(Filter.Pvs(Owner), file, Owner, AudioHelpers.WithVariation(0.15f).WithVolume(volume));
}
public void PlayUseSound(float volume=-5f)
{
if (string.IsNullOrEmpty(UseSoundCollection))
{
if (!string.IsNullOrEmpty(UseSound))
{
SoundSystem.Play(Filter.Pvs(Owner), UseSound, Owner, AudioHelpers.WithVariation(0.15f).WithVolume(volume));
}
}
else
{
PlaySoundCollection(UseSoundCollection, volume);
}
if(UseSound.TryGetSound(out var useSound))
SoundSystem.Play(Filter.Pvs(Owner), useSound, Owner, AudioHelpers.WithVariation(0.15f).WithVolume(volume));
}
}
}

View File

@@ -8,6 +8,7 @@ using Content.Server.Chemistry.Components;
using Content.Server.Explosion;
using Content.Server.Items;
using Content.Server.Notification;
using Content.Shared.Audio;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Solution.Components;
@@ -16,6 +17,7 @@ using Content.Shared.Interaction;
using Content.Shared.NetIDs;
using Content.Shared.Notification;
using Content.Shared.Notification.Managers;
using Content.Shared.Sound;
using Content.Shared.Temperature;
using Content.Shared.Tool;
using Robust.Server.GameObjects;
@@ -58,8 +60,17 @@ namespace Content.Server.Tools.Components
private SolutionContainerComponent? _solutionComponent;
private PointLightComponent? _pointLightComponent;
[DataField("weldSoundCollection")]
public string? WeldSoundCollection { get; set; }
[DataField("weldSounds")]
private SoundSpecifier WeldSounds { get; set; } = default!;
[DataField("welderOffSounds")]
private SoundSpecifier WelderOffSounds { get; set; } = new SoundCollectionSpecifier("WelderOff");
[DataField("welderOnSounds")]
private SoundSpecifier WelderOnSounds { get; set; } = new SoundCollectionSpecifier("WelderOn");
[DataField("welderRefill")]
private SoundSpecifier WelderRefill { get; set; } = new SoundPathSpecifier("/Audio/Effects/refill.ogg");
[ViewVariables]
public float Fuel => _solutionComponent?.Solution?.GetReagentQuantity("WeldingFuel").Float() ?? 0f;
@@ -160,9 +171,9 @@ namespace Content.Server.Tools.Components
var succeeded = _solutionComponent.TryRemoveReagent("WeldingFuel", ReagentUnit.New(value));
if (succeeded && !silent)
if (succeeded && !silent && WeldSounds.TryGetSound(out var weldSounds))
{
PlaySoundCollection(WeldSoundCollection);
PlaySound(weldSounds);
}
return succeeded;
}
@@ -193,7 +204,8 @@ namespace Content.Server.Tools.Components
if (_pointLightComponent != null) _pointLightComponent.Enabled = false;
PlaySoundCollection("WelderOff", -5);
if(WelderOffSounds.TryGetSound(out var welderOffSOunds))
PlaySound(welderOffSOunds, -5);
_welderSystem.Unsubscribe(this);
return true;
}
@@ -210,7 +222,8 @@ namespace Content.Server.Tools.Components
if (_pointLightComponent != null) _pointLightComponent.Enabled = true;
PlaySoundCollection("WelderOn", -5);
if (WelderOnSounds.TryGetSound(out var welderOnSOunds))
PlaySound(welderOnSOunds, -5);
_welderSystem.Subscribe(this);
Owner.Transform.Coordinates
@@ -272,7 +285,8 @@ namespace Content.Server.Tools.Components
if (TryWeld(5, victim, silent: true))
{
PlaySoundCollection(WeldSoundCollection);
if(WeldSounds.TryGetSound(out var weldSound))
PlaySound(weldSound);
othersMessage =
Loc.GetString("welder-component-suicide-lit-others-message",
@@ -325,13 +339,18 @@ namespace Content.Server.Tools.Components
{
var drained = targetSolution.Drain(trans);
_solutionComponent.TryAddSolution(drained);
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Effects/refill.ogg", Owner);
if(WelderRefill.TryGetSound(out var welderRefillSound))
SoundSystem.Play(Filter.Pvs(Owner), welderRefillSound, Owner);
eventArgs.Target.PopupMessage(eventArgs.User, Loc.GetString("welder-component-after-interact-refueled-message"));
}
}
return true;
}
private void PlaySound(string soundName, float volume = -5f)
{
SoundSystem.Play(Filter.Pvs(Owner), soundName, Owner, AudioHelpers.WithVariation(0.15f).WithVolume(volume));
}
}
}