ILPLayerConfig.create constructor

ILPLayerConfig.create(
  1. dynamic data
)

Implementation

factory ILPLayerConfig.create(dynamic data) {
  if (data is List) {
    return ILPLayerConfig(
      layers: List.from(data.map((e) => ILPLayerConfig.create(e))),
    );
  } else if (data is Map) {
    if (data.containsKey('layers')) {
      return ILPLayerConfig(
        name: data['name'],
        layers: List.from(
          data['layers'].map((e) => ILPLayerConfig.create(e)),
        ),
      );
    } else {
      if (!data.containsKey('width')) {
        throw ILPConfigException(message: 'layer_missing_width');
      }
      if (!data.containsKey('height')) {
        throw ILPConfigException(message: 'layer_missing_height');
      }
      if (!data.containsKey('x')) {
        throw ILPConfigException(message: 'layer_missing_x');
      }
      if (!data.containsKey('y')) {
        throw ILPConfigException(message: 'layer_missing_y');
      }
      if (!data.containsKey('file')) {
        throw ILPConfigException(message: 'layer_missing_file');
      }
      if (!File(data['file']).existsSync()) {
        throw ILPConfigException(message: 'layer_file_not_exists');
      }
      return ILPLayerConfig(
        name: data['name'],
        width: data['width'],
        height: data['height'],
        x: data['x'],
        y: data['y'],
        file: data['file'],
      );
    }
  } else {
    throw ILPConfigException(message: 'layer_data_error');
  }
}