using Content.Shared.Vapor; using Robust.Client.Animations; using Robust.Client.GameObjects; namespace Content.Client.Chemistry.Visualizers; /// /// Handles vapor playing the 'being sprayed' animation if necessary. /// public sealed class VaporVisualizerSystem : VisualizerSystem { public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnComponentInit); } /// /// Constructs the 'being sprayed' animation for the vapor entity. /// 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) } } } }; if (AppearanceSystem.TryGetData(uid, VaporVisuals.State, out var state) && state && TryComp(uid, out var animPlayer) && !AnimationSystem.HasRunningAnimation(uid, animPlayer, VaporVisualsComponent.AnimationKey)) { AnimationSystem.Play((uid, animPlayer), comp.VaporFlick, VaporVisualsComponent.AnimationKey); } } /// /// Ensures that the vapor entity plays its 'being sprayed' animation if necessary. /// protected override void OnAppearanceChange(EntityUid uid, VaporVisualsComponent comp, ref AppearanceChangeEvent args) { if (AppearanceSystem.TryGetData(uid, VaporVisuals.Color, out var color, args.Component) && args.Sprite != null) { args.Sprite.Color = color; } } } public enum VaporVisualLayers : byte { Base }