Resolves VaporVisualizer is Obsolete (#13882)
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
using System;
|
||||
using Content.Shared.Vapor;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Chemistry.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class VaporVisualizer : AppearanceVisualizer, ISerializationHooks
|
||||
{
|
||||
private const string AnimationKey = "flick_animation";
|
||||
|
||||
[DataField("animation_time")]
|
||||
private float _delay = 0.25f;
|
||||
|
||||
[DataField("animation_state")]
|
||||
private string _state = "chempuff";
|
||||
|
||||
private Animation VaporFlick = default!;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
VaporFlick = new Animation {Length = TimeSpan.FromSeconds(_delay)};
|
||||
{
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
VaporFlick.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = VaporVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(_state, 0f));
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (component.TryGetData<Color>(VaporVisuals.Color, out var color))
|
||||
{
|
||||
SetColor(component, color);
|
||||
}
|
||||
|
||||
if (component.TryGetData<bool>(VaporVisuals.State, out var state))
|
||||
{
|
||||
SetState(component, state);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetState(AppearanceComponent component, bool state)
|
||||
{
|
||||
if (!state) return;
|
||||
|
||||
var animPlayer = IoCManager.Resolve<IEntityManager>().GetComponent<AnimationPlayerComponent>(component.Owner);
|
||||
|
||||
if(!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
animPlayer.Play(VaporFlick, AnimationKey);
|
||||
}
|
||||
|
||||
private void SetColor(AppearanceComponent component, Color color)
|
||||
{
|
||||
var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<SpriteComponent>(component.Owner);
|
||||
|
||||
sprite.Color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public enum VaporVisualLayers : byte
|
||||
{
|
||||
Base
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Content.Shared.Vapor;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Chemistry.Visualizers;
|
||||
|
||||
/// <summary>
|
||||
/// Handles vapor playing the 'being sprayed' animation if necessary.
|
||||
/// </summary>
|
||||
public sealed class VaporVisualizerSystem : VisualizerSystem<VaporVisualsComponent>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<VaporVisualsComponent, ComponentInit>(OnComponentInit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the 'being sprayed' animation for the vapor entity.
|
||||
/// </summary>
|
||||
private void OnComponentInit(EntityUid uid, VaporVisualsComponent comp, ComponentInit args)
|
||||
{
|
||||
comp.VaporFlick = new Animation()
|
||||
{
|
||||
Length = TimeSpan.FromSeconds(comp.AnimationTime),
|
||||
AnimationTracks =
|
||||
{
|
||||
new AnimationTrackSpriteFlick()
|
||||
{
|
||||
LayerKey = VaporVisualLayers.Base,
|
||||
KeyFrames =
|
||||
{
|
||||
new AnimationTrackSpriteFlick.KeyFrame(comp.AnimationState, 0f)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the vapor entity plays its 'being sprayed' animation if necessary.
|
||||
/// </summary>
|
||||
protected override void OnAppearanceChange(EntityUid uid, VaporVisualsComponent comp, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (AppearanceSystem.TryGetData<Color>(uid, VaporVisuals.Color, out var color, args.Component) && args.Sprite != null)
|
||||
{
|
||||
args.Sprite.Color = color;
|
||||
}
|
||||
|
||||
if ((AppearanceSystem.TryGetData<bool>(uid, VaporVisuals.State, out var state, args.Component) && state) &&
|
||||
TryComp<AnimationPlayerComponent>(uid, out var animPlayer) &&
|
||||
!AnimationSystem.HasRunningAnimation(uid, animPlayer, VaporVisualsComponent.AnimationKey))
|
||||
{
|
||||
AnimationSystem.Play(uid, animPlayer, comp.VaporFlick, VaporVisualsComponent.AnimationKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum VaporVisualLayers : byte
|
||||
{
|
||||
Base
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Robust.Client.Animations;
|
||||
|
||||
namespace Content.Client.Chemistry.Visualizers;
|
||||
|
||||
/// <summary>
|
||||
/// A component that plays an animation when it is sprayed.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(VaporVisualizerSystem))]
|
||||
public sealed class VaporVisualsComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The id of the animation played when the vapor spawns in.
|
||||
/// </summary>
|
||||
public const string AnimationKey = "flick_animation";
|
||||
|
||||
/// <summary>
|
||||
/// The amount of time over which the spray animation is played.
|
||||
/// </summary>
|
||||
[DataField("animationTime")]
|
||||
public float AnimationTime = 0.25f;
|
||||
|
||||
/// <summary>
|
||||
/// The RSI state that is flicked when the vapor is sprayed.
|
||||
/// </summary>
|
||||
[DataField("animationState")]
|
||||
public string AnimationState = "chempuff";
|
||||
|
||||
/// <summary>
|
||||
/// The animation that plays when the vapor is sprayed.
|
||||
/// Generated in <see cref="VaporVisualizerSystem.OnComponentInit"/>
|
||||
/// </summary>
|
||||
public Animation VaporFlick = default!;
|
||||
}
|
||||
@@ -65,7 +65,6 @@
|
||||
- type: Physics
|
||||
bodyType: Dynamic
|
||||
- type: Appearance
|
||||
visuals:
|
||||
- type: VaporVisualizer
|
||||
animation_delay: 0.8
|
||||
animation_state: extinguish
|
||||
- type: VaporVisuals
|
||||
animationTime: 0.8
|
||||
animationState: extinguish
|
||||
|
||||
@@ -101,5 +101,4 @@
|
||||
- FullTileMask
|
||||
- Opaque
|
||||
- type: Appearance
|
||||
visuals:
|
||||
- type: VaporVisualizer
|
||||
- type: VaporVisuals
|
||||
|
||||
Reference in New Issue
Block a user