getLaunchOptions method

List getLaunchOptions ({@required Authorization auth, dynamic modification })

Implementation

List getLaunchOptions({@required Authorization auth, modification}) {
  Map type = modification ?? this.version;

  List args = type["minecraftArguments"] != null ? type["minecraftArguments"].split(' ') : type["arguments"]["game"];
  String assetRoot = path.join(this.root, 'assets');
  String assetPath = this.version["assets"] == "legacy" || this.version["assets"] == "pre-1.6" ? path.join(assetRoot, 'legacy') : assetRoot;

  int minArgs =  5;
  if(args.length < minArgs) args.addAll(type["minecraftArguments"] != null ? type["minecraftArguments"].split(' ') : type["arguments"]["game"]);

  Map<String,String> fields = {
    '\${auth_access_token}': auth.access_token, //this.options.authorization.access_token,
    '\${auth_session}': auth.access_token, //this.options.authorization.access_token,
    '\${auth_player_name}': auth.name, //this.options.authorization.name,
    '\${auth_uuid}': auth.uuid, //this.options.authorization.uuid,
    '\${user_properties}': auth.user_properties, //this.options.authorization.user_properties,
    '\${user_type}': 'mojang',
    '\${version_name}': this.version["id"],
    '\${assets_index_name}': this.version["assetIndex"]["id"],
    '\${game_directory}': resolvePath(root),
    '\${assets_root}':  resolvePath(assetPath),
    '\${game_assets}': resolvePath(assetPath),
    '\${version_type}': this.version["type"],
  };

  for (int index = 0; index < args.length; index++) {
    if (fields.keys.contains(args[index])) {
      args[index] = fields[args[index]];
    }
    else if(args[index] is Map) {
      args.removeAt(index);
      index--;
    }
    else if(args[index] == "") {
      args.removeAt(index);
      index--;
    }
  }
  return args;

}