Added the ability to exclude frames from a frame range. This will help with death animations where the sprites are out of order.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-17 12:38:45 +01:00
parent a778e0f1fa
commit 556f89e076

View File

@@ -1,13 +1,28 @@
/// Represents a slice of indices within a sprite list for animation states.
/// Represents a slice of indices within a sprite list for animation states,
/// with the ability to skip specific frames.
class SpriteFrameRange {
final int start;
final int end;
final Set<int> excluded;
const SpriteFrameRange(this.start, this.end);
const SpriteFrameRange(
this.start,
this.end, {
this.excluded = const {},
});
/// Total number of frames in this animation range.
int get length => end - start + 1;
/// Checks if a specific sprite [index] is part of this animation range.
bool contains(int index) => index >= start && index <= end;
/// Total number of frames in this animation range, excluding skipped indices.
int get length {
final baseLength = end - start + 1;
// Count how many excluded indices actually fall within the start/end bounds
final exclusionsInRange = excluded
.where((i) => i >= start && i <= end)
.length;
return baseLength - exclusionsInRange;
}
/// Checks if a specific sprite [index] is part of this range and not excluded.
bool contains(int index) {
return index >= start && index <= end && !excluded.contains(index);
}
}