Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinary1 committed Oct 21, 2024
1 parent 6624c61 commit 609e9b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Content.Shared.Actions;
using Content.Shared.Inventory.Events;
using Content.Shared.Toggleable;
using Content.Shared.PowerCell;
using Content.Shared.PowerCell.Components;
using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
Expand All @@ -20,13 +22,17 @@ public sealed class NightVisionDeviceSystem : EntitySystem
[Dependency] private readonly SharedPointLightSystem _light = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedPowerCellSystem _cell = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<NightVisionDeviceComponent, InventoryRelayedEvent<CanVisionAttemptEvent>>(OnNVDTrySee);
SubscribeLocalEvent<NightVisionDeviceComponent, NightVisionDeviceUpdateVisualsEvent>(OnNightVisionDeviceUpdateVisuals);

SubscribeLocalEvent<NightVisionDeviceComponent, PowerCellChangedEvent>(OnPowerCellChanged);
SubscribeLocalEvent<NightVisionDeviceComponent, PowerCellSlotEmptyEvent>(OnPowerCellSlotEmpty);

SubscribeLocalEvent<NightVisionDeviceComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<NightVisionDeviceComponent, ToggleActionEvent>(OnToggleAction);
Expand Down Expand Up @@ -56,7 +62,20 @@ private void OnShutdown(EntityUid uid, NightVisionDeviceComponent component, Com
{
_actionsSystem.RemoveAction(uid, component.ToggleActionEntity);
}

private void OnPowerCellSlotEmpty(Entity<NightVisionDeviceComponent> ent, ref PowerCellSlotEmptyEvent args)
{
if (ent.Comp.isPowered)
Toggle(ent);
}

private void OnPowerCellChanged(Entity<NightVisionDeviceComponent> ent, ref PowerCellChangedEvent args)
{
if (args.Ejected || !_powerCell.HasDrawCharge(ent))
if (ent.Comp.isPowered)
Toggle(ent);
}

private void OnToggleAction(Entity<NightVisionDeviceComponent> ent, ref ToggleActionEvent args)
{
if (args.Handled)
Expand All @@ -68,6 +87,13 @@ private void OnToggleAction(Entity<NightVisionDeviceComponent> ent, ref ToggleAc
return;
}

Toggle(ent);

args.Handled = true;
}

public void Toggle(Entity<NightVisionDeviceComponent> ent)
{
var updVisEv = new NightVisionDeviceUpdateVisualsEvent();
RaiseLocalEvent(ent, ref updVisEv);

Expand All @@ -81,15 +107,22 @@ private void OnToggleAction(Entity<NightVisionDeviceComponent> ent, ref ToggleAc

if (!_light.TryGetLight(ent.Owner, out var light))
return;

var draw = Comp<PowerCellDrawComponent>(ent.Owner);
_cell.QueueUpdate((ent.Owner, draw));
_cell.SetDrawEnabled((ent.Owner, draw), ent.Comp.Activated);

_appearance.SetData(ent, ToggleableLightVisuals.Enabled, ent.Comp.Activated);
_light.SetEnabled(ent.Owner, ent.Comp.Activated, comp: light);

var changeEv = new NightVisionDeviceToggledEvent(args.Performer);
RaiseLocalEvent(ent.Owner, ref changeEv);
Dirty(ent);
if (TryComp<TransformComponent>(ent.Owner, out var transform))
{
var equipped = transform.ParentUid;

args.Handled = true;
var changeEv = new NightVisionDeviceToggledEvent(equipped);
RaiseLocalEvent(ent.Owner, ref changeEv);
}
Dirty(ent);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
- type: PowerCellDraw
drawRate: 0
useRate: 20
- type: ToggleCellDraw

- type: entity
parent: [ClothingEyesNVD,ShowSecurityIcons]
Expand Down

0 comments on commit 609e9b8

Please sign in to comment.