Resolves ThrusterVisualizer is Obsolete (#13904)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
12
Content.Client/Shuttles/ThrusterComponent.cs
Normal file
12
Content.Client/Shuttles/ThrusterComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Client.Shuttles;
|
||||
|
||||
/// <summary>
|
||||
/// A component that emits a visible exhaust plume if the entity is an active thruster.
|
||||
/// Managed by <see cref="ThrusterSystem"/>
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(ThrusterSystem))]
|
||||
public sealed class ThrusterComponent : Component
|
||||
{
|
||||
}
|
||||
51
Content.Client/Shuttles/ThrusterSystem.cs
Normal file
51
Content.Client/Shuttles/ThrusterSystem.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Shuttles;
|
||||
|
||||
/// <summary>
|
||||
/// Handles making a thruster visibly turn on/emit an exhaust plume according to its state.
|
||||
/// </summary>
|
||||
public sealed class ThrusterSystem : VisualizerSystem<ThrusterComponent>
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates whether or not the thruster is visibly active/thrusting.
|
||||
/// </summary>
|
||||
protected override void OnAppearanceChange(EntityUid uid, ThrusterComponent comp, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (args.Sprite == null
|
||||
|| !AppearanceSystem.TryGetData<bool>(uid, ThrusterVisualState.State, out var state, args.Component))
|
||||
return;
|
||||
|
||||
args.Sprite.LayerSetVisible(ThrusterVisualLayers.ThrustOn, state);
|
||||
SetThrusting(
|
||||
uid,
|
||||
state && AppearanceSystem.TryGetData<bool>(uid, ThrusterVisualState.Thrusting, out var thrusting, args.Component) && thrusting,
|
||||
args.Sprite
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not the exhaust plume of the thruster is visible or not.
|
||||
/// </summary>
|
||||
private static void SetThrusting(EntityUid _, bool value, SpriteComponent sprite)
|
||||
{
|
||||
if (sprite.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out var thrustingLayer))
|
||||
{
|
||||
sprite.LayerSetVisible(thrustingLayer, value);
|
||||
}
|
||||
|
||||
if (sprite.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out var unshadedLayer))
|
||||
{
|
||||
sprite.LayerSetVisible(unshadedLayer, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ThrusterVisualLayers : byte
|
||||
{
|
||||
Base,
|
||||
ThrustOn,
|
||||
Thrusting,
|
||||
ThrustingUnshaded,
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
using Content.Shared.Shuttles.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Client.Shuttles
|
||||
{
|
||||
public sealed class ThrusterVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[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 SpriteComponent? spriteComponent)) return;
|
||||
|
||||
component.TryGetData(ThrusterVisualState.State, out bool state);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case true:
|
||||
spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustOn, true);
|
||||
|
||||
if (component.TryGetData(ThrusterVisualState.Thrusting, out bool thrusting) && thrusting)
|
||||
{
|
||||
if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out _))
|
||||
{
|
||||
spriteComponent.LayerSetVisible(ThrusterVisualLayers.Thrusting, true);
|
||||
}
|
||||
|
||||
if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out _))
|
||||
{
|
||||
spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustingUnshaded, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableThrusting(component, spriteComponent);
|
||||
}
|
||||
|
||||
break;
|
||||
case false:
|
||||
spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustOn, false);
|
||||
DisableThrusting(component, spriteComponent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void DisableThrusting(AppearanceComponent component, SpriteComponent spriteComponent)
|
||||
{
|
||||
if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out _))
|
||||
{
|
||||
spriteComponent.LayerSetVisible(ThrusterVisualLayers.Thrusting, false);
|
||||
}
|
||||
|
||||
if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out _))
|
||||
{
|
||||
spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustingUnshaded, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ThrusterVisualLayers : byte
|
||||
{
|
||||
Base,
|
||||
ThrustOn,
|
||||
Thrusting,
|
||||
ThrustingUnshaded,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user