read static method

KeyFrame? read(
  1. StreamReader reader,
  2. ActorComponent? component
)
override

Implementation

static KeyFrame? read(StreamReader reader, ActorComponent? component) {
  KeyFramePathVertices frame = KeyFramePathVertices();
  if (!KeyFrameWithInterpolation.read(reader, frame) ||
      component is! ActorPath) {
    return null;
  }

  ActorPath pathNode = component;

  int length = pathNode.points.fold<int>(0, (int previous, PathPoint point) {
    return previous + 2 + (point.pointType == PointType.straight ? 1 : 4);
  });
  frame._vertices = Float32List(length);
  int readIdx = 0;
  reader.openArray('value');
  for (final PathPoint point in pathNode.points) {
    frame._vertices[readIdx++] = reader.readFloat32('translationX');
    frame._vertices[readIdx++] = reader.readFloat32('translationY');
    if (point.pointType == PointType.straight) {
      // radius
      frame._vertices[readIdx++] = reader.readFloat32('radius');
    } else {
      // in/out
      frame._vertices[readIdx++] = reader.readFloat32('inValueX');
      frame._vertices[readIdx++] = reader.readFloat32('inValueY');
      frame._vertices[readIdx++] = reader.readFloat32('outValueX');
      frame._vertices[readIdx++] = reader.readFloat32('outValueY');
    }
  }
  reader.closeArray();

  pathNode.makeVertexDeform();
  return frame;
}