handleCallCommand method

void handleCallCommand({
  1. required CallCommand callCommand,
  2. List<CallCommand> calledCommands = const [],
  3. Map<String, String> replacements = const {},
  4. AssetReference? nullSound,
  5. SoundChannel? soundChannel,
  6. ZoneLevel? zoneLevel,
})

Call the specified callCommand.

Implementation

void handleCallCommand({
  required final CallCommand callCommand,
  final List<CallCommand> calledCommands = const [],
  final Map<String, String> replacements = const {},
  final AssetReference? nullSound,
  final SoundChannel? soundChannel,
  final ZoneLevel? zoneLevel,
}) {
  if (calledCommands.contains(callCommand)) {
    final category = world.commandCategories.firstWhere(
      (final element) => element.commands
          .where(
            (final element) => element.id == callCommand.commandId,
          )
          .isNotEmpty,
    );
    final commandName = category.commands.firstWhere(
      (final element) => element.id == callCommand.commandId,
    );
    throw UnsupportedError(
      'The $commandName command from the ${category.name} is attempting '
      'to call itself.',
    );
  }
  if (handleConditionals(callCommand.conditions) == false) {
    return;
  }
  final command = world.getCommand(callCommand.commandId);
  final callAfter = callCommand.callAfter;
  if (callAfter == null) {
    runCommand(
      command: command,
      replacements: replacements,
      calledCommands: [...calledCommands, callCommand],
      nullSound: nullSound,
      soundChannel: soundChannel,
      zoneLevel: zoneLevel,
    );
  } else {
    game.callAfter(
      runAfter: callAfter,
      func: () => runCommand(
        command: command,
        replacements: replacements,
        nullSound: nullSound,
        soundChannel: soundChannel,
        zoneLevel: zoneLevel,
      ),
    );
  }
}