using Content.Shared.PDA;
using Content.Shared.PDA.Ringer;
using Content.Shared.Store.Components;
namespace Content.Client.PDA.Ringer;
///
/// Handles the client-side logic for .
///
public sealed class RingerSystem : SharedRingerSystem
{
///
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnRingerUpdate);
}
///
/// Updates the UI whenever we get a new component state from the server.
///
private void OnRingerUpdate(Entity ent, ref AfterAutoHandleStateEvent args)
{
UpdateRingerUi(ent);
}
///
protected override void UpdateRingerUi(Entity ent)
{
if (UI.TryGetOpenUi(ent.Owner, RingerUiKey.Key, out var bui))
{
bui.Update();
}
}
///
public override bool TryToggleUplink(EntityUid uid, Note[] ringtone, EntityUid? user = null)
{
if (!TryComp(uid, out var uplink))
return false;
if (!HasComp(uid))
return false;
// Special case for client-side prediction:
// Since we can't expose the uplink code to clients for security reasons,
// we assume if an antagonist is trying to set a ringtone, it's to unlock the uplink.
// The server will properly verify the code and correct if needed.
if (IsAntagonist(user))
return ToggleUplinkInternal((uid, uplink));
// Non-antagonists never get to toggle the uplink on the client
return false;
}
}