replacing sound (collection) names with SoundSpecifier - part 1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -38,7 +39,7 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
public IReadOnlyList<IReactionEffect> Effects => _effects;
|
||||
|
||||
// TODO SERV3: Empty on the client, (de)serialize on the server with module manager is server module
|
||||
[DataField("sound", serverOnly: true)] public string? Sound { get; private set; } = "/Audio/Effects/Chemistry/bubbles.ogg";
|
||||
[DataField("sound", serverOnly: true)] public SoundSpecifier Sound { get; private set; } = new SoundPathSpecifier("/Audio/Effects/Chemistry/bubbles.ogg");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using Content.Shared.NetIDs;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Gravity
|
||||
@@ -14,6 +16,9 @@ namespace Content.Shared.Gravity
|
||||
public override string Name => "Gravity";
|
||||
public override uint? NetID => ContentNetIDs.GRAVITY;
|
||||
|
||||
[DataField("gravityShakeSound")]
|
||||
public SoundSpecifier GravityShakeSound { get; set; } = new SoundPathSpecifier("/Audio/Effects/alert.ogg");
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Enabled
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#nullable enable
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -17,7 +18,7 @@ namespace Content.Shared.Kitchen.Components
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("sound")]
|
||||
protected string? SpikeSound = "/Audio/Effects/Fluids/splat.ogg";
|
||||
protected SoundSpecifier SpikeSound = new SoundPathSpecifier("/Audio/Effects/Fluids/splat.ogg");
|
||||
|
||||
bool IDragDropOn.CanDragDropOn(DragDropEvent eventArgs)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -62,14 +63,14 @@ namespace Content.Shared.Light.Component
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("litSound")]
|
||||
protected string LitSound { get; set; } = string.Empty;
|
||||
protected SoundSpecifier LitSound { get; set; } = default!;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("loopedSound")]
|
||||
protected string LoopedSound { get; set; } = string.Empty;
|
||||
protected string LoopedSound { get; set; } = default!;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("dieSound")]
|
||||
protected string DieSound { get; set; } = string.Empty;
|
||||
protected SoundSpecifier DieSound { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
#nullable enable
|
||||
using Content.Shared.Sound;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Shared.Maps
|
||||
{
|
||||
@@ -30,7 +31,7 @@ namespace Content.Shared.Maps
|
||||
|
||||
[DataField("can_crowbar")] public bool CanCrowbar { get; private set; }
|
||||
|
||||
[DataField("footstep_sounds")] public string FootstepSounds { get; } = string.Empty;
|
||||
[DataField("footstep_sounds")] public SoundSpecifier FootstepSounds { get; } = default!;
|
||||
|
||||
[DataField("friction")] public float Friction { get; set; }
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Audio;
|
||||
using Content.Shared.EffectBlocker;
|
||||
using Content.Shared.Module;
|
||||
using Content.Shared.NetIDs;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Stunnable;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -36,7 +37,7 @@ namespace Content.Shared.Slippery
|
||||
private float _requiredSlipSpeed = 0.1f;
|
||||
private float _launchForwardsMultiplier = 1f;
|
||||
private bool _slippery = true;
|
||||
private string _slipSound = "/Audio/Effects/slip.ogg";
|
||||
private SoundSpecifier _slipSound = new SoundPathSpecifier("/Audio/Effects/slip.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// List of entities that are currently colliding with the entity.
|
||||
@@ -53,7 +54,7 @@ namespace Content.Shared.Slippery
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("slipSound")]
|
||||
public string SlipSound
|
||||
public SoundSpecifier SlipSound
|
||||
{
|
||||
get => _slipSound;
|
||||
set
|
||||
@@ -184,9 +185,9 @@ namespace Content.Shared.Slippery
|
||||
_slipped.Add(otherBody.Owner.Uid);
|
||||
Dirty();
|
||||
|
||||
if (!string.IsNullOrEmpty(SlipSound) && _moduleManager.IsServerModule)
|
||||
if (SlipSound.TryGetSound(out var slipSound) && _moduleManager.IsServerModule)
|
||||
{
|
||||
SoundSystem.Play(Filter.Broadcast(), SlipSound, Owner, AudioHelpers.WithVariation(0.2f));
|
||||
SoundSystem.Play(Filter.Broadcast(), slipSound, Owner, AudioHelpers.WithVariation(0.2f));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -232,7 +233,7 @@ namespace Content.Shared.Slippery
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new SlipperyComponentState(ParalyzeTime, IntersectPercentage, RequiredSlipSpeed, LaunchForwardsMultiplier, Slippery, SlipSound, _slipped.ToArray());
|
||||
return new SlipperyComponentState(ParalyzeTime, IntersectPercentage, RequiredSlipSpeed, LaunchForwardsMultiplier, Slippery, SlipSound.GetSound(), _slipped.ToArray());
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
@@ -244,7 +245,7 @@ namespace Content.Shared.Slippery
|
||||
_paralyzeTime = state.ParalyzeTime;
|
||||
_requiredSlipSpeed = state.RequiredSlipSpeed;
|
||||
_launchForwardsMultiplier = state.LaunchForwardsMultiplier;
|
||||
_slipSound = state.SlipSound;
|
||||
_slipSound = new SoundPathSpecifier(state.SlipSound);
|
||||
_slipped.Clear();
|
||||
|
||||
foreach (var slipped in state.Slipped)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using Content.Shared.Audio;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Shared.Sound
|
||||
{
|
||||
@@ -12,6 +11,8 @@ namespace Content.Shared.Sound
|
||||
public abstract class SoundSpecifier
|
||||
{
|
||||
public abstract string GetSound();
|
||||
|
||||
public abstract bool TryGetSound([NotNullWhen(true)] out string? sound);
|
||||
}
|
||||
|
||||
[DataDefinition]
|
||||
@@ -19,7 +20,7 @@ namespace Content.Shared.Sound
|
||||
{
|
||||
public const string Node = "path";
|
||||
|
||||
[DataField(Node, customTypeSerializer:typeof(ResourcePathSerializer), required:true)]
|
||||
[DataField(Node, customTypeSerializer: typeof(ResourcePathSerializer), required: true)]
|
||||
public ResourcePath? Path { get; }
|
||||
|
||||
public SoundPathSpecifier()
|
||||
@@ -40,6 +41,12 @@ namespace Content.Shared.Sound
|
||||
{
|
||||
return Path == null ? string.Empty : Path.ToString();
|
||||
}
|
||||
|
||||
public override bool TryGetSound([NotNullWhen(true)] out string? sound)
|
||||
{
|
||||
sound = GetSound();
|
||||
return !string.IsNullOrWhiteSpace(sound);
|
||||
}
|
||||
}
|
||||
|
||||
[DataDefinition]
|
||||
@@ -47,7 +54,7 @@ namespace Content.Shared.Sound
|
||||
{
|
||||
public const string Node = "collection";
|
||||
|
||||
[DataField(Node, customTypeSerializer:typeof(PrototypeIdSerializer<SoundCollectionPrototype>), required:true)]
|
||||
[DataField(Node, customTypeSerializer: typeof(PrototypeIdSerializer<SoundCollectionPrototype>), required: true)]
|
||||
public string? Collection { get; }
|
||||
|
||||
public SoundCollectionSpecifier()
|
||||
@@ -63,5 +70,11 @@ namespace Content.Shared.Sound
|
||||
{
|
||||
return Collection == null ? string.Empty : AudioHelpers.GetRandomFileFromSoundCollection(Collection);
|
||||
}
|
||||
|
||||
public override bool TryGetSound([NotNullWhen(true)] out string? sound)
|
||||
{
|
||||
sound = GetSound();
|
||||
return !string.IsNullOrWhiteSpace(sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Content.Shared.EffectBlocker;
|
||||
using Content.Shared.NetIDs;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -18,7 +19,7 @@ namespace Content.Shared.Standing
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("downSoundCollection")]
|
||||
public string? DownSoundCollection { get; } = "BodyFall";
|
||||
public SoundSpecifier DownSoundCollection { get; } = new SoundCollectionSpecifier("BodyFall");
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("standing")]
|
||||
|
||||
@@ -62,12 +62,9 @@ namespace Content.Shared.Standing
|
||||
}
|
||||
|
||||
// Currently shit is only downed by server but when it's predicted we can probably only play this on server / client
|
||||
var sound = component.DownSoundCollection;
|
||||
|
||||
if (playSound && !string.IsNullOrEmpty(sound))
|
||||
if (playSound && component.DownSoundCollection.TryGetSound(out var sound))
|
||||
{
|
||||
var file = AudioHelpers.GetRandomFileFromSoundCollection(sound);
|
||||
SoundSystem.Play(Filter.Pvs(entity), file, entity, AudioHelpers.WithVariation(0.25f));
|
||||
SoundSystem.Play(Filter.Pvs(entity), sound, entity, AudioHelpers.WithVariation(0.25f));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user