Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(JitteringSystem): Fix warnings and double Play. #30085

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Content.Client/Jittering/JitteringSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class JitteringSystem : SharedJitteringSystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AnimationPlayerSystem _animationPlayer = default!;

private readonly float[] _sign = { -1, 1 };
private readonly float[] _sign = [-1, 1];
private readonly string _jitterAnimationKey = "jittering";

public override void Initialize()
Expand All @@ -28,10 +28,12 @@ private void OnStartup(EntityUid uid, JitteringComponent jittering, ComponentSta
if (!TryComp(uid, out SpriteComponent? sprite))
return;

var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
if (_animationPlayer.HasRunningAnimation(uid, _jitterAnimationKey))
return;

jittering.StartOffset = sprite.Offset;
_animationPlayer.Play(uid, animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);

_animationPlayer.Play(uid, GetAnimation(jittering, sprite), _jitterAnimationKey);
}

private void OnShutdown(EntityUid uid, JitteringComponent jittering, ComponentShutdown args)
Expand All @@ -51,9 +53,10 @@ private void OnAnimationCompleted(EntityUid uid, JitteringComponent jittering, A
if (!args.Finished)
return;

if (TryComp(uid, out AnimationPlayerComponent? animationPlayer)
&& TryComp(uid, out SpriteComponent? sprite))
_animationPlayer.Play(uid, animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
if (HasComp<AnimationPlayerComponent>(uid)
&& TryComp(uid, out SpriteComponent? sprite)
&& !_animationPlayer.HasRunningAnimation(uid, _jitterAnimationKey))
_animationPlayer.Play(uid, GetAnimation(jittering, sprite), _jitterAnimationKey);
Comment on lines +56 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the animation player be passed in here still?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there are Play functions that do but they're deprecated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see one that takes in Entity that looks suitable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that the uid in arg0? Or am I missing something here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using public void Play(EntityUid uid, Animation animation, string key) which basically calls Play the same way in this case, except I guess we could drop the HasComp check if I use it the way as it is in this PR.

}

private Animation GetAnimation(JitteringComponent jittering, SpriteComponent sprite)
Expand Down Expand Up @@ -96,9 +99,9 @@ private Animation GetAnimation(JitteringComponent jittering, SpriteComponent spr
{
new AnimationTrackProperty.KeyFrame(sprite.Offset, 0f),
new AnimationTrackProperty.KeyFrame(jittering.StartOffset + offset, length),
}
}
}
},
},
},
};
}
}
Expand Down
Loading