1
0

AmbientSoundComponent.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Numerics;
  2. using Robust.Shared.Audio;
  3. using Robust.Shared.ComponentTrees;
  4. using Robust.Shared.GameStates;
  5. using Robust.Shared.Physics;
  6. using Robust.Shared.Serialization;
  7. namespace Content.Shared.Audio;
  8. [RegisterComponent]
  9. [NetworkedComponent]
  10. [Access(typeof(SharedAmbientSoundSystem))]
  11. public sealed partial class AmbientSoundComponent : Component, IComponentTreeEntry<AmbientSoundComponent>
  12. {
  13. [DataField("enabled", readOnly: true)]
  14. [ViewVariables(VVAccess.ReadWrite)] // only for map editing
  15. public bool Enabled { get; set; } = true;
  16. [DataField("sound", required: true), ViewVariables(VVAccess.ReadWrite)] // only for map editing
  17. public SoundSpecifier Sound = default!;
  18. /// <summary>
  19. /// How far away this ambient sound can potentially be heard.
  20. /// </summary>
  21. [ViewVariables(VVAccess.ReadWrite)] // only for map editing
  22. [DataField("range")]
  23. public float Range = 2f;
  24. public Vector2 RangeVector => new Vector2(Range, Range);
  25. /// <summary>
  26. /// Applies this volume to the sound being played.
  27. /// </summary>
  28. [ViewVariables(VVAccess.ReadWrite)] // only for map editing
  29. [DataField("volume")]
  30. public float Volume = -10f;
  31. public EntityUid? TreeUid { get; set; }
  32. public DynamicTree<ComponentTreeEntry<AmbientSoundComponent>>? Tree { get; set; }
  33. public bool AddToTree => Enabled;
  34. public bool TreeUpdateQueued { get; set; }
  35. }
  36. [Serializable, NetSerializable]
  37. public sealed class AmbientSoundComponentState : ComponentState
  38. {
  39. public bool Enabled { get; init; }
  40. public float Range { get; init; }
  41. public float Volume { get; init; }
  42. public SoundSpecifier Sound { get; init; } = default!;
  43. }