Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Glimmer-Reactive Prober Ambient Sounds (space-wizards#1345)
Browse files Browse the repository at this point in the history
* Add Glimmer Reactivity to Probers for Testing

* Add Troubleshooting for Prober Glimmer Reactivity

* Remove Unneeded Line

* Fix Prober Glimmer Reactivity

* Bugfix Glimmer Reactive Probers

* Add Fourth Dangerous Ambient Hum
  • Loading branch information
Finket authored Mar 9, 2023
1 parent 1f94501 commit 989315d
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Content.Client/Audio/AmbientSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,21 @@ private void ProcessNearbyAmbience(TransformComponent playerXform)
var metaQuery = GetEntityQuery<MetaDataComponent>();
var mapPos = playerXform.MapPosition;

// Remove out-of-range ambiences
// Remove out-of-range ambiences and sounds with updated paths
foreach (var (comp, sound) in _playingSounds)
{
var entity = comp.Owner;

// check if path has been updated
if (sound.Sound != comp.Sound.GetSound())
{
sound.Stream?.Stop();
_playingSounds.Remove(comp);
_playingCount[sound.Sound] -= 1;
if (_playingCount[sound.Sound] == 0)
_playingCount.Remove(sound.Sound);
}

if (comp.Enabled &&
query.TryGetComponent(entity, out var xform) &&
xform.MapID == playerXform.MapID &&
Expand Down
24 changes: 24 additions & 0 deletions Content.Server/Audio/GlimmerSoundComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Content.Server.Psionics.Glimmer;
using Content.Shared.Audio;
using Content.Shared.Psionics.Glimmer;
using Robust.Shared.Audio;
using Robust.Shared.ComponentTrees;
using Robust.Shared.GameStates;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;

namespace Content.Server.Audio
{
[RegisterComponent]
[Access(typeof(SharedAmbientSoundSystem), typeof(GlimmerReactiveSystem))]
public sealed class GlimmerSoundComponent : Component
{
[DataField("glimmerTier", required: true), ViewVariables(VVAccess.ReadWrite)] // only for map editing
public Dictionary<string, SoundSpecifier> Sound { get; set; } = new();

public bool GetSound(GlimmerTier glimmerTier, out SoundSpecifier? spec)
{
return Sound.TryGetValue(glimmerTier.ToString(), out spec);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Audio;
using Content.Server.Power.Components;
using Content.Server.Electrocution;
using Content.Server.Lightning;
Expand All @@ -6,13 +7,15 @@
using Content.Server.Coordinates.Helpers;
using Content.Server.Ghost;
using Content.Server.Revenant.EntitySystems;
using Content.Shared.Audio;
using Content.Shared.GameTicking;
using Content.Shared.Psionics.Glimmer;
using Content.Shared.Verbs;
using Content.Shared.StatusEffect;
using Content.Shared.Damage;
using Content.Shared.Destructible;
using Content.Shared.Construction.Components;
using Robust.Shared.Audio;
using Robust.Shared.Random;
using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;
Expand All @@ -25,6 +28,7 @@ public sealed class GlimmerReactiveSystem : EntitySystem
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly ElectrocutionSystem _electrocutionSystem = default!;
[Dependency] private readonly SharedAudioSystem _sharedAudioSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _sharedAmbientSoundSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly LightningSystem _lightning = default!;
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
Expand Down Expand Up @@ -70,6 +74,15 @@ private void UpdateEntityState(EntityUid uid, SharedGlimmerReactiveComponent com

_appearanceSystem.SetData(uid, GlimmerReactiveVisuals.GlimmerTier, isEnabled ? currentGlimmerTier : GlimmerTier.Minimal);

// update ambient sound
if (TryComp(uid, out GlimmerSoundComponent? glimmerSound)
&& TryComp(uid, out AmbientSoundComponent? ambientSoundComponent)
&& glimmerSound.GetSound(currentGlimmerTier, out SoundSpecifier? spec))
{
if (spec != null)
_sharedAmbientSoundSystem.SetSound(uid, spec, ambientSoundComponent);
}

if (component.ModulatesPointLight)
if (TryComp(uid, out SharedPointLightComponent? pointLight))
{
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Audio/AmbientSoundComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ public sealed class AmbientSoundComponentState : ComponentState
public bool Enabled { get; init; }
public float Range { get; init; }
public float Volume { get; init; }
public SoundSpecifier? Sound { get; init; }
}
}
14 changes: 14 additions & 0 deletions Content.Shared/Audio/SharedAmbientSoundSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;

namespace Content.Shared.Audio
Expand Down Expand Up @@ -45,12 +46,24 @@ public virtual void SetVolume(EntityUid uid, float value, AmbientSoundComponent?
Dirty(ambience);
}

public virtual void SetSound(EntityUid uid, SoundSpecifier path, AmbientSoundComponent? ambience = null)
{
if (!Resolve(uid, ref ambience, false) || ambience.Sound == path)
return;

ambience.Sound = path;
QueueUpdate(uid, ambience);
Dirty(ambience);
}

private void HandleCompState(EntityUid uid, AmbientSoundComponent component, ref ComponentHandleState args)
{
if (args.Current is not AmbientSoundComponentState state) return;
SetAmbience(uid, state.Enabled, component);
SetRange(uid, state.Range, component);
SetVolume(uid, state.Volume, component);
if (state.Sound != null)
SetSound(uid, state.Sound, component);
}

private void GetCompState(EntityUid uid, AmbientSoundComponent component, ref ComponentGetState args)
Expand All @@ -60,6 +73,7 @@ private void GetCompState(EntityUid uid, AmbientSoundComponent component, ref Co
Enabled = component.Enabled,
Range = component.Range,
Volume = component.Volume,
Sound = component.Sound,
};
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@
- type: GuideHelp
guides:
- Psionics
- type: AmbientSound
range: 6
volume: -6
sound: /Audio/Ambience/Objects/prober_hum_low.ogg
- type: AmbientOnPowered
- type: GlimmerSound
glimmerTier:
Minimal:
path: /Audio/Ambience/Objects/prober_hum_low.ogg
Low:
path: /Audio/Ambience/Objects/prober_hum_low.ogg
Moderate:
path: /Audio/Ambience/Objects/prober_hum_moderate.ogg
High:
path: /Audio/Ambience/Objects/prober_hum_high.ogg
Dangerous:
path: /Audio/Ambience/Objects/prober_hum_dangerous.ogg
Critical:
path: /Audio/Ambience/Objects/prober_hum_dangerous.ogg

- type: entity
parent: BaseMachinePowered
Expand Down

0 comments on commit 989315d

Please sign in to comment.