CollisionArea.fromMap constructor

CollisionArea.fromMap(
  1. Map<String, dynamic> map
)

Implementation

factory CollisionArea.fromMap(Map<String, dynamic> map) {
  Vector2 align = Vector2(
    map['align']['x'],
    map['align']['y'],
  );
  if (map['shape']['type'] == 'RectangleShape') {
    return CollisionArea.rectangle(
        size: Vector2(
          map['shape']['size']['width'],
          map['shape']['size']['height'],
        ),
        align: align);
  }

  if (map['shape']['type'] == 'CircleShape') {
    return CollisionArea.circle(radius: map['shape']['radius'], align: align);
  }

  if (map['shape']['type'] == 'PolygonShape') {
    return CollisionArea.polygon(
        points: (map['shape']['points'] as List).map((e) {
          return Vector2(e['x'], e['y']);
        }).toList(),
        align: align);
  }

  return CollisionArea.rectangle(
    size: Vector2.zero(),
    align: align,
  );
}