mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* First impl. of appearance TryGetData cleanup * Handful of fixes * DamageVisuals: fix HandleDamage call, inheritdoc * bunch of unused AppearanceSystem instances * Handful more unused appearance systems, inheritdoc * JetpackSystem: Ent<T> * cleanup roundup, more Ent<T> * a few lingering AppearanceSystem.TryGetData calls * more lingering AppearanceData access * Remove unnecessary inheritdoc * once again, with feeling
70 lines
3 KiB
C#
70 lines
3 KiB
C#
using Content.Client.Atmos.Components;
|
|
using Content.Shared.Atmos.Components;
|
|
using Content.Shared.Atmos.EntitySystems;
|
|
using Content.Shared.Rounding;
|
|
using Robust.Client.GameObjects;
|
|
|
|
namespace Content.Client.Atmos.EntitySystems;
|
|
|
|
/// <summary>
|
|
/// This system handles sprite changes for a <see cref="IGasMaxPressureHolder"/>
|
|
/// with a <see cref="MaxPressureVisualsComponent"/> when its <see cref="IGasMaxPressureHolder.Integrity"/> changes.
|
|
/// </summary>
|
|
public sealed partial class MaxPressureVisualsSystem : EntitySystem
|
|
{
|
|
[Dependency] private SpriteSystem _sprite = default!;
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnMaxPressureInit(Entity<MaxPressureVisualsComponent> entity, ref ComponentInit args)
|
|
{
|
|
if (!TryComp<SpriteComponent>(entity, out var sprite))
|
|
return;
|
|
|
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(entity.Comp.IntegritySteps);
|
|
|
|
if (_sprite.LayerMapTryGet((entity, sprite), MaxPressureVisualLayers.Base, out var layerIndex, false))
|
|
{
|
|
_sprite.LayerSetRsiState((entity, sprite), layerIndex, $"{entity.Comp.IntegrityMask}");
|
|
_sprite.LayerSetVisible((entity, sprite), layerIndex, false);
|
|
}
|
|
|
|
if (_sprite.LayerMapTryGet((entity, sprite), MaxPressureVisualLayers.BaseUnshaded, out layerIndex, false))
|
|
{
|
|
_sprite.LayerSetRsiState((entity, sprite), layerIndex, $"{entity.Comp.IntegrityState}-unshaded-0");
|
|
_sprite.LayerSetVisible((entity, sprite), layerIndex, false);
|
|
}
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnAppearanceChange(Entity<MaxPressureVisualsComponent> entity, ref AppearanceChangeEvent args)
|
|
{
|
|
if (args.Sprite is not { } sprite)
|
|
return;
|
|
|
|
if (!args.TryGetData<float>(GasIntegrity.Integrity, out var integrity)
|
|
|| !args.TryGetData<float>(GasIntegrity.MaxIntegrity, out var maxIntegrity))
|
|
return;
|
|
|
|
// We don't want visuals at max integrity, so we return if we're at max.
|
|
if (integrity >= maxIntegrity)
|
|
{
|
|
_sprite.LayerSetVisible((entity, sprite), MaxPressureVisualLayers.Base, false);
|
|
_sprite.LayerSetVisible((entity, sprite), MaxPressureVisualLayers.BaseUnshaded, false);
|
|
return;
|
|
}
|
|
|
|
_sprite.LayerSetVisible((entity, sprite), MaxPressureVisualLayers.Base, true);
|
|
_sprite.LayerSetVisible((entity, sprite), MaxPressureVisualLayers.BaseUnshaded, true);
|
|
|
|
// Subtract our integrity + 1 to get an accurate step count.
|
|
if (entity.Comp.IntegritySteps > 1)
|
|
{
|
|
var step = ContentHelpers.RoundToEqualLevels(maxIntegrity - integrity - 1, maxIntegrity, entity.Comp.IntegritySteps);
|
|
_sprite.LayerSetRsiState((entity, sprite), MaxPressureVisualLayers.BaseUnshaded, $"{entity.Comp.IntegrityState}-unshaded-{step}");
|
|
}
|
|
else
|
|
{
|
|
_sprite.LayerSetRsiState((entity, sprite), MaxPressureVisualLayers.BaseUnshaded, $"{entity.Comp.IntegrityState}-unshaded-0");
|
|
}
|
|
}
|
|
}
|