Skip to content

Commit

Permalink
fix: Disallow mutatation of SpriteAnimationGroupComponent.animations (
Browse files Browse the repository at this point in the history
#3183)

Many users try to modify the `SpriteAnimationGroupComponent.animations`
map, but that doesn't work since it has to go through the setter, so
this PR makes the returned map from the getter unmodifiable.
  • Loading branch information
spydon authored Jun 5, 2024
1 parent a1f9633 commit 5277340
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ class SpriteAnimationGroupComponent<T> extends PositionComponent
}

/// Returns the map of animation state and their corresponding animations.
Map<T, SpriteAnimation>? get animations => _animations;
///
/// If you want to change the contents of the map use the animations setter
/// and pass in a new map of animations
Map<T, SpriteAnimation>? get animations =>
_animations != null ? Map.unmodifiable(_animations!) : null;

/// Sets the given [value] as new animation state map.
set animations(Map<T, SpriteAnimation>? value) {
Expand Down

0 comments on commit 5277340

Please sign in to comment.