load static method

Future<PlaybackReport> load(
  1. String path
)

Implementation

static Future<PlaybackReport> load(String path) async {
  final file = File(path);
  if (!file.existsSync()) {
    throw Exception('File not found');
  }
  Archive archive = TarDecoder().decodeBuffer(InputFileStream(path));

  ReplayReportInfo basicInfo = ReplayReportInfo();
  List<int>? log;
  List<CheckpointMatchError> matchErrors = <CheckpointMatchError>[];

  Map<int, RatioRect> matchPositionMap = <int, RatioRect>{};
  Map<int, List<int>> recorderImage = <int, List<int>>{};
  Map<int, List<int>> playerImage = <int, List<int>>{};

  final iterator = archive.iterator;
  while (iterator.moveNext()) {
    final data = iterator.current.content as List<int>;
    final name = iterator.current.name;
    if (name == TarKey.playbackBasicInfo) {
      basicInfo = ReplayReportInfo.fromBuffer(data);
    } else if (name == TarKey.log) {
      log = data;
    } else if (name.startsWith(TarKey.matchPositionPrefix)) {
      final index =
          int.parse(name.replaceAll(TarKey.matchPositionPrefix, ''));
      matchPositionMap[index] =
          RatioRect.matchPosition(MatchPosition.fromBuffer(data));
    } else if (name.startsWith(TarKey.recorderImgPrefix)) {
      final index = int.parse(name.replaceAll(TarKey.recorderImgPrefix, ''));
      recorderImage[index] = data;
    } else if (name.startsWith(TarKey.playerImgPrefix)) {
      final index = int.parse(name.replaceAll(TarKey.playerImgPrefix, ''));
      playerImage[index] = data;
    }
  }
  matchPositionMap.forEach((key, value) {
    matchErrors.add(CheckpointMatchError(
        imageOfRecorder: Uint8List.fromList(recorderImage[key]!),
        imageOfPlayer: Uint8List.fromList(playerImage[key]!),
        matchPosition: matchPositionMap[key]!));
  });

  return PlaybackReport(
      basicInfo: basicInfo, log: log, matchErrors: matchErrors);
}