WorldBloc constructor

WorldBloc(
  1. SetonixData data,
  2. SetonixServer server,
  3. String worldName
)

Implementation

WorldBloc(SetonixData data, this.server, this.worldName)
    : super(WorldState(
        data: data,
        table: data.getTableOrDefault(),
        metadata: data.getMetadataOrDefault(),
        info: data.getInfoOrDefault(),
      )) {
  _pluginSystem = PluginSystem(
    server: this,
  );
  _serverPlugin = _pluginSystem.registerPlugin('', SetonixPlugin.new);
  on<ServerWorldEvent>((event, emit) async {
    final signature = assetManager.createSignature();
    final processed =
        await _computeEvent(event, state, signature.values.toList());
    final newState = processed.state;
    processed.responses.forEach(process);
    if (event is WorldInitialized) {
      server.log(
          "World initialized${(event.info?.script != null) ? " with script ${event.info?.script}" : ""}",
          level: LogLevel.info);
      await _loadScript((newState ?? state).info.script);
    }
    if (newState == null) return;
    emit(newState);
    return save();
  }, transformer: sequential());
  on<ImagesUpdated>((event, emit) {
    emit(state.copyWith(images: event.images));
  });
}