mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 14:07:53 +03:00
# Description IPCs were ported from a codebase that didn't necessarily follow all of our repo's coding standards. And while I had done my part to cleanup as much of the system as was practical within the bounds of a Maintainer Review, there were a lot of things that I felt were inappropriate to leave to review, and wished to go over with a fine lense. Thus, here is my Refactor of IPC code. Do not merge this without first testing that nothing was broken. Because I haven't tested it myself yet.
42 lines
1.6 KiB
C#
42 lines
1.6 KiB
C#
using Content.Shared.Containers.ItemSlots;
|
|
using Content.Shared.Lock;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Silicon.Components;
|
|
using Content.Shared.IdentityManagement;
|
|
|
|
namespace Content.Server.Silicon.BatteryLocking;
|
|
|
|
public sealed class BatterySlotRequiresLockSystem : EntitySystem
|
|
|
|
{
|
|
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<BatterySlotRequiresLockComponent, LockToggledEvent>(LockToggled);
|
|
SubscribeLocalEvent<BatterySlotRequiresLockComponent, LockToggleAttemptEvent>(LockToggleAttempted);
|
|
}
|
|
|
|
private void LockToggled(EntityUid uid, BatterySlotRequiresLockComponent component, LockToggledEvent args)
|
|
{
|
|
if (!TryComp<LockComponent>(uid, out var lockComp)
|
|
|| !TryComp<ItemSlotsComponent>(uid, out var itemslots)
|
|
|| !_itemSlotsSystem.TryGetSlot(uid, component.ItemSlot, out var slot, itemslots))
|
|
return;
|
|
|
|
_itemSlotsSystem.SetLock(uid, slot, lockComp.Locked, itemslots);
|
|
}
|
|
|
|
private void LockToggleAttempted(EntityUid uid, BatterySlotRequiresLockComponent component, LockToggleAttemptEvent args)
|
|
{
|
|
if (args.User == uid
|
|
|| !HasComp<SiliconComponent>(uid))
|
|
return;
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("batteryslotrequireslock-component-alert-owner", ("user", Identity.Entity(args.User, EntityManager))), uid, uid, PopupType.Large);
|
|
}
|
|
|
|
}
|