mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-01 00:27:59 +00:00
Fix tray scanner not updating it's range on change.
Add range value to the tray scanner state.to synchronize it between
client and server.
(cherry picked from commit 3d6d7820d6)
71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
using Content.Shared.Interaction;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
using System.Linq;
|
|
|
|
namespace Content.Shared.SubFloor;
|
|
|
|
public abstract class SharedTrayScannerSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
|
|
public const float SubfloorRevealAlpha = 0.8f;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<TrayScannerComponent, ComponentGetState>(OnTrayScannerGetState);
|
|
SubscribeLocalEvent<TrayScannerComponent, ComponentHandleState>(OnTrayScannerHandleState);
|
|
SubscribeLocalEvent<TrayScannerComponent, ActivateInWorldEvent>(OnTrayScannerActivate);
|
|
}
|
|
|
|
private void OnTrayScannerActivate(EntityUid uid, TrayScannerComponent scanner, ActivateInWorldEvent args)
|
|
{
|
|
SetScannerEnabled(uid, !scanner.Enabled, scanner);
|
|
}
|
|
|
|
private void SetScannerEnabled(EntityUid uid, bool enabled, TrayScannerComponent? scanner = null)
|
|
{
|
|
if (!Resolve(uid, ref scanner) || scanner.Enabled == enabled)
|
|
return;
|
|
|
|
scanner.Enabled = enabled;
|
|
Dirty(uid, scanner);
|
|
|
|
// We don't remove from _activeScanners on disabled, because the update function will handle that, as well as
|
|
// managing the revealed subfloor entities
|
|
|
|
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
|
{
|
|
_appearance.SetData(uid, TrayScannerVisual.Visual, scanner.Enabled ? TrayScannerVisual.On : TrayScannerVisual.Off, appearance);
|
|
}
|
|
}
|
|
|
|
private void OnTrayScannerGetState(EntityUid uid, TrayScannerComponent scanner, ref ComponentGetState args)
|
|
{
|
|
args.State = new TrayScannerState(scanner.Enabled, scanner.Range);
|
|
}
|
|
|
|
private void OnTrayScannerHandleState(EntityUid uid, TrayScannerComponent scanner, ref ComponentHandleState args)
|
|
{
|
|
if (args.Current is not TrayScannerState state)
|
|
return;
|
|
|
|
scanner.Range = state.Range;
|
|
SetScannerEnabled(uid, state.Enabled, scanner);
|
|
}
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public enum TrayScannerVisual : sbyte
|
|
{
|
|
Visual,
|
|
On,
|
|
Off
|
|
}
|