2023-05-06 17:54:36 +12:00
|
|
|
using Content.Shared.Doors.Components;
|
2024-05-22 11:16:20 +00:00
|
|
|
using Content.Shared.Doors.Systems;
|
2025-04-21 15:39:28 -07:00
|
|
|
using Robust.Client.Animations;
|
2023-05-06 17:54:36 +12:00
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.Doors;
|
|
|
|
|
|
2024-05-22 11:16:20 +00:00
|
|
|
public sealed class FirelockSystem : SharedFirelockSystem
|
2023-05-06 17:54:36 +12:00
|
|
|
{
|
2024-02-13 22:48:39 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
2025-05-18 21:09:47 -04:00
|
|
|
[Dependency] private readonly SpriteSystem _sprite = default!;
|
2023-05-06 17:54:36 +12:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<FirelockComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-21 15:39:28 -07:00
|
|
|
protected override void OnComponentStartup(Entity<FirelockComponent> ent, ref ComponentStartup args)
|
|
|
|
|
{
|
|
|
|
|
base.OnComponentStartup(ent, ref args);
|
2025-05-18 21:09:47 -04:00
|
|
|
if (!TryComp<DoorComponent>(ent.Owner, out var door))
|
2025-04-21 15:39:28 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
door.ClosedSpriteStates.Add((DoorVisualLayers.BaseUnlit, ent.Comp.WarningLightSpriteState));
|
|
|
|
|
door.OpenSpriteStates.Add((DoorVisualLayers.BaseUnlit, ent.Comp.WarningLightSpriteState));
|
|
|
|
|
|
|
|
|
|
((Animation)door.OpeningAnimation).AnimationTracks.Add(new AnimationTrackSpriteFlick()
|
|
|
|
|
{
|
|
|
|
|
LayerKey = DoorVisualLayers.BaseUnlit,
|
|
|
|
|
KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame(ent.Comp.OpeningLightSpriteState, 0f) },
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
((Animation)door.ClosingAnimation).AnimationTracks.Add(new AnimationTrackSpriteFlick()
|
|
|
|
|
{
|
|
|
|
|
LayerKey = DoorVisualLayers.BaseUnlit,
|
|
|
|
|
KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame(ent.Comp.ClosingLightSpriteState, 0f) },
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-06 17:54:36 +12:00
|
|
|
private void OnAppearanceChange(EntityUid uid, FirelockComponent comp, ref AppearanceChangeEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Sprite == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-08-11 21:29:33 +12:00
|
|
|
var boltedVisible = false;
|
|
|
|
|
var unlitVisible = false;
|
|
|
|
|
|
|
|
|
|
if (!_appearanceSystem.TryGetData<DoorState>(uid, DoorVisuals.State, out var state, args.Component))
|
|
|
|
|
state = DoorState.Closed;
|
|
|
|
|
|
2024-06-15 08:17:16 -07:00
|
|
|
boltedVisible = _appearanceSystem.TryGetData<bool>(uid, DoorVisuals.BoltLights, out var lights, args.Component) && lights;
|
|
|
|
|
unlitVisible =
|
|
|
|
|
state == DoorState.Closing
|
|
|
|
|
|| state == DoorState.Opening
|
|
|
|
|
|| state == DoorState.Denying
|
|
|
|
|
|| (_appearanceSystem.TryGetData<bool>(uid, DoorVisuals.ClosedLights, out var closedLights, args.Component) && closedLights);
|
2023-08-11 21:29:33 +12:00
|
|
|
|
2025-05-18 21:09:47 -04:00
|
|
|
_sprite.LayerSetVisible((uid, args.Sprite), DoorVisualLayers.BaseUnlit, unlitVisible && !boltedVisible);
|
|
|
|
|
_sprite.LayerSetVisible((uid, args.Sprite), DoorVisualLayers.BaseBolted, boltedVisible);
|
2023-05-06 17:54:36 +12:00
|
|
|
}
|
|
|
|
|
}
|