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

@@ -1,11 +1,12 @@
using Content.Client.Radio.Ui;
using Content.Shared.Radio;
using Content.Shared.Radio.Components;
using Content.Shared.Radio.EntitySystems;
using Robust.Client.GameObjects;
namespace Content.Client.Radio.EntitySystems;
public sealed class RadioDeviceSystem : EntitySystem
public sealed class RadioDeviceSystem : SharedRadioDeviceSystem
{
[Dependency] private readonly UserInterfaceSystem _ui = default!;

View File

@@ -26,7 +26,7 @@ public sealed partial class LawDisplay : Control
private readonly Dictionary<Button, TimeSpan> _nextAllowedPress = new();
public LawDisplay(EntityUid uid, SiliconLaw law, HashSet<string>? radioChannels)
public LawDisplay(EntityUid uid, SiliconLaw law, HashSet<ProtoId<RadioChannelPrototype>>? radioChannels)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

View File

@@ -1,6 +1,6 @@
using Content.Server.Radio.Components;
using Content.Shared.Implants;
using Content.Shared.Implants;
using Content.Shared.Implants.Components;
using Content.Shared.Radio.Components;
namespace Content.Server.Implants;

View File

@@ -1,17 +0,0 @@
using Content.Server.Chat.Systems;
using Content.Shared.Chat;
using Content.Shared.Radio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
namespace Content.Server.Radio.Components;
/// <summary>
/// This component allows an entity to directly translate spoken text into radio messages (effectively an intrinsic
/// radio headset).
/// </summary>
[RegisterComponent]
public sealed partial class IntrinsicRadioTransmitterComponent : Component
{
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
public HashSet<string> Channels = new() { SharedChatSystem.CommonChannel };
}

View File

@@ -1,43 +0,0 @@
using Content.Server.Radio.EntitySystems;
using Content.Shared.Chat;
using Content.Shared.Radio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Server.Radio.Components;
/// <summary>
/// Listens for local chat messages and relays them to some radio frequency
/// </summary>
[RegisterComponent]
[Access(typeof(RadioDeviceSystem))]
public sealed partial class RadioMicrophoneComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("broadcastChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
public string BroadcastChannel = SharedChatSystem.CommonChannel;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("listenRange")]
public int ListenRange = 4;
[DataField("enabled")]
public bool Enabled = false;
[DataField("powerRequired")]
public bool PowerRequired = false;
/// <summary>
/// Whether or not interacting with this entity
/// toggles it on or off.
/// </summary>
[DataField("toggleOnInteract")]
public bool ToggleOnInteract = true;
/// <summary>
/// Whether or not the speaker must have an
/// unobstructed path to the radio to speak
/// </summary>
[DataField("unobstructedRequired")]
public bool UnobstructedRequired = false;
}

View File

@@ -1,27 +0,0 @@
using Content.Server.Radio.EntitySystems;
using Content.Shared.Chat;
using Content.Shared.Radio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
namespace Content.Server.Radio.Components;
/// <summary>
/// Listens for radio messages and relays them to local chat.
/// </summary>
[RegisterComponent]
[Access(typeof(RadioDeviceSystem))]
public sealed partial class RadioSpeakerComponent : Component
{
/// <summary>
/// Whether or not interacting with this entity
/// toggles it on or off.
/// </summary>
[DataField("toggleOnInteract")]
public bool ToggleOnInteract = true;
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
public HashSet<string> Channels = new () { SharedChatSystem.CommonChannel };
[DataField("enabled")]
public bool Enabled;
}

View File

@@ -1,6 +1,5 @@
using Content.Server.Chat.Systems;
using Content.Server.Emp;
using Content.Server.Radio.Components;
using Content.Shared.Inventory.Events;
using Content.Shared.Radio;
using Content.Shared.Radio.Components;

View File

@@ -3,7 +3,7 @@ using Content.Server.Chat.Systems;
using Content.Server.Interaction;
using Content.Server.Popups;
using Content.Server.Power.EntitySystems;
using Content.Server.Radio.Components;
using Content.Shared.Radio.Components;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Power;
@@ -11,15 +11,15 @@ using Content.Shared.Radio;
using Content.Shared.Speech;
using Content.Shared.Speech.Components;
using Content.Shared.Chat;
using Content.Shared.Radio.Components;
using Robust.Shared.Prototypes;
using Content.Shared.Radio.EntitySystems;
namespace Content.Server.Radio.EntitySystems;
/// <summary>
/// This system handles radio speakers and microphones (which together form a hand-held radio).
/// </summary>
public sealed class RadioDeviceSystem : EntitySystem
public sealed class RadioDeviceSystem : SharedRadioDeviceSystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly PopupSystem _popup = default!;
@@ -100,15 +100,6 @@ public sealed class RadioDeviceSystem : EntitySystem
ToggleRadioSpeaker(uid, args.User, args.Handled, component);
args.Handled = true;
}
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);
}
private void OnPowerChanged(EntityUid uid, RadioMicrophoneComponent component, ref PowerChangedEvent args)
{
if (args.Powered)
@@ -116,7 +107,8 @@ public sealed class RadioDeviceSystem : EntitySystem
SetMicrophoneEnabled(uid, null, false, true, component);
}
public void SetMicrophoneEnabled(EntityUid uid, EntityUid? user, bool enabled, bool quiet = false, RadioMicrophoneComponent? component = null)
public override void SetMicrophoneEnabled(EntityUid uid, EntityUid? user, bool enabled, bool quiet = false, RadioMicrophoneComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
@@ -140,34 +132,6 @@ public sealed class RadioDeviceSystem : EntitySystem
RemCompDeferred<ActiveListenerComponent>(uid);
}
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;
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
private void OnExamine(EntityUid uid, RadioMicrophoneComponent component, ExaminedEvent args)
@@ -277,9 +241,9 @@ public sealed class RadioDeviceSystem : EntitySystem
}
if (TryComp<RadioMicrophoneComponent>(ent, out var mic))
mic.BroadcastChannel = channel;
mic.BroadcastChannel = channel.Value;
if (TryComp<RadioSpeakerComponent>(ent, out var speaker))
speaker.Channels = new() { channel };
speaker.Channels = new() { channel.Value };
Dirty(ent);
}
}

View File

@@ -1,7 +1,6 @@
using Content.Server.Administration.Logs;
using Content.Server.Chat.Systems;
using Content.Server.Power.Components;
using Content.Server.Radio.Components;
using Content.Shared.Chat;
using Content.Shared.Database;
using Content.Shared.Radio;

View File

@@ -1,6 +1,6 @@
using Content.Server.Inventory;
using Content.Server.Radio.Components;
using Content.Shared.Inventory;
using Content.Shared.Radio.Components;
using Content.Shared.Silicons.Borgs;
using Content.Shared.Silicons.Borgs.Components;
using Robust.Shared.Prototypes;

View File

@@ -1,7 +1,6 @@
using System.Linq;
using Content.Server.Administration;
using Content.Server.Chat.Managers;
using Content.Server.Radio.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Content.Shared.Chat;
@@ -9,6 +8,7 @@ using Content.Shared.Emag.Systems;
using Content.Shared.GameTicking;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Radio.Components;
using Content.Shared.Roles;
using Content.Shared.Roles.Components;
using Content.Shared.Silicons.Laws;

View File

@@ -1,11 +1,11 @@
using Content.Server.Chat.Systems;
using Content.Shared.Radio;
using Content.Server.Radio.Components;
using Content.Shared.Radio.Components;
using Content.Server.Radio.EntitySystems;
using Content.Server.Speech.Components;
using Content.Server.Wires;
using Content.Shared.Wires;
using Content.Shared.Radio;
using Content.Shared.Speech;
using Content.Shared.Wires;
using Robust.Shared.Prototypes;
namespace Content.Server.Speech;

View File

@@ -1,9 +1,9 @@
using Content.Server.Chat.Systems;
using Content.Server.Radio.Components;
using Content.Server.Vocalization.Components;
using Content.Shared.Chat;
using Content.Shared.Inventory;
using Content.Shared.Radio;
using Content.Shared.Radio.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
@@ -42,9 +42,9 @@ public sealed partial class RadioVocalizationSystem : EntitySystem
/// Selects a random radio channel from all ActiveRadio entities in a given entity's inventory
/// If no channels are found, this returns false and sets channel to an empty string
/// </summary>
private bool TryPickRandomRadioChannel(EntityUid entity, out string channel)
private bool TryPickRandomRadioChannel(EntityUid entity, out ProtoId<RadioChannelPrototype> channel)
{
HashSet<string> potentialChannels = [];
HashSet<ProtoId<RadioChannelPrototype>> potentialChannels = [];
// we don't have to check if this entity has an inventory. GetHandOrInventoryEntities will not yield anything
// if an entity has no inventory or inventory slots

View File

@@ -1,30 +1,30 @@
using Content.Shared.Radio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Server.Radio.Components;
namespace Content.Shared.Radio.Components;
/// <summary>
/// This component is required to receive radio message events.
/// </summary>
[RegisterComponent]
[RegisterComponent, NetworkedComponent]
public sealed partial class ActiveRadioComponent : Component
{
/// <summary>
/// The channels that this radio is listening on.
/// </summary>
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
public HashSet<string> Channels = new();
[DataField]
public HashSet<ProtoId<RadioChannelPrototype>> Channels = new();
/// <summary>
/// A toggle for globally receiving all radio channels.
/// Overrides <see cref="Channels"/>
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool ReceiveAllChannels;
/// <summary>
/// If this radio can hear all messages on all maps
/// </summary>
[DataField("globalReceive")]
[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

@@ -1,11 +1,11 @@
namespace Content.Server.Radio.Components;
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]
public sealed partial class IntrinsicRadioReceiverComponent : Component
{
}
[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

@@ -1,13 +1,13 @@
using Content.Server.Radio.EntitySystems;
using Robust.Shared.GameStates;
namespace Content.Server.Radio.Components;
namespace Content.Shared.Radio.Components;
/// <summary>
/// This component is used to tag players that are currently wearing an ACTIVE headset.
/// </summary>
[RegisterComponent]
[RegisterComponent, NetworkedComponent]
public sealed partial class WearingHeadsetComponent : Component
{
[DataField("headset")]
[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;