loadReplayPlan function

Future<ResolvedReplay?> loadReplayPlan(
  1. ReplayHarnessConfig config, {
  2. ReplayEventHook? eventHook,
})

Load a replay plan from configuration for inline use.

Returns null when no replay source (trace or scenario) is configured. Handles both trace-to-scenario conversion and direct scenario loading.

eventHook is optional and called for each custom event action in the replay scenario.

Implementation

Future<ResolvedReplay?> loadReplayPlan(
  ReplayHarnessConfig config, {
  ReplayEventHook? eventHook,
}) async {
  if (config.scenarioPath == null && config.tracePath == null) return null;

  ReplayScenario scenario;
  ReplayTraceConversionResult? traceConversion;
  String resolvedPath;

  if (config.tracePath != null) {
    final resolvedTrace = _resolveTracePath(config.tracePath!);
    traceConversion = await ReplayTraceConverter.convertFile(
      resolvedTrace,
      options: ReplayTraceConversionOptions(
        name: config.scenarioName,
        description: config.scenarioDescription,
        screenWidth: config.screenWidth,
        screenHeight: config.screenHeight,
        fixedRightWidth: config.fixedRightWidth,
        fromUs: config.traceFromUs,
        toUs: config.traceToUs,
        minSleepUs: config.minSleepUs,
        includeHoverMoves: config.traceIncludeHoverMoves,
      ),
    );
    scenario = traceConversion.scenario;
    resolvedPath = resolvedTrace;
    final scenarioOut = config.scenarioOut;
    if (scenarioOut != null && scenarioOut.isNotEmpty) {
      await scenario.save(scenarioOut);
      resolvedPath = scenarioOut;
    }
  } else {
    resolvedPath = config.scenarioPath!;
    scenario = await ReplayScenario.load(resolvedPath);
  }

  return ResolvedReplay(
    path: resolvedPath,
    name: scenario.name,
    actionCount: scenario.actions.length,
    loop: config.loop,
    keepOpen: config.keepOpen,
    blockInput: config.blockInput,
    speed: config.speed,
    replay: scenario.toProgramReplay(
      loop: config.loop,
      keepOpen: config.keepOpen,
      speed: config.speed,
      eventHook: eventHook,
    ),
    interceptor: ReplayCoordinateInterceptor(
      sourceWidth: scenario.screen.width,
      sourceHeight: scenario.screen.height,
      sourceRightFixedWidth: scenario.screen.fixedRightWidth,
    ),
    convertOnly: config.convertOnly,
    traceConversion: traceConversion,
  );
}