2022-08-28 20:06:59 +02:00
|
|
|
package io.gitlab.jfronny.respackopts;
|
|
|
|
|
2023-09-22 19:19:55 +02:00
|
|
|
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;
|
2022-08-28 20:06:59 +02:00
|
|
|
import io.gitlab.jfronny.respackopts.util.MetaCache;
|
2023-09-02 22:27:23 +02:00
|
|
|
import net.fabricmc.loader.api.FabricLoader;
|
2022-08-28 20:06:59 +02:00
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class RespackoptsConfig implements JfCustomConfig {
|
|
|
|
public static boolean debugCommands = false;
|
|
|
|
public static boolean debugLogs = false;
|
2023-08-14 17:27:32 +02:00
|
|
|
public static boolean ioLogs = false;
|
2022-08-28 20:06:59 +02:00
|
|
|
public static boolean dashloaderCompat = true;
|
|
|
|
|
2023-09-02 22:27:23 +02:00
|
|
|
public static boolean packsInitialized = false;
|
|
|
|
public static ConfigInstance configInstance = null;
|
|
|
|
|
2022-08-28 20:06:59 +02:00
|
|
|
@Override
|
|
|
|
public void register(DSL.Defaulted dsl) {
|
2023-09-02 22:27:23 +02:00
|
|
|
if (configInstance != null) return;
|
|
|
|
configInstance = dsl.register(builder -> builder
|
2022-08-28 20:06:59 +02:00
|
|
|
.value("debugCommands", debugCommands, () -> debugCommands, v -> debugCommands = v)
|
|
|
|
.value("debugLogs", debugLogs, () -> debugLogs, v -> debugLogs = v)
|
2023-08-14 17:27:32 +02:00
|
|
|
.value("ioLogs", ioLogs, () -> ioLogs, v -> ioLogs = v)
|
2022-08-28 20:06:59 +02:00
|
|
|
.value("dashloaderCompat", dashloaderCompat, () -> dashloaderCompat, v -> dashloaderCompat = v)
|
2023-09-02 22:27:23 +02:00
|
|
|
// Not using Respackopts.FALLBACK_CONF_DIR to avoid premature initialization with libjf-unsafe and libjf-config-reflect
|
|
|
|
.setPath(FabricLoader.getInstance().getConfigDir().resolve("respackopts").resolve("_respackopts.conf"))
|
2022-08-28 20:06:59 +02:00
|
|
|
.referenceConfig(() -> {
|
2023-09-02 22:27:23 +02:00
|
|
|
if (!packsInitialized) return List.of();
|
2022-08-28 20:06:59 +02:00
|
|
|
List<ConfigInstance> instances = new LinkedList<>();
|
|
|
|
MetaCache.forEach((key, state) -> instances.add(DSL.create(state.packId())
|
2022-08-28 20:52:27 +02:00
|
|
|
.config(cb -> state.configBranch().buildConfig(cb, state.packId(), key.dataLocation()))
|
2022-08-28 20:06:59 +02:00
|
|
|
));
|
|
|
|
return instances;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|