InstanceMeta.checkArguments to centralize null checking + remove mutability from Arguments and kotlin lambda indy
This commit is contained in:
parent
3d73879bed
commit
218e12714d
|
@ -10,6 +10,7 @@ import io.gitlab.jfronny.inceptum.launcher.system.setup.Steps;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class LaunchCommand extends BaseInstanceCommand {
|
||||
private final boolean server;
|
||||
|
@ -47,14 +48,10 @@ public class LaunchCommand extends BaseInstanceCommand {
|
|||
}
|
||||
if (args.length > 1) {
|
||||
InstanceMeta meta = instance.meta();
|
||||
if (meta.arguments == null) meta.arguments = new InstanceMeta.Arguments(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
|
||||
else meta.arguments = new InstanceMeta.Arguments(
|
||||
meta.arguments.jvm() == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.jvm()),
|
||||
meta.arguments.client() == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.client()),
|
||||
meta.arguments.server() == null ? new ArrayList<>() : new ArrayList<>(meta.arguments.server())
|
||||
);
|
||||
meta.arguments.client().addAll(args.after(0));
|
||||
meta.arguments.server().addAll(args.after(0));
|
||||
meta.checkArguments();
|
||||
meta.arguments = meta.arguments
|
||||
.withClient(Stream.concat(meta.arguments.client().stream(), args.after(0).stream()).toList())
|
||||
.withServer(Stream.concat(meta.arguments.server().stream(), args.after(0).stream()).toList());
|
||||
}
|
||||
Steps.reDownload(instance, Steps.createProcessState());
|
||||
if (server) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id("inceptum.application")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
|
@ -48,3 +50,14 @@ tasks.runShadow {
|
|||
environment("GTK_DEBUG", "interactive") // interactive:actions
|
||||
jvmArgs("--enable-preview", "--enable-native-access=ALL-UNNAMED")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets.all {
|
||||
languageSettings {
|
||||
languageVersion = "2.0"
|
||||
progressiveMode = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(KotlinCompile::class) { compilerOptions.freeCompilerArgs.addAll("-Xlambdas=indy") }
|
|
@ -185,10 +185,7 @@ class GeneralTab(instance: Instance, window: InstanceSettingsWindow) : SettingsT
|
|||
}
|
||||
}
|
||||
section("instance.settings.general.args") {
|
||||
if (instance.meta.arguments == null) instance.meta.arguments = InstanceMeta.Arguments(listOf(), listOf(), listOf())
|
||||
if (instance.meta.arguments.jvm == null) instance.meta.arguments = instance.meta.arguments.withJvm(listOf())
|
||||
if (instance.meta.arguments.client == null) instance.meta.arguments = instance.meta.arguments.withClient(listOf())
|
||||
if (instance.meta.arguments.server == null) instance.meta.arguments = instance.meta.arguments.withServer(listOf())
|
||||
instance.meta.checkArguments()
|
||||
row("instance.settings.general.args.jvm", "instance.settings.general.args.jvm.subtitle") {
|
||||
setEntry(ArgumentsTokenizer.join(instance.meta.arguments.jvm.toTypedArray())) {
|
||||
instance.meta.arguments = instance.meta.arguments.withJvm(listOf(*ArgumentsTokenizer.tokenize(it)))
|
||||
|
|
|
@ -7,7 +7,6 @@ import io.gitlab.jfronny.inceptum.imgui.control.Tab;
|
|||
import io.gitlab.jfronny.inceptum.imgui.window.GuiUtil;
|
||||
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ArgumentsTab extends Tab {
|
||||
|
@ -20,12 +19,9 @@ public class ArgumentsTab extends Tab {
|
|||
super("Arguments");
|
||||
this.window = window;
|
||||
InstanceMeta meta = window.instance.meta();
|
||||
if (meta.arguments == null) meta.arguments = new InstanceMeta.Arguments(new LinkedList<>(), new LinkedList<>(), new LinkedList<>());
|
||||
if (meta.arguments.jvm() == null) meta.arguments = meta.arguments.withJvm(new LinkedList<>());
|
||||
meta.checkArguments();
|
||||
jvm.set(String.join("\n", meta.arguments.jvm()));
|
||||
if (meta.arguments.client() == null) meta.arguments = meta.arguments.withClient(new LinkedList<>());
|
||||
client.set(String.join("\n", meta.arguments.client()));
|
||||
if (meta.arguments.server() == null) meta.arguments = meta.arguments.withServer(new LinkedList<>());
|
||||
server.set(String.join("\n", meta.arguments.server()));
|
||||
}
|
||||
|
||||
|
|
|
@ -38,8 +38,22 @@ public class InstanceMeta {
|
|||
return Objects.hash(gameVersion, java, minMem, maxMem, lastLaunched, arguments);
|
||||
}
|
||||
|
||||
public void checkArguments() {
|
||||
arguments = arguments == null ? Arguments.EMPTY : arguments.checked();
|
||||
}
|
||||
|
||||
@GSerializable(configure = GsonPreset.Config.class)
|
||||
public record Arguments(List<String> jvm, List<String> client, List<String> server) {
|
||||
public static final Arguments EMPTY = new Arguments(List.of(), List.of(), List.of());
|
||||
|
||||
public Arguments checked() {
|
||||
return new Arguments(
|
||||
jvm == null ? List.of() : jvm,
|
||||
client == null ? List.of() : client,
|
||||
server == null ? List.of() : server
|
||||
);
|
||||
}
|
||||
|
||||
public Arguments withJvm(List<String> jvm) {
|
||||
return new Arguments(jvm, client, server);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue