- fix: Night vision fix. (#33)
This commit is contained in:
@@ -28,12 +28,18 @@ public sealed class NightVisionSystem : SharedNightVisionSystem
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, NightVisionComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
UpdateNightVision(uid, component.IsActive);
|
||||
if (_player.LocalSession != args.Player)
|
||||
return;
|
||||
|
||||
UpdateNightVision(component.IsActive);
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(EntityUid uid, NightVisionComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
UpdateNightVision(uid, false);
|
||||
if (_player.LocalSession != args.Player)
|
||||
return;
|
||||
|
||||
UpdateNightVision(false);
|
||||
}
|
||||
|
||||
protected override void UpdateNightVision(EntityUid uid, bool active)
|
||||
@@ -41,6 +47,11 @@ public sealed class NightVisionSystem : SharedNightVisionSystem
|
||||
if (_player.LocalSession?.AttachedEntity != uid)
|
||||
return;
|
||||
|
||||
UpdateNightVision(active);
|
||||
}
|
||||
|
||||
private void UpdateNightVision(bool active)
|
||||
{
|
||||
if (active)
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
else
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared._White.Overlays;
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._Miracle.Systems;
|
||||
|
||||
@@ -8,6 +9,7 @@ public abstract class SharedNightVisionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -34,10 +36,12 @@ public abstract class SharedNightVisionSystem : EntitySystem
|
||||
|
||||
private void OnToggle(EntityUid uid, NightVisionComponent component, ToggleNightVisionEvent args)
|
||||
{
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
component.IsActive = !component.IsActive;
|
||||
_audio.PlayPredicted(component.ToggleSound, uid, uid);
|
||||
UpdateNightVision(uid, component.IsActive);
|
||||
Dirty(uid, component);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user