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

Commit

Permalink
Sound collections can now be specified per tile, to allow for dynamic…
Browse files Browse the repository at this point in the history
… switching of ambient sound. (#7)

Sounds are temporary. (i.e. They suck)
  • Loading branch information
Pspritechologist committed Apr 6, 2023
1 parent a31833e commit 5fc7357
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 3 deletions.
35 changes: 32 additions & 3 deletions Content.Client/Audio/BackgroundAudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Content.Client.GameTicking.Managers;
using Content.Client.Lobby;
using Content.Shared.CCVar;
using Content.Shared.Maps;
using JetBrains.Annotations;
using Robust.Client;
using Robust.Client.GameObjects;
Expand All @@ -11,6 +12,7 @@
using Robust.Client.State;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
Expand All @@ -31,6 +33,8 @@ public sealed class BackgroundAudioSystem : EntitySystem
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapManager _mappingManager = default!;
[Dependency] private readonly ITileDefinitionManager _tileDef = default!;

private readonly AudioParams _ambientParams = new(-10f, 1, "Master", 0, 0, 0, true, 0f);
private readonly AudioParams _lobbyParams = new(-5f, 1, "Master", 0, 0, 0, true, 0f);
Expand All @@ -51,14 +55,16 @@ public sealed class BackgroundAudioSystem : EntitySystem

private SoundCollectionPrototype _spaceAmbience = default!;
private SoundCollectionPrototype _stationAmbience = default!;
private SoundCollectionPrototype _defaultAmbience = default!;

public override void Initialize()
{
base.Initialize();

_stationAmbience = _prototypeManager.Index<SoundCollectionPrototype>("StationAmbienceBase");
_spaceAmbience = _prototypeManager.Index<SoundCollectionPrototype>("SpaceAmbienceBase");
_currentCollection = _stationAmbience;
_defaultAmbience = _prototypeManager.Index<SoundCollectionPrototype>("TileForestAmbience");
_currentCollection = _defaultAmbience;

// TODO: Ideally audio loading streamed better / we have more robust audio but this is quite annoying
var cache = IoCManager.Resolve<IResourceCache>();
Expand Down Expand Up @@ -118,10 +124,33 @@ public override void Shutdown()
EndLobbyMusic();
}

public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);

if (_playMan.LocalPlayer?.ControlledEntity is not { } entity)
return;

CheckAmbience(Transform(entity));
}

private void CheckAmbience(TransformComponent xform)
{
if (xform.GridUid != null)
ChangeAmbience(_stationAmbience);
if (_mappingManager.TryGetGrid(xform.GridUid.Value, out var grid))
{
var tile = grid.GetTileRef(xform.Coordinates);
var tileDef = (ContentTileDefinition)_tileDef[tile.Tile.TypeId];

if (tileDef.TileAmbientSound == "Stop")
ChangeAmbience(null);

if (tileDef.TileAmbientSound != null &&
_prototypeManager.TryIndex<SoundCollectionPrototype>(tileDef.TileAmbientSound, out var soundCollection))
ChangeAmbience(soundCollection);
else
return;
}
else
ChangeAmbience(_spaceAmbience);
}
Expand All @@ -137,7 +166,7 @@ private void EntParentChanged(ref EntParentChangedMessage message)
CheckAmbience(message.Transform);
}

private void ChangeAmbience(SoundCollectionPrototype newAmbience)
private void ChangeAmbience(SoundCollectionPrototype? newAmbience)
{
if (_currentCollection == newAmbience)
return;
Expand Down
2 changes: 2 additions & 0 deletions Content.Shared/Maps/ContentTileDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public sealed class ContentTileDefinition : IPrototype, IInheritingPrototype, IT
/// </summary>
[DataField("weather")] public bool Weather = false;

[DataField("tileAmbientSound")] public String? TileAmbientSound { get;}

public void AssignTileId(ushort id)
{
TileId = id;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions Resources/Prototypes/CM-SS14/SoundCollections/ambience.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- type: soundCollection
id: TileJungleAmbience
files:
- /Audio/CM-SS14/Ambience/Terrains/jungle_1.ogg

- type: soundCollection
id: TileDesertAmbience
files:
- /Audio/CM-SS14/Ambience/Terrains/desert_1.ogg

- type: soundCollection
id: TileForestAmbience
files:
- /Audio/CM-SS14/Ambience/Terrains/forest_1.ogg

- type: soundCollection
id: TileCaveAmbience
files:
- /Audio/CM-SS14/Ambience/Terrains/caveinterior_1.ogg
3 changes: 3 additions & 0 deletions Resources/Prototypes/Tiles/floors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@
collection: FootstepGrass
heatCapacity: 10000
weather: true
tileAmbientSound: TileJungleAmbience

- type: tile
id: FloorDirt
Expand Down Expand Up @@ -1191,6 +1192,7 @@
footstepSounds:
collection: FootstepAsteroid
heatCapacity: 10000
tileAmbientSound: TileCaveAmbience

- type: tile
id: FloorCaveDrought
Expand All @@ -1205,6 +1207,7 @@
footstepSounds:
collection: FootstepAsteroid
heatCapacity: 10000
tileAmbientSound: TileDesertAmbience

- type: tile
id: FloorFlesh
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Tiles/planet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
itemDrop: FloorTileItemGrass
heatCapacity: 10000
weather: true
tileAmbientSound: TileForestAmbience

# Lava
- type: tile
Expand Down

0 comments on commit 5fc7357

Please sign in to comment.