Default game arguments

This commit is contained in:
huangyuhui 2017-11-03 13:38:20 +08:00
parent 9d95d3ea66
commit b5fbc69ee6
5 changed files with 33 additions and 17 deletions

View File

@ -147,13 +147,6 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
HMCLog.log("On making launcher args.");
if (StrUtils.isNotBlank(options.getHeight()) && StrUtils.isNotBlank(options.getWidth())) {
res.add("--height");
res.add(options.getHeight());
res.add("--width");
res.add(options.getWidth());
}
String serverIp = options.getServerIp();
if (StrUtils.isNotBlank(serverIp)) {
String[] args = serverIp.split(":");

View File

@ -33,6 +33,7 @@ import org.jackhuang.hmcl.core.GameException;
import org.jackhuang.hmcl.api.auth.UserProfileProvider;
import org.jackhuang.hmcl.core.version.MinecraftLibrary;
import org.jackhuang.hmcl.core.service.IMinecraftService;
import org.jackhuang.hmcl.core.version.Argument;
import org.jackhuang.hmcl.core.version.Arguments;
/**
@ -46,8 +47,18 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
if (version.arguments == null)
version.arguments = new Arguments();
if (version.arguments.game == null)
version.arguments.game = getDefaultGameArguments();
if (version.arguments.jvm == null)
version.arguments.jvm = Arguments.DEFAULT_JVM_ARGUMENTS;
version.arguments.jvm = getDefaultJVMArguments();
}
protected List<Argument> getDefaultJVMArguments() {
return Arguments.DEFAULT_JVM_ARGUMENTS;
}
protected List<Argument> getDefaultGameArguments() {
return Arguments.DEFAULT_GAME_ARGUMENTS;
}
@Override
@ -86,16 +97,16 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
res.addAll(Arguments.parseArguments(version.arguments.jvm, configuration));
res.add(version.mainClass);
Map<String, Boolean> features = new HashMap<>();
Map<String, Boolean> features = getFeatures();
if (version.arguments.game != null)
res.addAll(Arguments.parseArguments(version.arguments.game, configuration, features));
res.addAll(Arguments.parseArguments(version.arguments.game, configuration, features));
res.addAll(Arguments.parseStringArguments(Arrays.asList(StrUtils.tokenize(version.minecraftArguments)), configuration));
if (res.indexOf("--gameDir") != -1 && res.indexOf("--workDir") != -1) {
res.add("--workDir");
res.add(gameDir.getAbsolutePath());
}
}
protected Map<String, Boolean> getFeatures() {
Map<String, Boolean> features = new HashMap<>();
features.put("has_custom_resolution", StrUtils.isNotBlank(options.getHeight()) && StrUtils.isNotBlank(options.getWidth()));
return features;
}
protected Map<String, String> getConfigurations() {
@ -112,6 +123,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
map.put("${user_type}", lr.getUserType());
map.put("${assets_index_name}", version.getAssetsIndex().getId());
map.put("${user_properties}", lr.getUserProperties());
map.put("${resolution_width}", options.getWidth());
map.put("${resolution_height}", options.getHeight());
map.put("${natives_directory}", service.version().getDecompressNativesToLocation(version).getAbsolutePath());
return map;
}

View File

@ -48,6 +48,7 @@ public class Arguments {
}
public static final List<Argument> DEFAULT_JVM_ARGUMENTS;
public static final List<Argument> DEFAULT_GAME_ARGUMENTS;
static {
List<Argument> jvm = new LinkedList<>();
@ -60,5 +61,9 @@ public class Arguments {
jvm.add(new StringArgument("-cp"));
jvm.add(new StringArgument("${classpath}"));
DEFAULT_JVM_ARGUMENTS = Collections.unmodifiableList(jvm);
List<Argument> game = new LinkedList<>();
game.add(new RuledArgument(Collections.singletonList(new Rules("allow", Collections.singletonMap("has_custom_resolution", true))), Arrays.asList("--width", "${resolution_width}", "--height", "${resolution_height}")));
DEFAULT_GAME_ARGUMENTS = Collections.unmodifiableList(game);
}
}

View File

@ -42,6 +42,11 @@ public class Rules {
this.action = action;
this.os = os;
}
public Rules(String action, Map<String, Boolean> features) {
this.action = action;
this.features = features;
}
public String action(Map<String, Boolean> features) {
if (os != null && !os.isCurrentOS()) return null;

View File

@ -29,7 +29,7 @@ import java.util.regex.Pattern;
*/
public class StringArgument implements Argument {
String argument;
public String argument;
public StringArgument(String argument) {
this.argument = argument;