moveAnimation method

  1. @override
Future<void> moveAnimation(
  1. String nameFrom,
  2. String nameTo
)
override

Moves animation from nameFrom to nameTo.

Implementation

@override
Future<void> moveAnimation(String nameFrom, String nameTo) async {
  assert(nameFrom.isNotEmpty);
  assert(nameTo.isNotEmpty);

  print('\n--move_animation'
      '\n\tsource: `$sourcePath`'
      '\n\tnameFrom: $nameFrom'
      '\n\tnameTo: $nameTo'
      '\n');

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

    final file = File(p);
    final skeleton = SpineSkeletonJson(file);
    animations =
        (skeleton.json['animations'] ?? <String, dynamic>{}) as JsonMap;

    if (animations.isEmpty) {
      print('$currentIndent\tAnimation `$nameFrom` not found into the `$p`.');
      return;
    }

    print('$currentIndent\tAnimation `$nameFrom` found into the `$p`.');
  }

  // 2) Move animation.
  ++step;
  resetCurrentIndent();
  {
    final p = pathToFileSkeleton;
    print('$currentIndent$step) Moving animation `$nameFrom`'
        ' to `$nameTo` into the `$p`...');

    final file = File(p);
    final skeleton = SpineSkeletonJson(file);
    final moved = skeleton.moveAnimation(nameFrom, nameTo);
    skeleton.save(moved);

    print('$currentIndent\tAnimation `$nameFrom` moved'
        ' to `$nameFrom` into the `$p`.');
  }
}