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

feat: Adding getters and methods for easier manipulation of selections #3350

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
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