Removes linter warnings from the PDA module (#17097)
This commit is contained in:
@@ -10,6 +10,7 @@ using Content.Server.Store.Components;
|
||||
using Content.Server.Store.Systems;
|
||||
using Content.Shared.PDA;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Containers;
|
||||
using Content.Shared.Light.Component;
|
||||
|
||||
@@ -32,20 +33,25 @@ namespace Content.Server.PDA
|
||||
SubscribeLocalEvent<PDAComponent, LightToggleEvent>(OnLightToggle);
|
||||
SubscribeLocalEvent<PDAComponent, GridModifiedEvent>(OnGridChanged);
|
||||
SubscribeLocalEvent<PDAComponent, AlertLevelChangedEvent>(OnAlertLevelChanged);
|
||||
|
||||
// UI Events:
|
||||
SubscribeLocalEvent<PDAComponent, PDARequestUpdateInterfaceMessage>(OnUiMessage);
|
||||
SubscribeLocalEvent<PDAComponent, PDAToggleFlashlightMessage>(OnUiMessage);
|
||||
SubscribeLocalEvent<PDAComponent, PDAShowRingtoneMessage>(OnUiMessage);
|
||||
SubscribeLocalEvent<PDAComponent, PDAShowMusicMessage>(OnUiMessage);
|
||||
SubscribeLocalEvent<PDAComponent, PDAShowUplinkMessage>(OnUiMessage);
|
||||
SubscribeLocalEvent<PDAComponent, PDALockUplinkMessage>(OnUiMessage);
|
||||
}
|
||||
|
||||
protected override void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args)
|
||||
{
|
||||
base.OnComponentInit(uid, pda, args);
|
||||
|
||||
if (!TryComp(uid, out ServerUserInterfaceComponent? uiComponent))
|
||||
if (!HasComp<ServerUserInterfaceComponent>(uid))
|
||||
return;
|
||||
|
||||
UpdateAlertLevel(uid, pda);
|
||||
UpdateStationName(uid, pda);
|
||||
|
||||
if (_ui.TryGetUi(uid, PDAUiKey.Key, out var ui, uiComponent))
|
||||
ui.OnReceiveMessage += (msg) => OnUIMessage(pda, msg);
|
||||
}
|
||||
|
||||
protected override void OnItemInserted(EntityUid uid, PDAComponent pda, EntInsertedIntoContainerMessage args)
|
||||
@@ -116,55 +122,66 @@ namespace Content.Server.PDA
|
||||
_cartridgeLoader?.UpdateUiState(uid, state);
|
||||
}
|
||||
|
||||
private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg)
|
||||
private void OnUiMessage(EntityUid uid, PDAComponent pda, PDARequestUpdateInterfaceMessage msg)
|
||||
{
|
||||
var uid = pda.Owner;
|
||||
// todo: move this to entity events
|
||||
switch (msg.Message)
|
||||
if (!PDAUiKey.Key.Equals(msg.UiKey))
|
||||
return;
|
||||
|
||||
UpdatePdaUi(uid, pda);
|
||||
}
|
||||
|
||||
private void OnUiMessage(EntityUid uid, PDAComponent pda, PDAToggleFlashlightMessage msg)
|
||||
{
|
||||
if (!PDAUiKey.Key.Equals(msg.UiKey))
|
||||
return;
|
||||
|
||||
if (TryComp<UnpoweredFlashlightComponent>(uid, out var flashlight))
|
||||
_unpoweredFlashlight.ToggleLight(uid, flashlight);
|
||||
}
|
||||
|
||||
private void OnUiMessage(EntityUid uid, PDAComponent pda, PDAShowRingtoneMessage msg)
|
||||
{
|
||||
if (!PDAUiKey.Key.Equals(msg.UiKey))
|
||||
return;
|
||||
|
||||
if (HasComp<RingerComponent>(uid))
|
||||
_ringer.ToggleRingerUI(uid, (IPlayerSession) msg.Session);
|
||||
}
|
||||
|
||||
private void OnUiMessage(EntityUid uid, PDAComponent pda, PDAShowMusicMessage msg)
|
||||
{
|
||||
if (!PDAUiKey.Key.Equals(msg.UiKey))
|
||||
return;
|
||||
|
||||
if (TryComp<InstrumentComponent>(uid, out var instrument))
|
||||
_instrument.ToggleInstrumentUi(uid, (IPlayerSession) msg.Session, instrument);
|
||||
}
|
||||
|
||||
private void OnUiMessage(EntityUid uid, PDAComponent pda, PDAShowUplinkMessage msg)
|
||||
{
|
||||
if (!PDAUiKey.Key.Equals(msg.UiKey))
|
||||
return;
|
||||
|
||||
// check if its locked again to prevent malicious clients opening locked uplinks
|
||||
if (TryComp<StoreComponent>(uid, out var store) && IsUnlocked(uid))
|
||||
_store.ToggleUi(msg.Session.AttachedEntity!.Value, uid, store);
|
||||
}
|
||||
|
||||
private void OnUiMessage(EntityUid uid, PDAComponent pda, PDALockUplinkMessage msg)
|
||||
{
|
||||
if (!PDAUiKey.Key.Equals(msg.UiKey))
|
||||
return;
|
||||
|
||||
if (TryComp<RingerUplinkComponent>(uid, out var uplink))
|
||||
{
|
||||
case PDARequestUpdateInterfaceMessage _:
|
||||
UpdatePdaUi(uid, pda);
|
||||
break;
|
||||
case PDAToggleFlashlightMessage _:
|
||||
{
|
||||
if (TryComp<UnpoweredFlashlightComponent>(uid, out var flashlight))
|
||||
_unpoweredFlashlight.ToggleLight(uid, flashlight);
|
||||
break;
|
||||
}
|
||||
case PDAShowRingtoneMessage _:
|
||||
{
|
||||
if (TryComp<RingerComponent>(uid, out var ringer))
|
||||
_ringer.ToggleRingerUI(ringer, msg.Session);
|
||||
break;
|
||||
}
|
||||
case PDAShowMusicMessage _:
|
||||
{
|
||||
if (TryComp<InstrumentComponent>(uid, out var instrument))
|
||||
_instrument.ToggleInstrumentUi(uid, msg.Session, instrument);
|
||||
break;
|
||||
}
|
||||
case PDAShowUplinkMessage _:
|
||||
{
|
||||
// check if its locked again to prevent malicious clients opening locked uplinks
|
||||
if (TryComp<StoreComponent>(uid, out var store) && IsUnlocked(uid))
|
||||
_store.ToggleUi(msg.Session.AttachedEntity!.Value, uid, store);
|
||||
break;
|
||||
}
|
||||
case PDALockUplinkMessage _:
|
||||
{
|
||||
if (TryComp<RingerUplinkComponent>(uid, out var uplink))
|
||||
{
|
||||
_ringer.LockUplink(uid, uplink);
|
||||
UpdatePdaUi(uid, pda);
|
||||
}
|
||||
break;
|
||||
}
|
||||
_ringer.LockUplink(uid, uplink);
|
||||
UpdatePdaUi(uid, pda);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsUnlocked(EntityUid uid)
|
||||
{
|
||||
return TryComp<RingerUplinkComponent>(uid, out var uplink) ? uplink.Unlocked : true;
|
||||
return !TryComp<RingerUplinkComponent>(uid, out var uplink) || uplink.Unlocked;
|
||||
}
|
||||
|
||||
private void UpdateStationName(EntityUid uid, PDAComponent pda)
|
||||
|
||||
@@ -30,5 +30,7 @@ namespace Content.Server.PDA.Ringer
|
||||
}
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class ActiveRingerComponent : Component {}
|
||||
public sealed class ActiveRingerComponent : Component
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Content.Server.Store.Components;
|
||||
using Content.Server.Store.Systems;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.PDA.Ringer;
|
||||
using Content.Shared.Store;
|
||||
@@ -18,8 +17,8 @@ namespace Content.Server.PDA.Ringer
|
||||
{
|
||||
[Dependency] private readonly PDASystem _pda = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly StoreSystem _store = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||
[Dependency] private readonly AudioSystem _audio = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -49,12 +48,12 @@ namespace Content.Server.PDA.Ringer
|
||||
private void RingerPlayRingtone(EntityUid uid, RingerComponent ringer, RingerPlayRingtoneMessage args)
|
||||
{
|
||||
EnsureComp<ActiveRingerComponent>(uid);
|
||||
UpdateRingerUserInterface(ringer);
|
||||
UpdateRingerUserInterface(uid, ringer);
|
||||
}
|
||||
|
||||
private void UpdateRingerUserInterfaceDriver(EntityUid uid, RingerComponent ringer, RingerRequestUpdateInterfaceMessage args)
|
||||
{
|
||||
UpdateRingerUserInterface(ringer);
|
||||
UpdateRingerUserInterface(uid, ringer);
|
||||
}
|
||||
|
||||
private void OnSetRingtone(EntityUid uid, RingerComponent ringer, RingerSetRingtoneMessage args)
|
||||
@@ -67,12 +66,12 @@ namespace Content.Server.PDA.Ringer
|
||||
if (ev.Handled)
|
||||
return;
|
||||
|
||||
UpdateRingerRingtone(ringer, args.Ringtone);
|
||||
UpdateRingerRingtone(uid, ringer, args.Ringtone);
|
||||
}
|
||||
|
||||
private void OnSetUplinkRingtone(EntityUid uid, RingerUplinkComponent uplink, ref BeforeRingtoneSetEvent args)
|
||||
{
|
||||
if (uplink.Code.SequenceEqual(args.Ringtone) && TryComp<StoreComponent>(uid, out var store))
|
||||
if (uplink.Code.SequenceEqual(args.Ringtone) && HasComp<StoreComponent>(uid))
|
||||
{
|
||||
uplink.Unlocked = !uplink.Unlocked;
|
||||
if (TryComp<PDAComponent>(uid, out var pda))
|
||||
@@ -104,7 +103,7 @@ namespace Content.Server.PDA.Ringer
|
||||
|
||||
public void RandomizeRingtone(EntityUid uid, RingerComponent ringer, MapInitEvent args)
|
||||
{
|
||||
UpdateRingerRingtone(ringer, GenerateRingtone());
|
||||
UpdateRingerRingtone(uid, ringer, GenerateRingtone());
|
||||
}
|
||||
|
||||
public void RandomizeUplinkCode(EntityUid uid, RingerUplinkComponent uplink, ComponentInit args)
|
||||
@@ -136,25 +135,25 @@ namespace Content.Server.PDA.Ringer
|
||||
return ringtone;
|
||||
}
|
||||
|
||||
private bool UpdateRingerRingtone(RingerComponent ringer, Note[] ringtone)
|
||||
private bool UpdateRingerRingtone(EntityUid uid, RingerComponent ringer, Note[] ringtone)
|
||||
{
|
||||
// Assume validation has already happened.
|
||||
ringer.Ringtone = ringtone;
|
||||
UpdateRingerUserInterface(ringer);
|
||||
UpdateRingerUserInterface(uid, ringer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void UpdateRingerUserInterface(RingerComponent ringer)
|
||||
private void UpdateRingerUserInterface(EntityUid uid, RingerComponent ringer)
|
||||
{
|
||||
var ui = ringer.Owner.GetUIOrNull(RingerUiKey.Key);
|
||||
ui?.SetState(new RingerUpdateState(HasComp<ActiveRingerComponent>(ringer.Owner), ringer.Ringtone));
|
||||
if (_ui.TryGetUi(uid, RingerUiKey.Key, out var bui))
|
||||
_ui.SetUiState(bui, new RingerUpdateState(HasComp<ActiveRingerComponent>(uid), ringer.Ringtone));
|
||||
}
|
||||
|
||||
public bool ToggleRingerUI(RingerComponent ringer, IPlayerSession session)
|
||||
public bool ToggleRingerUI(EntityUid uid, IPlayerSession session)
|
||||
{
|
||||
var ui = ringer.Owner.GetUIOrNull(RingerUiKey.Key);
|
||||
ui?.Toggle(session);
|
||||
if (_ui.TryGetUi(uid, RingerUiKey.Key, out var bui))
|
||||
_ui.ToggleUi(bui, session);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -162,25 +161,31 @@ namespace Content.Server.PDA.Ringer
|
||||
{
|
||||
var remove = new RemQueue<EntityUid>();
|
||||
|
||||
foreach(var (_, ringer) in EntityManager.EntityQuery<ActiveRingerComponent, RingerComponent>())
|
||||
var pdaQuery = EntityQueryEnumerator<RingerComponent, ActiveRingerComponent>();
|
||||
while (pdaQuery.MoveNext(out var uid, out var ringer, out var _))
|
||||
{
|
||||
ringer.TimeElapsed += frameTime;
|
||||
|
||||
if (ringer.TimeElapsed < NoteDelay) continue;
|
||||
if (ringer.TimeElapsed < NoteDelay)
|
||||
continue;
|
||||
|
||||
ringer.TimeElapsed -= NoteDelay;
|
||||
var ringerXform = Transform(ringer.Owner);
|
||||
var ringerXform = Transform(uid);
|
||||
|
||||
SoundSystem.Play(GetSound(ringer.Ringtone[ringer.NoteCount]),
|
||||
_audio.Play(
|
||||
GetSound(ringer.Ringtone[ringer.NoteCount]),
|
||||
Filter.Empty().AddInRange(ringerXform.MapPosition, ringer.Range),
|
||||
ringer.Owner, AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume));
|
||||
uid,
|
||||
true,
|
||||
AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume)
|
||||
);
|
||||
|
||||
ringer.NoteCount++;
|
||||
|
||||
if (ringer.NoteCount > 3)
|
||||
{
|
||||
remove.Add(ringer.Owner);
|
||||
UpdateRingerUserInterface(ringer);
|
||||
remove.Add(uid);
|
||||
UpdateRingerUserInterface(uid, ringer);
|
||||
ringer.TimeElapsed = 0;
|
||||
ringer.NoteCount = 0;
|
||||
break;
|
||||
@@ -193,12 +198,12 @@ namespace Content.Server.PDA.Ringer
|
||||
}
|
||||
}
|
||||
|
||||
private string GetSound(Note note)
|
||||
private static string GetSound(Note note)
|
||||
{
|
||||
return new ResPath("/Audio/Effects/RingtoneNotes/" + note.ToString().ToLower()) + ".ogg";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct BeforeRingtoneSetEvent(Note[] Ringtone, bool Handled = false);
|
||||
[ByRefEvent]
|
||||
public record struct BeforeRingtoneSetEvent(Note[] Ringtone, bool Handled = false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user