animations method
Every row of the grid, played as rows says, end to end.
Rows are stated in the order the grid holds them. A SheetRow.skip passes
over as many as it counts, and a row left unstated plays whole at fps.
Implementation
SpriteGroup animations({
required double fps,
bool? loop,
List<SheetRow>? rows,
}) {
final grid = this.rows;
final declared = rows ?? const <SheetRow>[];
final animations = <Sprite<int>>[];
var index = 0;
var row = 0;
while (row < grid) {
SheetRow? stated;
while (index < declared.length) {
final next = declared[index];
index += 1;
final skip = next.skip;
if (skip == null) {
stated = next;
break;
}
row += skip;
if (row > grid) {
throw ArgumentError.value(
skip,
'rows[${index - 1}]',
'Skips past row $grid, from row ${row - skip}.',
);
}
}
if (row >= grid) break;
final durations = stated?.durations;
if (durations == null) {
animations.add(
animation(
row: row,
start: stated?.start,
end: stated?.end,
fps: stated?.fps ?? fps,
loop: stated?.loop ?? loop,
),
);
} else {
animations.add(
timed(
durations,
row: row,
start: stated?.start,
loop: stated?.loop ?? loop,
),
);
}
row += 1;
}
if (index < declared.length) {
throw ArgumentError.value(
declared.length,
'rows',
'The sheet only has $grid rows.',
);
}
if (animations.isEmpty) {
throw ArgumentError.value(rows, 'rows', 'Every row is skipped.');
}
return SpriteGroup(animations);
}