Skip to content

Commit

Permalink
Add AnimationCompletedEvent "Finished" boolean.
Browse files Browse the repository at this point in the history
Content has multiple cases where AnimationCompletedEvent is used to loop an animation. #5238 broke some of these by making this event raised even when manually removed.

Luckily most cases in content tie the animation looping to the presence of a component, so the component getting removed means there's nothing to refresh the loop. LightBehavior is not as fortunate however, causing bugs like space-wizards/space-station-14#29144

This boolean allows looping code to properly distinguish the event, so it won't try to restart an animation after removing it directly.
  • Loading branch information
PJB3005 committed Jun 25, 2024
1 parent 90e8752 commit a4ea5a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ END TEMPLATE-->

### New features

*None yet*
* Added a `Finished` boolean to `AnimationCompletedEvent` which allows distinguishing if an animation was removed prematurely or completed naturally.

### Bugfixes

Expand Down
12 changes: 10 additions & 2 deletions Robust.Client/GameObjects/EntitySystems/AnimationPlayerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ private bool Update(EntityUid uid, AnimationPlayerComponent component, float fra
foreach (var key in remie)
{
component.PlayingAnimations.Remove(key);
EntityManager.EventBus.RaiseLocalEvent(uid, new AnimationCompletedEvent {Uid = uid, Key = key}, true);
var completedEvent = new AnimationCompletedEvent {Uid = uid, Key = key, Finished = true};
EntityManager.EventBus.RaiseLocalEvent(uid, completedEvent, true);
}

return false;
Expand Down Expand Up @@ -187,7 +188,8 @@ public void Stop(Entity<AnimationPlayerComponent?> entity, string key)
return;
}

EntityManager.EventBus.RaiseLocalEvent(entity.Owner, new AnimationCompletedEvent {Uid = entity.Owner, Key = key}, true);
var completedEvent = new AnimationCompletedEvent {Uid = entity.Owner, Key = key, Finished = false};
EntityManager.EventBus.RaiseLocalEvent(entity.Owner, completedEvent, true);
}

public void Stop(EntityUid uid, AnimationPlayerComponent? component, string key)
Expand All @@ -203,5 +205,11 @@ public sealed class AnimationCompletedEvent : EntityEventArgs
{
public EntityUid Uid { get; init; }
public string Key { get; init; } = string.Empty;

/// <summary>
/// If true, the animation finished by getting to its natural end.
/// If false, it was removed prematurely via <see cref="AnimationPlayerSystem.Stop(Robust.Client.GameObjects.AnimationPlayerComponent,string)"/> or similar overloads.
/// </summary>
public bool Finished { get; init; }
}
}

0 comments on commit a4ea5a4

Please sign in to comment.