150 lines
6.3 KiB
C#
150 lines
6.3 KiB
C#
using Content.Client.Wires.Visualizers;
|
||
using Content.Shared.Doors;
|
||
using Content.Shared.Doors.Components;
|
||
using Content.Shared.Doors.Systems;
|
||
using Robust.Client.Animations;
|
||
using Robust.Client.GameObjects;
|
||
|
||
namespace Content.Client.Doors;
|
||
|
||
public sealed class AirlockSystem : SharedAirlockSystem
|
||
{
|
||
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
|
||
|
||
public override void Initialize()
|
||
{
|
||
base.Initialize();
|
||
SubscribeLocalEvent<AirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
|
||
SubscribeLocalEvent<AirlockComponent, ComponentStartup>(OnComponentStartup);
|
||
SubscribeLocalEvent<AirlockComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||
}
|
||
|
||
// А нужен ли ты блять
|
||
private void OnBeforeDoorClosed(EntityUid uid, AirlockComponent airlock, BeforeDoorClosedEvent args)
|
||
{
|
||
if (_appearanceSystem.TryGetData<bool>(uid, DoorVisuals.BoltLights, out var boltLights) && boltLights)
|
||
{
|
||
args.Cancel();
|
||
}
|
||
}
|
||
|
||
private void OnComponentStartup(EntityUid uid, AirlockComponent comp, ComponentStartup args)
|
||
{
|
||
// Has to be on component startup because we don't know what order components initialize in and running this before DoorComponent inits _will_ crash.
|
||
if (!TryComp<DoorComponent>(uid, out var door))
|
||
return;
|
||
|
||
if (comp.OpenUnlitVisible) // Otherwise there are flashes of the fallback sprite between clicking on the door and the door closing animation starting.
|
||
{
|
||
door.OpenSpriteStates.Add((DoorVisualLayers.BaseUnlit, comp.OpenSpriteState));
|
||
door.OpenSpriteStates.Add((DoorVisualLayers.BaseBolted, comp.OpenBoltedSpriteState));
|
||
door.OpenSpriteStates.Add((DoorVisualLayers.BaseEmergencyAccess, comp.OpenEmergencySpriteState));
|
||
door.ClosedSpriteStates.Add((DoorVisualLayers.BaseUnlit, comp.ClosedSpriteState));
|
||
door.ClosedSpriteStates.Add((DoorVisualLayers.BaseBolted, comp.ClosedBoltedSpriteState));
|
||
door.ClosedSpriteStates.Add((DoorVisualLayers.BaseEmergencyAccess, comp.ClosedEmergencySpriteState));
|
||
}
|
||
|
||
((Animation) door.OpeningAnimation).AnimationTracks.Add(new AnimationTrackSpriteFlick
|
||
{
|
||
LayerKey = DoorVisualLayers.BaseUnlit,
|
||
KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame(comp.OpeningSpriteState, 0f) },
|
||
}
|
||
);
|
||
|
||
((Animation) door.ClosingAnimation).AnimationTracks.Add(new AnimationTrackSpriteFlick
|
||
{
|
||
LayerKey = DoorVisualLayers.BaseUnlit,
|
||
KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame(comp.ClosingSpriteState, 0f) },
|
||
}
|
||
);
|
||
|
||
door.DenyingAnimation = new Animation
|
||
{
|
||
Length = TimeSpan.FromSeconds(comp.DenyAnimationTime),
|
||
AnimationTracks =
|
||
{
|
||
new AnimationTrackSpriteFlick
|
||
{
|
||
LayerKey = DoorVisualLayers.BaseUnlit,
|
||
KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame(comp.DenySpriteState, 0f) },
|
||
}
|
||
}
|
||
};
|
||
|
||
if (!comp.AnimatePanel)
|
||
return;
|
||
|
||
((Animation) door.OpeningAnimation).AnimationTracks.Add(new AnimationTrackSpriteFlick
|
||
{
|
||
LayerKey = WiresVisualLayers.MaintenancePanel,
|
||
KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame(comp.OpeningPanelSpriteState, 0f) },
|
||
});
|
||
|
||
((Animation) door.ClosingAnimation).AnimationTracks.Add(new AnimationTrackSpriteFlick
|
||
{
|
||
LayerKey = WiresVisualLayers.MaintenancePanel,
|
||
KeyFrames = { new AnimationTrackSpriteFlick.KeyFrame(comp.ClosingPanelSpriteState, 0f) },
|
||
});
|
||
}
|
||
|
||
private void OnAppearanceChange(EntityUid uid, AirlockComponent comp, ref AppearanceChangeEvent args)
|
||
{
|
||
if (args.Sprite == null)
|
||
return;
|
||
|
||
var boltedVisible = false;
|
||
var emergencyLightsVisible = false;
|
||
var unlitVisible = false;
|
||
|
||
if (!_appearanceSystem.TryGetData<DoorState>(uid, DoorVisuals.State, out var state, args.Component))
|
||
state = DoorState.Closed;
|
||
|
||
if (_appearanceSystem.TryGetData<bool>(uid, DoorVisuals.Powered, out var powered, args.Component) && powered)
|
||
{
|
||
boltedVisible =
|
||
_appearanceSystem.TryGetData<bool>(uid, DoorVisuals.BoltLights, out var lights, args.Component)
|
||
&& lights && state is DoorState.Closed or DoorState.Welded or DoorState.Open;
|
||
|
||
emergencyLightsVisible =
|
||
_appearanceSystem.TryGetData<bool>(uid, DoorVisuals.EmergencyLights, out var eaLights,
|
||
args.Component) && eaLights;
|
||
|
||
unlitVisible =
|
||
(state == DoorState.Closing
|
||
|| state == DoorState.Opening
|
||
|| state == DoorState.Denying
|
||
|| state == DoorState.Welded
|
||
|| state == DoorState.Open && comp.OpenUnlitVisible
|
||
|| state == DoorState.Closed && comp.OpenUnlitVisible
|
||
|| _appearanceSystem.TryGetData<bool>(uid, DoorVisuals.ClosedLights, out var closedLights,
|
||
args.Component) && closedLights)
|
||
&& !boltedVisible && !emergencyLightsVisible;
|
||
}
|
||
|
||
args.Sprite.LayerSetVisible(DoorVisualLayers.BaseUnlit, unlitVisible);
|
||
args.Sprite.LayerSetVisible(DoorVisualLayers.BaseBolted, boltedVisible);
|
||
if (comp.EmergencyAccessLayer)
|
||
{
|
||
args.Sprite.LayerSetVisible(
|
||
DoorVisualLayers.BaseEmergencyAccess,
|
||
emergencyLightsVisible
|
||
&& state != DoorState.Opening
|
||
&& state != DoorState.Closing
|
||
&& !boltedVisible
|
||
);
|
||
}
|
||
|
||
switch (state)
|
||
{
|
||
case DoorState.Open:
|
||
args.Sprite.LayerSetState(DoorVisualLayers.BaseUnlit, comp.ClosingSpriteState);
|
||
args.Sprite.LayerSetAnimationTime(DoorVisualLayers.BaseUnlit, 0);
|
||
break;
|
||
case DoorState.Closed:
|
||
args.Sprite.LayerSetState(DoorVisualLayers.BaseUnlit, comp.OpeningSpriteState);
|
||
args.Sprite.LayerSetAnimationTime(DoorVisualLayers.BaseUnlit, 0);
|
||
break;
|
||
}
|
||
}
|
||
}
|