readMap method

Future<TiledMap> readMap()

Implementation

Future<TiledMap> readMap() async {
  if (_fromServer) {
    try {
      final mapResponse = await http.get(Uri.parse(path));
      TiledMap tiledMap = TiledMap.fromJson(jsonDecode(mapResponse.body));
      await Future.forEach<TileSetDetail>(
        tiledMap.tileSets ?? [],
        _fillTileSet,
      );
      if (tiledMap.orientation != ORIENTATION_SUPPORTED) {
        throw Exception(
          'Orientation not supported. please use $ORIENTATION_SUPPORTED orientation',
        );
      }
      return Future.value(tiledMap);
    } catch (e) {
      // ignore: avoid_print
      print('(TiledReader) Error: $e');
      return Future.value(TiledMap());
    }
  } else {
    return _reader.read();
  }
}