build method
Implementation
Future<WorldBuildData> build({bool onlyObjects = false}) async {
try {
// Cache the parsed map so repeated builds (e.g. infinite maps loading
// one chunk at a time) don't re-read/re-parse the asset every time.
_tiledMap ??= await reader.readMap();
if (_tiledMap?.orientation != _mapOrientationSupported) {
throw Exception(
'Bonfire have only suport to $_mapOrientationSupported orientation.',
);
}
if (_tileWidthOrigin == 0) {
_tileWidthOrigin = _tiledMap?.tileWidth?.toDouble() ?? 0.0;
_tileHeightOrigin = _tiledMap?.tileHeight?.toDouble() ?? 0.0;
}
_tileWidth = forceTileSize?.x ?? _tileWidthOrigin;
_tileHeight = forceTileSize?.y ?? _tileHeightOrigin;
_lightingOccluders.clear();
if (onlyObjects) {
// Keep the tile layers untouched and only (re)build the objects of
// the object layers. Internal lists are cleared so repeated builds
// don't accumulate components.
_components.clear();
_mapDecorations.clear();
} else {
_layers.clear();
_components.clear();
_mapDecorations.clear();
}
await _load(_tiledMap!, onlyObjects: onlyObjects);
} catch (e) {
onError?.call(e);
// ignore: avoid_print
print('(TiledWorldBuilder) Error: $e');
}
return Future.value(
WorldBuildData(
map: WorldMap(
_layers.where((e) => e.tiles.isNotEmpty).toList(),
tileSizeToUpdate: sizeToUpdate,
),
components: _components,
mapChildren: _mapDecorations,
lightingOccluders: _lightingOccluders,
),
);
}