using System.Collections.Generic; using System.Linq; using Robust.Client.Animations; using Robust.Shared.GameObjects; using static Robust.Client.Animations.AnimationPlaybackShared; namespace Robust.Client.GameObjects.Components.Animations { /// /// Plays back s on entities. /// public sealed class AnimationPlayerComponent : Component { public override string Name => "AnimationPlayer"; private readonly Dictionary _playingAnimations = new Dictionary(); /// /// Start playing an animation. /// /// The animation to play. /// /// The key for this animation play. This key can be used to stop playback short later. /// public void Play(Animation animation, string key) { var playback = new AnimationPlayback(animation); _playingAnimations.Add(key, playback); } public bool HasRunningAnimation(string key) { return _playingAnimations.ContainsKey(key); } public void Stop(string key) { _playingAnimations.Remove(key); } internal void Update(float frameTime) { if (_playingAnimations.Count == 0) { return; } // TODO: Get rid of this ToArray() allocation. foreach (var (key, playback) in _playingAnimations.ToArray()) { var keep = UpdatePlayback(Owner, playback, frameTime); if (!keep) { _playingAnimations.Remove(key); } } } } }