diff --git a/packages/flame_fire_atlas/lib/flame_fire_atlas.dart b/packages/flame_fire_atlas/lib/flame_fire_atlas.dart index a354a1a0ff4..235e9d2b89b 100644 --- a/packages/flame_fire_atlas/lib/flame_fire_atlas.dart +++ b/packages/flame_fire_atlas/lib/flame_fire_atlas.dart @@ -60,6 +60,23 @@ class Selection { h: json['h'] as int, ); } + + /// Copies this instance with a new id. + Selection copyWith({ + String? id, + int? x, + int? y, + int? w, + int? h, + }) { + return Selection( + id: id ?? this.id, + x: x ?? this.x, + y: y ?? this.y, + w: w ?? this.w, + h: h ?? this.h, + ); + } } /// {@template _base_selection} @@ -93,9 +110,15 @@ abstract class BaseSelection { /// A group that this selection belongs to. final String? group; + /// The selection information. + Selection get selection => _info; + /// Copies this instance with a new group. BaseSelection copyWithGroup(String? group); + /// Copies this instance with a new selection info. + BaseSelection copyWithInfo(Selection info); + /// Returns this instance as a json. Map toJson() { final json = {} @@ -139,6 +162,12 @@ class SpriteSelection extends BaseSelection { SpriteSelection copyWithGroup(String? group) { return SpriteSelection(info: _info, group: group); } + + /// Copies this instance with a new info. + @override + SpriteSelection copyWithInfo(Selection info) { + return SpriteSelection(info: info, group: group); + } } /// {@template _animation_selection} @@ -199,6 +228,18 @@ class AnimationSelection extends BaseSelection { group: group, ); } + + /// Copies this instance with a new info. + @override + AnimationSelection copyWithInfo(Selection info) { + return AnimationSelection( + info: info, + frameCount: frameCount, + stepTime: stepTime, + loop: loop, + group: group, + ); + } } /// FireAtlas is a mapping file that can hold several [Sprite]s and