emitter visuals update (#13382)

This commit is contained in:
Nemanja
2023-01-08 22:42:31 -05:00
committed by GitHub
parent 692079745f
commit 2933f030d9
7 changed files with 210 additions and 186 deletions

View File

@@ -0,0 +1,59 @@
using Content.Client.Storage.Visualizers;
using Content.Shared.Singularity.Components;
using Content.Shared.Singularity.EntitySystems;
using Content.Shared.Storage;
using Robust.Client.GameObjects;
namespace Content.Client.Singularity.Systems;
public sealed class EmitterSystem : SharedEmitterSystem
{
[Dependency] private readonly AppearanceSystem _appearance = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<EmitterComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
private void OnAppearanceChange(EntityUid uid, EmitterComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;
if (args.Sprite.LayerMapTryGet(StorageVisualLayers.Lock, out var lockLayer))
{
if (!_appearance.TryGetData(uid, StorageVisuals.Locked, out bool locked, args.Component))
locked = false;
args.Sprite.LayerSetVisible(lockLayer, locked);
}
if (!_appearance.TryGetData(uid, EmitterVisuals.VisualState, out EmitterVisualState state, args.Component))
state = EmitterVisualState.Off;
if (!args.Sprite.LayerMapTryGet(EmitterVisualLayers.Lights, out var layer))
return;
switch (state)
{
case EmitterVisualState.On:
if (component.OnState == null)
break;
args.Sprite.LayerSetVisible(layer, true);
args.Sprite.LayerSetState(layer, component.OnState);
break;
case EmitterVisualState.Underpowered:
if (component.UnderpoweredState == null)
break;
args.Sprite.LayerSetVisible(layer, true);
args.Sprite.LayerSetState(layer, component.UnderpoweredState);
break;
case EmitterVisualState.Off:
args.Sprite.LayerSetVisible(layer, false);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}

View File

@@ -1,55 +0,0 @@
using System;
using Content.Shared.Singularity.Components;
using Content.Shared.Storage;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Client.Singularity.Visualizers
{
[UsedImplicitly]
public sealed class EmitterVisualizer : AppearanceVisualizer
{
private const string OverlayBeam = "beam";
private const string OverlayUnderPowered = "underpowered";
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var entities = IoCManager.Resolve<IEntityManager>();
if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite))
{
return;
}
if (!component.TryGetData(StorageVisuals.Locked, out bool locked))
locked = false;
if (!component.TryGetData(EmitterVisuals.VisualState, out EmitterVisualState state))
state = EmitterVisualState.Off;
switch (state)
{
case EmitterVisualState.On:
sprite.LayerSetVisible(1, true);
sprite.LayerSetState(1, OverlayBeam);
break;
case EmitterVisualState.Underpowered:
sprite.LayerSetVisible(1, true);
sprite.LayerSetState(1, OverlayUnderPowered);
break;
case EmitterVisualState.Off:
sprite.LayerSetVisible(1, false);
break;
default:
throw new ArgumentOutOfRangeException();
}
sprite.LayerSetVisible(2, locked);
}
}
}