Files
tbd-station-14/Content.Shared/Radio/EntitySystems/SharedRadioDeviceSystem.cs
slarticodefast 321331e664 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>
2025-09-12 01:26:47 +02:00

54 lines
2.0 KiB
C#

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
}