Respackopts/src/main/java/io/gitlab/jfronny/respackopts/RespackoptsConfig.java

51 lines
2.2 KiB
Java

package io.gitlab.jfronny.respackopts;
import io.gitlab.jfronny.libjf.config.api.v2.ConfigInstance;
import io.gitlab.jfronny.libjf.config.api.v2.JfCustomConfig;
import io.gitlab.jfronny.libjf.config.api.v2.dsl.DSL;
import io.gitlab.jfronny.respackopts.util.MetaCache;
import net.fabricmc.loader.api.FabricLoader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;
public class RespackoptsConfig implements JfCustomConfig {
public static boolean debugCommands = false;
public static boolean debugLogs = false;
public static boolean ioLogs = false;
public static boolean dashloaderCompat = true;
public static boolean packsInitialized = false;
public static ConfigInstance configInstance = null;
@Override
public void register(DSL.Defaulted dsl) {
if (configInstance != null) return;
Path dir = FabricLoader.getInstance().getConfigDir().resolve("respackopts");
try {
Files.createDirectories(dir);
} catch (IOException e) {
// Ignore for now
}
configInstance = dsl.register(builder -> builder
.value("debugCommands", debugCommands, () -> debugCommands, v -> debugCommands = v)
.value("debugLogs", debugLogs, () -> debugLogs, v -> debugLogs = v)
.value("ioLogs", ioLogs, () -> ioLogs, v -> ioLogs = v)
.value("dashloaderCompat", dashloaderCompat, () -> dashloaderCompat, v -> dashloaderCompat = v)
// Not using Respackopts.FALLBACK_CONF_DIR to avoid premature initialization with libjf-unsafe and libjf-config-reflect
.setPath(dir.resolve("_respackopts.conf"))
.referenceConfig(() -> {
if (!packsInitialized) return List.of();
List<ConfigInstance> instances = new LinkedList<>();
MetaCache.forEach((key, state) -> instances.add(DSL.create(state.packId())
.config(cb -> state.configBranch().buildConfig(cb, state.packId(), key.dataLocation()))
));
return instances;
})
);
}
}