Skip to content

Commit

Permalink
feat: Adding getters and methods for easier manipulation of selections (
Browse files Browse the repository at this point in the history
flame-engine#3350)

Adding getters and methods to making it easier to copy new selections,
which will help the editor to offer more features.
  • Loading branch information
erickzanardo authored Oct 22, 2024
1 parent e591ebf commit 291af57
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/flame_fire_atlas/lib/flame_fire_atlas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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<String, dynamic> toJson() {
final json = <String, dynamic>{}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 291af57

Please sign in to comment.