readFromLocal method

Future<TiledMap> readFromLocal()

Implementation

Future<TiledMap> readFromLocal() async {
  String data = await io.File(pathFile).readAsString();
  Map<String, dynamic> _result = jsonDecode(data);
  _map = TiledMap.fromJson(_result);
  if (_map?.tileSets != null) {
    await Future.forEach(_map!.tileSets!, (TileSetDetail tileSet) async {
      if (!tileSet.source!.contains('.json')) {
        throw Exception('Invalid TileSet source: only supports json files');
      }
      String data = await io.File(
        '$_basePathFile${tileSet.source}',
      ).readAsString();
      Map<String, dynamic> _result = jsonDecode(data);
      tileSet.tileSet = TileSet.fromJson(_result);
    });
  }
  return Future.value(_map);
}