From 556f89e07695e74738d973c2646325c6ac73ca25 Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Tue, 17 Mar 2026 12:38:45 +0100 Subject: [PATCH] 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 --- .../src/data_types/sprite_frame_range.dart | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/wolf_3d_dart/lib/src/data_types/sprite_frame_range.dart b/packages/wolf_3d_dart/lib/src/data_types/sprite_frame_range.dart index 95a87d7..bd55592 100644 --- a/packages/wolf_3d_dart/lib/src/data_types/sprite_frame_range.dart +++ b/packages/wolf_3d_dart/lib/src/data_types/sprite_frame_range.dart @@ -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 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; + /// 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 animation range. - bool contains(int index) => index >= start && index <= end; + /// 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); + } }