decode static method

Take decode(
  1. Map<String, Object?> json, {
  2. List<(Duration, Object)>? cues,
})

Reads a timeline.

cues replaces the cues the file carries with the objects that were actually said — which is what an edit running in the same process as the scenario has and a file can never have. Without it, a cue the decoder does not recognise arrives as a ScenarioCueRecord.

Implementation

static Take decode(
  Map<String, Object?> json, {
  List<(Duration, Object)>? cues,
}) {
  var fps = (json['fps'] as num?)?.toInt() ?? 30;
  var rawPhases = json['beats'] as List? ?? const [];
  var phases = [
    for (var (i, raw) in rawPhases.indexed)
      Phase._decode(raw as Map<String, Object?>, i),
  ];
  var said = cues != null
      ? [for (var (at, cue) in cues) Said._(at, cue)]
      : [
          for (var raw in (json['cues'] as List? ?? const []))
            Said._decode(raw as Map<String, Object?>),
        ];
  var beats = _merge(_group(phases), said);
  return Take(
    scenario: json['scenario'] as String? ?? '',
    branches: [for (var b in (json['branches'] as List? ?? const [])) '$b'],
    fps: fps,
    scale: (json['scale'] as num?)?.toDouble() ?? 1,
    size: Size(
      (json['width'] as num?)?.toDouble() ?? 0,
      (json['height'] as num?)?.toDouble() ?? 0,
    ),
    screen: switch (json['screen']) {
      Map screen => Size(
        (screen['width'] as num?)?.toDouble() ?? 0,
        (screen['height'] as num?)?.toDouble() ?? 0,
      ),
      // An older timeline, or a film whose stage was the app itself: the
      // output is the screen.
      _ => Size(
        ((json['width'] as num?)?.toDouble() ?? 0) /
            ((json['scale'] as num?)?.toDouble() ?? 1),
        ((json['height'] as num?)?.toDouble() ?? 0) /
            ((json['scale'] as num?)?.toDouble() ?? 1),
      ),
    },
    duration: Duration(
      milliseconds: (json['durationMs'] as num?)?.toInt() ?? 0,
    ),
    beats: beats,
    dry: json['dry'] == true,
  );
}