createWithFiles static method

Future<SkeletonAnimation> createWithFiles(
  1. String name, {
  2. String pathBase = '',
  3. String rawAtlas = '',
  4. String rawSkeleton = '',
  5. Uint8List? rawTexture,
})

Implementation

static Future<SkeletonAnimation> createWithFiles(
  String name, {
  String pathBase = '',
  String rawAtlas = '',
  String rawSkeleton = '',
  Uint8List? rawTexture,
}) async {
  final String atlasDataFile = '$name.atlas';
  final String skeletonDataFile = '$name.json';
  final String path = '$pathBase$name/';

  final Map<String, dynamic> assets = <String, dynamic>{};
  final List<Future<MapEntry<String, dynamic>>> futures =
      <Future<MapEntry<String, dynamic>>>[
    AssetLoader.loadJson(path + skeletonDataFile, rawSkeleton),
    AssetLoader.loadText(path + atlasDataFile, rawAtlas),
  ];

  final List<String> textureDataFiles =
      await textureFilesFromAtlas(path + atlasDataFile);
  for (final String textureDataFile in textureDataFiles) {
    final Future<MapEntry<String, dynamic>> entry =
        AssetLoader.loadTexture(path + textureDataFile, rawTexture);
    futures.add(entry);
  }

  await Future.wait(futures).then(assets.addEntries).catchError((Object e) {
    if (kDebugMode) {
      print("Couldn't add entries. $e");
    }
  });

  final core.TextureAtlas atlas = core.TextureAtlas(
      assets[path + atlasDataFile], (String? p) => assets[path + (p ?? '')]);
  final core.AtlasAttachmentLoader atlasLoader =
      core.AtlasAttachmentLoader(atlas);
  final core.SkeletonJson skeletonJson = core.SkeletonJson(atlasLoader);
  final core.SkeletonData skeletonData =
      skeletonJson.readSkeletonData(assets[path + skeletonDataFile]);

  return SkeletonAnimation(skeletonData);
}