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:
@@ -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 {
|
class SpriteFrameRange {
|
||||||
final int start;
|
final int start;
|
||||||
final int end;
|
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.
|
/// Total number of frames in this animation range, excluding skipped indices.
|
||||||
int get length => end - start + 1;
|
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 animation range.
|
/// Checks if a specific sprite [index] is part of this range and not excluded.
|
||||||
bool contains(int index) => index >= start && index <= end;
|
bool contains(int index) {
|
||||||
|
return index >= start && index <= end && !excluded.contains(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user