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."); 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(); String serverIp = options.getServerIp();
if (StrUtils.isNotBlank(serverIp)) { if (StrUtils.isNotBlank(serverIp)) {
String[] args = serverIp.split(":"); 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.api.auth.UserProfileProvider;
import org.jackhuang.hmcl.core.version.MinecraftLibrary; import org.jackhuang.hmcl.core.version.MinecraftLibrary;
import org.jackhuang.hmcl.core.service.IMinecraftService; import org.jackhuang.hmcl.core.service.IMinecraftService;
import org.jackhuang.hmcl.core.version.Argument;
import org.jackhuang.hmcl.core.version.Arguments; import org.jackhuang.hmcl.core.version.Arguments;
/** /**
@ -46,8 +47,18 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
if (version.arguments == null) if (version.arguments == null)
version.arguments = new Arguments(); version.arguments = new Arguments();
if (version.arguments.game == null)
version.arguments.game = getDefaultGameArguments();
if (version.arguments.jvm == null) 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 @Override
@ -86,16 +97,16 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
res.addAll(Arguments.parseArguments(version.arguments.jvm, configuration)); res.addAll(Arguments.parseArguments(version.arguments.jvm, configuration));
res.add(version.mainClass); 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)); res.addAll(Arguments.parseStringArguments(Arrays.asList(StrUtils.tokenize(version.minecraftArguments)), configuration));
}
if (res.indexOf("--gameDir") != -1 && res.indexOf("--workDir") != -1) { protected Map<String, Boolean> getFeatures() {
res.add("--workDir"); Map<String, Boolean> features = new HashMap<>();
res.add(gameDir.getAbsolutePath()); features.put("has_custom_resolution", StrUtils.isNotBlank(options.getHeight()) && StrUtils.isNotBlank(options.getWidth()));
} return features;
} }
protected Map<String, String> getConfigurations() { protected Map<String, String> getConfigurations() {
@ -112,6 +123,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
map.put("${user_type}", lr.getUserType()); map.put("${user_type}", lr.getUserType());
map.put("${assets_index_name}", version.getAssetsIndex().getId()); map.put("${assets_index_name}", version.getAssetsIndex().getId());
map.put("${user_properties}", lr.getUserProperties()); 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()); map.put("${natives_directory}", service.version().getDecompressNativesToLocation(version).getAbsolutePath());
return map; 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_JVM_ARGUMENTS;
public static final List<Argument> DEFAULT_GAME_ARGUMENTS;
static { static {
List<Argument> jvm = new LinkedList<>(); List<Argument> jvm = new LinkedList<>();
@ -60,5 +61,9 @@ public class Arguments {
jvm.add(new StringArgument("-cp")); jvm.add(new StringArgument("-cp"));
jvm.add(new StringArgument("${classpath}")); jvm.add(new StringArgument("${classpath}"));
DEFAULT_JVM_ARGUMENTS = Collections.unmodifiableList(jvm); 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

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

View File

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