Remove obsolete usages of AnimationPlayerComponent (#20806)

This commit is contained in:
DrSmugleaf
2023-10-14 10:28:06 -07:00
committed by GitHub
parent 49a584f12c
commit 9e1ecdea76
8 changed files with 145 additions and 109 deletions

View File

@@ -431,20 +431,23 @@ namespace Content.Client.Light.Components
/// </summary>
public void StartLightBehaviour(string id = "")
{
if (!_entMan.TryGetComponent(Owner, out AnimationPlayerComponent? animation))
var uid = Owner;
if (!_entMan.TryGetComponent(uid, out AnimationPlayerComponent? animation))
{
return;
}
var animations = _entMan.System<AnimationPlayerSystem>();
foreach (var container in Animations)
{
if (container.LightBehaviour.ID == id || id == string.Empty)
{
if (!animation.HasRunningAnimation(KeyPrefix + container.Key))
if (!animations.HasRunningAnimation(uid, animation, KeyPrefix + container.Key))
{
CopyLightSettings(container.LightBehaviour.Property);
container.LightBehaviour.UpdatePlaybackValues(container.Animation);
animation.Play(container.Animation, KeyPrefix + container.Key);
animations.Play(uid, animation, container.Animation, KeyPrefix + container.Key);
}
}
}
@@ -460,20 +463,22 @@ namespace Content.Client.Light.Components
/// <param name="resetToOriginalSettings">Should the light have its original settings applied?</param>
public void StopLightBehaviour(string id = "", bool removeBehaviour = false, bool resetToOriginalSettings = false)
{
if (!_entMan.TryGetComponent(Owner, out AnimationPlayerComponent? animation))
var uid = Owner;
if (!_entMan.TryGetComponent(uid, out AnimationPlayerComponent? animation))
{
return;
}
var toRemove = new List<AnimationContainer>();
var animations = _entMan.System<AnimationPlayerSystem>();
foreach (var container in Animations)
{
if (container.LightBehaviour.ID == id || id == string.Empty)
{
if (animation.HasRunningAnimation(KeyPrefix + container.Key))
if (animations.HasRunningAnimation(uid, animation, KeyPrefix + container.Key))
{
animation.Stop(KeyPrefix + container.Key);
animations.Stop(uid, animation, KeyPrefix + container.Key);
}
if (removeBehaviour)
@@ -488,7 +493,7 @@ namespace Content.Client.Light.Components
Animations.Remove(container);
}
if (resetToOriginalSettings && _entMan.TryGetComponent(Owner, out PointLightComponent? light))
if (resetToOriginalSettings && _entMan.TryGetComponent(uid, out PointLightComponent? light))
{
foreach (var (property, value) in _originalPropertyValues)
{
@@ -505,12 +510,14 @@ namespace Content.Client.Light.Components
/// <returns>Whether at least one behaviour is running, false if none is.</returns>
public bool HasRunningBehaviours()
{
if (!_entMan.TryGetComponent(Owner, out AnimationPlayerComponent? animation))
var uid = Owner;
if (!_entMan.TryGetComponent(uid, out AnimationPlayerComponent? animation))
{
return false;
}
return Animations.Any(container => animation.HasRunningAnimation(KeyPrefix + container.Key));
var animations = _entMan.System<AnimationPlayerSystem>();
return Animations.Any(container => animations.HasRunningAnimation(uid, animation, KeyPrefix + container.Key));
}
/// <summary>

View File

@@ -3,14 +3,13 @@ using Content.Shared.Light.Components;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Maths;
namespace Content.Client.Light.Systems;
namespace Content.Client.Light.EntitySystems;
public sealed class RotatingLightSystem : SharedRotatingLightSystem
{
[Dependency] private readonly AnimationPlayerSystem _animations = default!;
private Animation GetAnimation(float speed)
{
var third = 120f / speed;
@@ -64,7 +63,7 @@ public sealed class RotatingLightSystem : SharedRotatingLightSystem
}
else
{
player.Stop(AnimKey);
_animations.Stop(uid, player, AnimKey);
}
}
@@ -81,9 +80,9 @@ public sealed class RotatingLightSystem : SharedRotatingLightSystem
if (!Resolve(uid, ref comp, ref player) || !comp.Enabled)
return;
if (!player.HasRunningAnimation(AnimKey))
if (!_animations.HasRunningAnimation(uid, player, AnimKey))
{
player.Play(GetAnimation(comp.Speed), AnimKey);
_animations.Play(uid, player, GetAnimation(comp.Speed), AnimKey);
}
}
}