updateTileset method

Future<void> updateTileset({
  1. required String path,
  2. required String name,
  3. bool gridUpdate = false,
  4. GridType? type,
  5. int? gridWidth,
  6. int? gridHeight,
  7. List<List<Rect>>? collisions,
})

Implementation

Future<void> updateTileset({required String path, required String name,bool gridUpdate = false, GridType? type, int? gridWidth, int? gridHeight, List<List<Rect>>? collisions}) async{
  if(tileSets.isEmpty  && !kIsWeb){
    fileName = name;
  }
  else{
    fileName = 'untitled';
  }

  await _loadImage(path).then((value) async{
    int height = (allTileImage == null?0:allTileImage!.height);
    tileSets.add(
      TileImage(
        size: Size(value.width.toDouble(),value.height.toDouble()),
        name: name,
        path: path,
        offsetHeight: height,
      )
    );
    if(allTileImage == null){
      allTileImage = value;
    }
    else{
      await _combineImage(allTileImage!,value).then((img){
        allTileImage = img;
      });
    }

    if(gridUpdate && gridWidth != null && gridHeight != null){
      if(type == GridType.manual){
        tileSets[tileSets.length-1].manualGrid(gridWidth, gridHeight);
        if(collisions != null){
          tileSets[tileSets.length-1].grid.collisions = collisions;
        }
      }
      else{
        tileSets[tileSets.length-1].autoGrid(allTileImage!).then((value){
          if(collisions != null){
            tileSets[tileSets.length-1].grid.collisions = collisions;
          }
        });
      }
    }
    update();
  });
}