ILPInfoConfig.fromJson constructor

ILPInfoConfig.fromJson(
  1. Map map, {
  2. String? filePath,
  3. String? name,
})

Implementation

factory ILPInfoConfig.fromJson(Map map, {String? filePath, String? name}) {
  if (!map.containsKey('width')) {
    throw ILPConfigException(message: 'info_missing_width', file: filePath);
  }
  if (!map.containsKey('height')) {
    throw ILPConfigException(message: 'info_missing_height', file: filePath);
  }
  if (!map.containsKey('cover')) {
    throw ILPConfigException(message: 'info_missing_cover', file: filePath);
  }
  if (!File(map['cover']).existsSync()) {
    throw ILPConfigException(
      message: 'info_cover_not_exists',
      file: filePath,
    );
  }
  if (!map.containsKey('layers')) {
    throw ILPConfigException(message: 'info_missing_layers', file: filePath);
  }

  try {
    return ILPInfoConfig(
      filePath: filePath,
      name: name ?? map['name'],
      width: map['width'],
      height: map['height'],
      cover: map['cover'],
      layer: ILPLayerConfig(
        name: 'background',
        x: 0,
        y: 0,
        width: map['width'],
        height: map['height'],
        file: map['background'],
        layers: List.from(map['layers'].map((m) => ILPLayerConfig.create(m))),
      ),
    );
  } on ILPConfigException catch (e) {
    e.file = filePath;
    rethrow;
  }
}