move all the radio components and system to Shared (#40293)

* move all the radio components and system to Shared.

* duh split impl

* address reviews

* cleanup

---------

Co-authored-by: walksanatora <walkerffo22@gmail.com>
This commit is contained in:
slarticodefast
2025-09-12 01:26:47 +02:00
committed by GitHub
parent d8c55aef3c
commit 321331e664
24 changed files with 194 additions and 185 deletions

View File

@@ -0,0 +1,30 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared.Radio.Components;
/// <summary>
/// This component is required to receive radio message events.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class ActiveRadioComponent : Component
{
/// <summary>
/// The channels that this radio is listening on.
/// </summary>
[DataField]
public HashSet<ProtoId<RadioChannelPrototype>> Channels = new();
/// <summary>
/// A toggle for globally receiving all radio channels.
/// Overrides <see cref="Channels"/>
/// </summary>
[DataField]
public bool ReceiveAllChannels;
/// <summary>
/// If this radio can hear all messages on all maps
/// </summary>
[DataField]
public bool GlobalReceive = false;
}

View File

@@ -1,6 +1,6 @@
using Content.Shared.Chat;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared.Radio.Components;
@@ -8,15 +8,15 @@ namespace Content.Shared.Radio.Components;
/// This component is currently used for providing access to channels for "HeadsetComponent"s.
/// It should be used for intercoms and other radios in future.
/// </summary>
[RegisterComponent]
[RegisterComponent, NetworkedComponent]
public sealed partial class EncryptionKeyComponent : Component
{
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
public HashSet<string> Channels = new();
[DataField]
public HashSet<ProtoId<RadioChannelPrototype>> Channels = new();
/// <summary>
/// This is the channel that will be used when using the default/department prefix (<see cref="SharedChatSystem.DefaultChannelKey"/>).
/// </summary>
[DataField("defaultChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
public string? DefaultChannel;
[DataField]
public ProtoId<RadioChannelPrototype>? DefaultChannel;
}

View File

@@ -2,40 +2,36 @@ using Content.Shared.Chat;
using Content.Shared.Tools;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared.Radio.Components;
/// <summary>
/// This component is by entities that can contain encryption keys
/// </summary>
[RegisterComponent]
[RegisterComponent, NetworkedComponent]
public sealed partial class EncryptionKeyHolderComponent : Component
{
/// <summary>
/// Whether or not encryption keys can be removed from the headset.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("keysUnlocked")]
[DataField]
public bool KeysUnlocked = true;
/// <summary>
/// The tool required to extract the encryption keys from the headset.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("keysExtractionMethod", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
public string KeysExtractionMethod = "Screwing";
[DataField]
public ProtoId<ToolQualityPrototype> KeysExtractionMethod = "Screwing";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("keySlots")]
[DataField]
public int KeySlots = 2;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("keyExtractionSound")]
[DataField]
public SoundSpecifier KeyExtractionSound = new SoundPathSpecifier("/Audio/Items/pistol_magout.ogg");
[ViewVariables(VVAccess.ReadWrite)]
[DataField("keyInsertionSound")]
[DataField]
public SoundSpecifier KeyInsertionSound = new SoundPathSpecifier("/Audio/Items/pistol_magin.ogg");
[ViewVariables]
@@ -46,7 +42,7 @@ public sealed partial class EncryptionKeyHolderComponent : Component
/// Combined set of radio channels provided by all contained keys.
/// </summary>
[ViewVariables]
public HashSet<string> Channels = new();
public HashSet<ProtoId<RadioChannelPrototype>> Channels = new();
/// <summary>
/// This is the channel that will be used when using the default/department prefix (<see cref="SharedChatSystem.DefaultChannelKey"/>).

View File

@@ -0,0 +1,11 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Radio.Components;
/// <summary>
/// This component allows an entity to directly translate radio messages into chat messages. Note that this does not
/// automatically add an <see cref="ActiveRadioComponent"/>, which is required to receive radio messages on specific
/// channels.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class IntrinsicRadioReceiverComponent : Component;

View File

@@ -0,0 +1,16 @@
using Content.Shared.Chat;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared.Radio.Components;
/// <summary>
/// This component allows an entity to directly translate spoken text into radio messages (effectively an intrinsic
/// radio headset).
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class IntrinsicRadioTransmitterComponent : Component
{
[DataField]
public HashSet<ProtoId<RadioChannelPrototype>> Channels = new() { SharedChatSystem.CommonChannel };
}

View File

@@ -0,0 +1,40 @@
using Content.Shared.Radio.EntitySystems;
using Content.Shared.Chat;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared.Radio.Components;
/// <summary>
/// Listens for local chat messages and relays them to some radio frequency
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedRadioDeviceSystem))]
public sealed partial class RadioMicrophoneComponent : Component
{
[DataField]
public ProtoId<RadioChannelPrototype> BroadcastChannel = SharedChatSystem.CommonChannel;
[DataField]
public int ListenRange = 4;
[DataField]
public bool Enabled = false;
[DataField]
public bool PowerRequired = false;
/// <summary>
/// Whether or not interacting with this entity
/// toggles it on or off.
/// </summary>
[DataField]
public bool ToggleOnInteract = true;
/// <summary>
/// Whether or not the speaker must have an
/// unobstructed path to the radio to speak
/// </summary>
[DataField]
public bool UnobstructedRequired = false;
}

View File

@@ -0,0 +1,27 @@
using Content.Shared.Radio.EntitySystems;
using Content.Shared.Chat;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared.Radio.Components;
/// <summary>
/// Listens for radio messages and relays them to local chat.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedRadioDeviceSystem))]
public sealed partial class RadioSpeakerComponent : Component
{
/// <summary>
/// Whether or not interacting with this entity
/// toggles it on or off.
/// </summary>
[DataField]
public bool ToggleOnInteract = true;
[DataField]
public HashSet<ProtoId<RadioChannelPrototype>> Channels = new() { SharedChatSystem.CommonChannel };
[DataField, AutoNetworkedField]
public bool Enabled;
}

View File

@@ -0,0 +1,13 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Radio.Components;
/// <summary>
/// This component is used to tag players that are currently wearing an ACTIVE headset.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class WearingHeadsetComponent : Component
{
[DataField]
public EntityUid Headset;
}

View File

@@ -207,7 +207,7 @@ public sealed partial class EncryptionKeySystem : EntitySystem
/// <param name="channels">HashSet of channels in headset, encryptionkey or etc.</param>
/// <param name="protoManager">IPrototypeManager for getting prototypes of channels with their variables.</param>
/// <param name="channelFTLPattern">String that provide id of pattern in .ftl files to format channel with variables of it.</param>
public void AddChannelsExamine(HashSet<string> channels, string? defaultChannel, ExaminedEvent examineEvent, IPrototypeManager protoManager, string channelFTLPattern)
public void AddChannelsExamine(HashSet<ProtoId<RadioChannelPrototype>> channels, string? defaultChannel, ExaminedEvent examineEvent, IPrototypeManager protoManager, string channelFTLPattern)
{
RadioChannelPrototype? proto;
foreach (var id in channels)

View File

@@ -0,0 +1,53 @@
using Content.Shared.Popups;
using Content.Shared.Radio.Components;
namespace Content.Shared.Radio.EntitySystems;
public abstract class SharedRadioDeviceSystem : EntitySystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
#region Toggling
public void ToggleRadioMicrophone(EntityUid uid, EntityUid user, bool quiet = false, RadioMicrophoneComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
SetMicrophoneEnabled(uid, user, !component.Enabled, quiet, component);
}
public virtual void SetMicrophoneEnabled(EntityUid uid, EntityUid? user, bool enabled, bool quiet = false, RadioMicrophoneComponent? component = null) { }
public void ToggleRadioSpeaker(EntityUid uid, EntityUid user, bool quiet = false, RadioSpeakerComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
SetSpeakerEnabled(uid, user, !component.Enabled, quiet, component);
}
public void SetSpeakerEnabled(EntityUid uid, EntityUid? user, bool enabled, bool quiet = false, RadioSpeakerComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
component.Enabled = enabled;
Dirty(uid, component);
if (!quiet && user != null)
{
var state = Loc.GetString(component.Enabled ? "handheld-radio-component-on-state" : "handheld-radio-component-off-state");
var message = Loc.GetString("handheld-radio-component-on-use", ("radioState", state));
_popup.PopupEntity(message, user.Value, user.Value);
}
_appearance.SetData(uid, RadioDeviceVisuals.Speaker, component.Enabled);
if (component.Enabled)
EnsureComp<ActiveRadioComponent>(uid).Channels.UnionWith(component.Channels);
else
RemCompDeferred<ActiveRadioComponent>(uid);
}
#endregion
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Actions;
using Content.Shared.Radio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
@@ -51,9 +52,9 @@ public enum SiliconLawsUiKey : byte
public sealed class SiliconLawBuiState : BoundUserInterfaceState
{
public List<SiliconLaw> Laws;
public HashSet<string>? RadioChannels;
public HashSet<ProtoId<RadioChannelPrototype>>? RadioChannels;
public SiliconLawBuiState(List<SiliconLaw> laws, HashSet<string>? radioChannels)
public SiliconLawBuiState(List<SiliconLaw> laws, HashSet<ProtoId<RadioChannelPrototype>>? radioChannels)
{
Laws = laws;
RadioChannels = radioChannels;