leaveAnimations method

  1. @override
Future<void> leaveAnimations(
  1. List<String> names
)
override

Leaves only names animation.

Implementation

@override
Future<void> leaveAnimations(List<String> names) async {
  assert(names.isNotEmpty);

  print('\n--leave_animations'
      '\n\tsource: `$sourcePath`'
      '\n\tnames: $names'
      '\n');

  // 1) Search animations.
  var step = 1;
  resetCurrentIndent();
  late final JsonMap animations;
  {
    final p = pathToFileSkeleton;
    print('$currentIndent$step) Searching animations $names'
        ' into the `$p`...');

    final file = File(p);
    final skeleton = SpineSkeletonJson(file);
    animations =
        (skeleton.json['animations'] ?? <String, dynamic>{}) as JsonMap;
    String? notFoundName;
    for (final name in names) {
      assert(name.trim() == name);
      if (animations[name] == null) {
        notFoundName = name;
        break;
      }
    }

    if (notFoundName != null) {
      print('$currentIndent\tAnimation `$notFoundName` not found'
          ' into the `$p`.');
      return;
    }

    print('$currentIndent\tAll animations - $names -'
        ' found into the `$p`.');
  }

  // 2) Leave only animations.
  ++step;
  resetCurrentIndent();
  {
    final p = pathToFileSkeleton;
    print('$currentIndent$step) Leave only animations $names'
        ' into the `$p`...');

    final file = File(p);
    final skeleton = SpineSkeletonJson(file);
    final kept = skeleton.leaveAnimations(names);
    skeleton.save(kept);

    print('$currentIndent\tOnly animations $names'
        ' are kept into the `$p`.');
  }
}