Add ambient music (#16829)

This commit is contained in:
metalgearsloth
2023-05-29 10:44:11 +10:00
committed by GitHub
parent f35fcff23f
commit 0c83642c5a
84 changed files with 1252 additions and 338 deletions

View File

@@ -0,0 +1,39 @@
using Content.Shared.Random;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Audio;
/// <summary>
/// Attaches a rules prototype to sound files to play ambience.
/// </summary>
[Prototype("ambientMusic")]
public sealed class AmbientMusicPrototype : IPrototype
{
[IdDataField] public string ID { get; } = string.Empty;
/// <summary>
/// Traditionally you'd prioritise most rules to least as priority but in our case we'll just be explicit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("priority")]
public int Priority = 0;
/// <summary>
/// Can we interrupt this ambience for a better prototype if possible?
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("interruptable")]
public bool Interruptable = false;
/// <summary>
/// Do we fade-in. Useful for songs.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("fadeIn")]
public bool FadeIn;
[ViewVariables(VVAccess.ReadWrite), DataField("sound", required: true)]
public SoundSpecifier Sound = default!;
[ViewVariables(VVAccess.ReadWrite), DataField("rules", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<RulesPrototype>))]
public string Rules = string.Empty;
}

View File

@@ -4,48 +4,47 @@ using Robust.Shared.GameStates;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
namespace Content.Shared.Audio
namespace Content.Shared.Audio;
[RegisterComponent]
[NetworkedComponent]
[Access(typeof(SharedAmbientSoundSystem))]
public sealed class AmbientSoundComponent : Component, IComponentTreeEntry<AmbientSoundComponent>
{
[RegisterComponent]
[NetworkedComponent]
[Access(typeof(SharedAmbientSoundSystem))]
public sealed class AmbientSoundComponent : Component, IComponentTreeEntry<AmbientSoundComponent>
{
[DataField("enabled")]
[ViewVariables(VVAccess.ReadWrite)] // only for map editing
public bool Enabled { get; set; } = true;
[DataField("enabled")]
[ViewVariables(VVAccess.ReadWrite)] // only for map editing
public bool Enabled { get; set; } = true;
[DataField("sound", required: true), ViewVariables(VVAccess.ReadWrite)] // only for map editing
public SoundSpecifier Sound = default!;
[DataField("sound", required: true), ViewVariables(VVAccess.ReadWrite)] // only for map editing
public SoundSpecifier Sound = default!;
/// <summary>
/// How far away this ambient sound can potentially be heard.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] // only for map editing
[DataField("range")]
public float Range = 2f;
/// <summary>
/// How far away this ambient sound can potentially be heard.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] // only for map editing
[DataField("range")]
public float Range = 2f;
/// <summary>
/// Applies this volume to the sound being played.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] // only for map editing
[DataField("volume")]
public float Volume = -10f;
/// <summary>
/// Applies this volume to the sound being played.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] // only for map editing
[DataField("volume")]
public float Volume = -10f;
public EntityUid? TreeUid { get; set; }
public EntityUid? TreeUid { get; set; }
public DynamicTree<ComponentTreeEntry<AmbientSoundComponent>>? Tree { get; set; }
public DynamicTree<ComponentTreeEntry<AmbientSoundComponent>>? Tree { get; set; }
public bool AddToTree => Enabled;
public bool AddToTree => Enabled;
public bool TreeUpdateQueued { get; set; }
}
[Serializable, NetSerializable]
public sealed class AmbientSoundComponentState : ComponentState
{
public bool Enabled { get; init; }
public float Range { get; init; }
public float Volume { get; init; }
}
public bool TreeUpdateQueued { get; set; }
}
[Serializable, NetSerializable]
public sealed class AmbientSoundComponentState : ComponentState
{
public bool Enabled { get; init; }
public float Range { get; init; }
public float Volume { get; init; }
}