feat: support specifying the MDS to use with a property
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/push/docs Pipeline was successful

This commit is contained in:
Johannes Frohnmeyer 2024-06-29 20:37:17 +02:00
parent 9db150efe6
commit 91c5686fde
Signed by: Johannes
GPG Key ID: E76429612C2929F4

View File

@ -1,9 +1,11 @@
package io.gitlab.jfronny.inceptum.launcher.system.mds;
import io.gitlab.jfronny.commons.throwable.ThrowingBiConsumer;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.system.mds.flow.FlowMds;
import io.gitlab.jfronny.inceptum.launcher.system.mds.noop.NoopMds;
import io.gitlab.jfronny.inceptum.launcher.system.mds.threaded.ThreadedMds;
import io.gitlab.jfronny.inceptum.launcher.util.GameVersionParser;
import java.io.Closeable;
@ -13,9 +15,22 @@ import java.nio.file.Path;
import java.util.Set;
public interface ModsDirScanner extends Closeable {
String MDS_KIND = switch (System.getProperty("inceptum.mds.kind", "flow").toLowerCase()) {
case "flow" -> "flow";
case "threaded" -> "threaded";
case "noop" -> "noop";
case String s -> {
Utils.LOGGER.error("Unknown mds kind: " + s + ", using flow");
yield "flow";
}
};
static ModsDirScanner get(Path modsDir, InstanceMeta meta) throws IOException {
if (Files.exists(modsDir)) return FlowMds.get(modsDir, meta);//ThreadedMds.get(modsDir, meta);
return new NoopMds(GameVersionParser.getGameVersion(meta.gameVersion));
//TODO use a primitive pattern and guard once available
return switch (MDS_KIND) {
case String s when s.equals("flow") && Files.exists(modsDir) -> FlowMds.get(modsDir, meta);
case String s when s.equals("threaded") && Files.exists(modsDir) -> ThreadedMds.get(modsDir, meta);
default -> new NoopMds(GameVersionParser.getGameVersion(meta.gameVersion));
};
}
static void closeAll() {