-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from VMSolidus/Upstream-Merge-7/15/2024
Done with tests locally
- Loading branch information
Showing
350 changed files
with
2,885 additions
and
773 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Content.Client.Audio; | ||
using Content.Shared.Announcements.Events; | ||
using Content.Shared.Announcements.Systems; | ||
using Content.Shared.CCVar; | ||
using Robust.Client.Audio; | ||
using Robust.Client.Player; | ||
using Robust.Client.ResourceManagement; | ||
using Robust.Shared.Audio.Sources; | ||
using Robust.Shared.Audio.Systems; | ||
using Robust.Shared.Configuration; | ||
|
||
namespace Content.Client.Announcements.Systems; | ||
|
||
public sealed class AnnouncerSystem : SharedAnnouncerSystem | ||
{ | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly IConfigurationManager _config = default!; | ||
[Dependency] private readonly IResourceCache _cache = default!; | ||
[Dependency] private readonly IAudioManager _audioManager = default!; | ||
|
||
private IAudioSource? AnnouncerSource { get; set; } | ||
private float AnnouncerVolume { get; set; } | ||
|
||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
AnnouncerVolume = _config.GetCVar(CCVars.AnnouncerVolume) * 100f / ContentAudioSystem.AnnouncerMultiplier; | ||
|
||
SubscribeNetworkEvent<AnnouncementSendEvent>(OnAnnouncementReceived); | ||
_config.OnValueChanged(CCVars.AnnouncerVolume, OnAnnouncerVolumeChanged); | ||
} | ||
|
||
public override void Shutdown() | ||
{ | ||
base.Shutdown(); | ||
|
||
_config.UnsubValueChanged(CCVars.AnnouncerVolume, OnAnnouncerVolumeChanged); | ||
} | ||
|
||
|
||
private void OnAnnouncerVolumeChanged(float value) | ||
{ | ||
AnnouncerVolume = value; | ||
|
||
if (AnnouncerSource != null) | ||
AnnouncerSource.Gain = AnnouncerVolume; | ||
} | ||
|
||
private void OnAnnouncementReceived(AnnouncementSendEvent ev) | ||
{ | ||
if (!ev.Recipients.Contains(_player.LocalSession!.UserId) | ||
|| !_cache.TryGetResource<AudioResource>(GetAnnouncementPath(ev.AnnouncementId, ev.AnnouncerId), | ||
out var resource)) | ||
return; | ||
|
||
var source = _audioManager.CreateAudioSource(resource); | ||
if (source != null) | ||
{ | ||
source.Gain = AnnouncerVolume * SharedAudioSystem.VolumeToGain(ev.AudioParams.Volume); | ||
source.Global = true; | ||
} | ||
|
||
AnnouncerSource?.Dispose(); | ||
AnnouncerSource = source; | ||
AnnouncerSource?.StartPlaying(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Content.IntegrationTests/Tests/Announcers/AnnouncerFallbackTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Content.Shared.Announcements.Prototypes; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.IntegrationTests.Tests.Announcers; | ||
|
||
[TestFixture] | ||
[TestOf(typeof(AnnouncerPrototype))] | ||
public sealed class AnnouncerPrototypeTests | ||
{ | ||
[Test] | ||
public async Task TestAnnouncerFallbacks() | ||
{ | ||
// Checks if every announcer has a fallback announcement | ||
|
||
await using var pair = await PoolManager.GetServerClient(); | ||
var server = pair.Server; | ||
|
||
var prototype = server.ResolveDependency<IPrototypeManager>(); | ||
|
||
await server.WaitAssertion(() => | ||
{ | ||
var success = true; | ||
var why = new List<string>(); | ||
|
||
foreach (var announcer in prototype.EnumeratePrototypes<AnnouncerPrototype>()) | ||
{ | ||
if (announcer.Announcements.All(a => a.ID.ToLower() != "fallback")) | ||
{ | ||
success = false; | ||
why.Add(announcer.ID); | ||
} | ||
} | ||
|
||
Assert.That(success, Is.True, $"The following announcers do not have a fallback announcement:\n {string.Join("\n ", why)}"); | ||
}); | ||
|
||
await pair.CleanReturnAsync(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
Content.IntegrationTests/Tests/Announcers/AnnouncerLocalizationTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Collections.Generic; | ||
using Content.Server.Announcements.Systems; | ||
using Content.Server.StationEvents; | ||
using Content.Shared.Announcements.Prototypes; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Localization; | ||
|
||
namespace Content.IntegrationTests.Tests.Announcers; | ||
|
||
[TestFixture] | ||
[TestOf(typeof(AnnouncerPrototype))] | ||
public sealed class AnnouncerLocalizationTest | ||
{ | ||
[Test] | ||
public async Task TestEventLocalization() | ||
{ | ||
// Checks if every station event wanting the announcerSystem to send messages has a localization string | ||
// If an event doesn't have startAnnouncement or endAnnouncement set to true | ||
// it will be expected for that system to handle the announcements if it wants them | ||
|
||
await using var pair = await PoolManager.GetServerClient(); | ||
var server = pair.Server; | ||
|
||
var locale = server.ResolveDependency<ILocalizationManager>(); | ||
var entSysMan = server.ResolveDependency<IEntitySystemManager>(); | ||
var announcer = entSysMan.GetEntitySystem<AnnouncerSystem>(); | ||
var events = entSysMan.GetEntitySystem<EventManagerSystem>(); | ||
|
||
await server.WaitAssertion(() => | ||
{ | ||
var succeeded = true; | ||
var why = new List<string>(); | ||
|
||
foreach (var ev in events.AllEvents()) | ||
{ | ||
if (ev.Value.StartAnnouncement) | ||
{ | ||
var announcementId = announcer.GetAnnouncementId(ev.Key.ID); | ||
var eventLocaleString = announcer.GetEventLocaleString(announcementId); | ||
|
||
if (locale.GetString(eventLocaleString) == eventLocaleString) | ||
{ | ||
succeeded = false; | ||
why.Add($"\"{announcementId}\": \"{eventLocaleString}\""); | ||
} | ||
} | ||
|
||
if (ev.Value.EndAnnouncement) | ||
{ | ||
var announcementId = announcer.GetAnnouncementId(ev.Key.ID, true); | ||
var eventLocaleString = announcer.GetEventLocaleString(announcementId); | ||
|
||
if (locale.GetString(eventLocaleString) == eventLocaleString) | ||
{ | ||
succeeded = false; | ||
why.Add($"\"{announcementId}\": \"{eventLocaleString}\""); | ||
} | ||
} | ||
} | ||
|
||
Assert.That(succeeded, Is.True, $"The following announcements do not have a localization string:\n {string.Join("\n ", why)}"); | ||
}); | ||
|
||
await pair.CleanReturnAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.