Skip to content

Commit

Permalink
Add random voices for borgs (#1505)
Browse files Browse the repository at this point in the history
* Add random voices for borgs

* Add summary

* Add borg voices

* oops

* Add comment
  • Loading branch information
Kirus59 authored Aug 5, 2024
1 parent dacf34f commit b8b7e2c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Content.Server/SS220/TTS/TTSSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Robust.Shared.Configuration;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server.SS220.TTS;

Expand All @@ -18,6 +19,7 @@ public sealed partial class TTSSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly TTSManager _ttsManager = default!;
[Dependency] private readonly SharedTransformSystem _xforms = default!;
[Dependency] private readonly IRobustRandom _random = default!;

private const int MaxMessageChars = 100 * 2; // same as SingleBubbleCharLimit * 2
private bool _isEnabled = false;
Expand All @@ -36,10 +38,18 @@ public override void Initialize()
SubscribeLocalEvent<RadioSpokeEvent>(OnRadioReceiveEvent);
SubscribeLocalEvent<AnnouncementSpokeEvent>(OnAnnouncementSpoke);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestartCleanup);
SubscribeLocalEvent<TTSComponent, ComponentInit>(OnInit);

SubscribeNetworkEvent<RequestGlobalTTSEvent>(OnRequestGlobalTTS);
}

private void OnInit(Entity<TTSComponent> ent, ref ComponentInit args)
{
// Set random voice from RandomVoicesList
// If RandomVoicesList is null - doesn`t set new voice
SetRandomVoice(ent);
}

private void OnRadioReceiveEvent(RadioSpokeEvent args)
{
if (!_isEnabled || args.Message.Length > MaxMessageChars)
Expand Down Expand Up @@ -74,6 +84,18 @@ private bool GetVoicePrototype(string voiceId, [NotNullWhen(true)] out TTSVoiceP
return true;
}

private void SetRandomVoice(EntityUid uid, TTSComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;

var protoId = comp.RandomVoicesList;
if (protoId is null)
return;

comp.VoicePrototypeId = _random.Pick(_prototypeManager.Index<RandomVoicesListPrototype>(protoId).VoicesList);
}

private async void OnAnnouncementSpoke(AnnouncementSpokeEvent args)
{
if (!_isEnabled ||
Expand Down
20 changes: 20 additions & 0 deletions Content.Shared/SS220/TTS/RandomVoicesListPrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Robust.Shared.Prototypes;

namespace Content.Shared.SS220.TTS;

/// <summary>
/// Prototype that contains a list of voices for randomize
/// </summary>
[Prototype("randomVoicesList")]
public sealed partial class RandomVoicesListPrototype : IPrototype
{
[IdDataField]
public string ID { get; private set; } = default!;

/// <summary>
/// List of TTSVoicePrototype
/// </summary>
[DataField("voices")]
public IReadOnlyList<string> VoicesList { get; private set; } = new List<string>();
}
8 changes: 7 additions & 1 deletion Content.Shared/SS220/TTS/TTSComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Shared.GameStates;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared.SS220.TTS;
Expand All @@ -16,4 +16,10 @@ public sealed partial class TTSComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField("voice", customTypeSerializer: typeof(PrototypeIdSerializer<TTSVoicePrototype>))]
public string? VoicePrototypeId { get; set; }

/// <summary>
/// Prototype that contains a list of voices for randomize
/// </summary>
[DataField("randomVoicesList", customTypeSerializer: typeof(PrototypeIdSerializer<RandomVoicesListPrototype>))]
public string? RandomVoicesList { get; private set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@
- Cyborgs
- Robotics
- type: StepTriggerImmune
- type: TTS
randomVoicesList: Borg

- type: entity
abstract: true
Expand Down
8 changes: 8 additions & 0 deletions Resources/Prototypes/SS220/Voice/random_voices_lists.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- type: randomVoicesList
id: Borg
voices:
- glados
- space_core
- adventure_core
- sentrybot
- fact_core

0 comments on commit b8b7e2c

Please sign in to comment.