Update to 1.19.4 and use Scope.fork instead of mutating a shared scope
This commit is contained in:
parent
9340f981fc
commit
42891f36c4
|
@ -27,7 +27,7 @@ dependencies {
|
||||||
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil:${prop("libjf_version")}") {
|
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil:${prop("libjf_version")}") {
|
||||||
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
||||||
}
|
}
|
||||||
modLocalRuntime("com.terraformersmc:modmenu:5.0.2") {
|
modLocalRuntime("com.terraformersmc:modmenu:6.1.0-rc.1") {
|
||||||
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# https://fabricmc.net/develop/
|
# https://fabricmc.net/develop/
|
||||||
minecraft_version=1.19.3
|
minecraft_version=1.19.4
|
||||||
yarn_mappings=build.5
|
yarn_mappings=build.1
|
||||||
loader_version=0.14.15
|
loader_version=0.14.17
|
||||||
|
|
||||||
maven_group=io.gitlab.jfronny
|
maven_group=io.gitlab.jfronny
|
||||||
archives_base_name=respackopts
|
archives_base_name=respackopts
|
||||||
|
@ -13,6 +13,6 @@ curseforge_id=430090
|
||||||
curseforge_required_dependencies=fabric-api, libjf
|
curseforge_required_dependencies=fabric-api, libjf
|
||||||
curseforge_optional_dependencies=modmenu
|
curseforge_optional_dependencies=modmenu
|
||||||
|
|
||||||
fabric_version=0.75.0+1.19.3
|
fabric_version=0.75.3+1.19.4
|
||||||
libjf_version=3.5.0
|
libjf_version=3.6.0
|
||||||
muscript_version=1.1-SNAPSHOT
|
muscript_version=1.2-SNAPSHOT
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package io.gitlab.jfronny.respackopts.mixin;
|
package io.gitlab.jfronny.respackopts.mixin;
|
||||||
|
|
||||||
import io.gitlab.jfronny.respackopts.RespackoptsClient;
|
import io.gitlab.jfronny.respackopts.RespackoptsClient;
|
||||||
import net.minecraft.client.gl.GLImportProcessor;
|
import net.minecraft.client.gl.GlImportProcessor;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
|
||||||
@Mixin(GLImportProcessor.class)
|
@Mixin(GlImportProcessor.class)
|
||||||
public class GLImportProcessorMixin {
|
public class GlImportProcessorMixin {
|
||||||
private static final String respackopts$prefix = "\n//include " + RespackoptsClient.RPO_SHADER_ID;
|
private static final String respackopts$prefix = "\n//include " + RespackoptsClient.RPO_SHADER_ID;
|
||||||
@ModifyArg(method = "readSource(Ljava/lang/String;)Ljava/util/List;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gl/GLImportProcessor;parseImports(Ljava/lang/String;Lnet/minecraft/client/gl/GLImportProcessor$Context;Ljava/lang/String;)Ljava/util/List;"), index = 0)
|
@ModifyArg(method = "readSource(Ljava/lang/String;)Ljava/util/List;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gl/GlImportProcessor;parseImports(Ljava/lang/String;Lnet/minecraft/client/gl/GlImportProcessor$Context;Ljava/lang/String;)Ljava/util/List;"), index = 0)
|
||||||
private String modify(String value) {
|
private String modify(String value) {
|
||||||
return value.replace(respackopts$prefix, "\n" + RespackoptsClient.getShaderImportSource());
|
return value.replace(respackopts$prefix, "\n" + RespackoptsClient.getShaderImportSource());
|
||||||
}
|
}
|
|
@ -2,7 +2,8 @@ package io.gitlab.jfronny.respackopts.mixin;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import io.gitlab.jfronny.respackopts.util.FallbackI18n;
|
import io.gitlab.jfronny.respackopts.util.FallbackI18n;
|
||||||
import net.minecraft.client.resource.language.*;
|
import net.minecraft.client.resource.language.LanguageManager;
|
||||||
|
import net.minecraft.client.resource.language.TranslationStorage;
|
||||||
import net.minecraft.resource.ResourceManager;
|
import net.minecraft.resource.ResourceManager;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -14,8 +15,8 @@ import java.util.*;
|
||||||
|
|
||||||
@Mixin(LanguageManager.class)
|
@Mixin(LanguageManager.class)
|
||||||
public class LanguageManagerMixin {
|
public class LanguageManagerMixin {
|
||||||
@Inject(method = "reload(Lnet/minecraft/resource/ResourceManager;)V", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILSOFT)
|
@Inject(method = "reload(Lnet/minecraft/resource/ResourceManager;)V", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
|
||||||
private void rpo$appendTranslations(ResourceManager manager, CallbackInfo ci, LanguageDefinition languageDefinition, List<LanguageDefinition> list, TranslationStorage translationStorage) {
|
private void rpo$appendTranslations(ResourceManager manager, CallbackInfo ci, List<String> list, boolean bl, TranslationStorage translationStorage) {
|
||||||
TranslationStorageAccessor storage = (TranslationStorageAccessor) translationStorage;
|
TranslationStorageAccessor storage = (TranslationStorageAccessor) translationStorage;
|
||||||
Map<String, String> map = new HashMap<>(storage.getTranslations());
|
Map<String, String> map = new HashMap<>(storage.getTranslations());
|
||||||
FallbackI18n.insertInto(map);
|
FallbackI18n.insertInto(map);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"package": "io.gitlab.jfronny.respackopts.mixin",
|
"package": "io.gitlab.jfronny.respackopts.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"client": [
|
"client": [
|
||||||
"GLImportProcessorMixin",
|
"GlImportProcessorMixin",
|
||||||
"LanguageManagerMixin",
|
"LanguageManagerMixin",
|
||||||
"OptionsScreenMixin",
|
"OptionsScreenMixin",
|
||||||
"PackScreenMixin",
|
"PackScreenMixin",
|
||||||
|
|
|
@ -4,7 +4,10 @@ import io.gitlab.jfronny.commons.log.Logger;
|
||||||
import io.gitlab.jfronny.gson.Gson;
|
import io.gitlab.jfronny.gson.Gson;
|
||||||
import io.gitlab.jfronny.gson.GsonBuilder;
|
import io.gitlab.jfronny.gson.GsonBuilder;
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.ConfigHolder;
|
import io.gitlab.jfronny.libjf.config.api.v1.ConfigHolder;
|
||||||
|
import io.gitlab.jfronny.muscript.StandardLib;
|
||||||
import io.gitlab.jfronny.muscript.ast.*;
|
import io.gitlab.jfronny.muscript.ast.*;
|
||||||
|
import io.gitlab.jfronny.muscript.data.Scope;
|
||||||
|
import io.gitlab.jfronny.muscript.data.dynamic.additional.DFinal;
|
||||||
import io.gitlab.jfronny.respackopts.filters.DirFilterEvents;
|
import io.gitlab.jfronny.respackopts.filters.DirFilterEvents;
|
||||||
import io.gitlab.jfronny.respackopts.filters.FileFilterEvents;
|
import io.gitlab.jfronny.respackopts.filters.FileFilterEvents;
|
||||||
import io.gitlab.jfronny.respackopts.gson.*;
|
import io.gitlab.jfronny.respackopts.gson.*;
|
||||||
|
@ -16,6 +19,8 @@ import io.gitlab.jfronny.respackopts.server.ServerInstanceHolder;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.fabricmc.loader.api.VersionParsingException;
|
||||||
|
import net.fabricmc.loader.api.metadata.version.VersionPredicate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -38,6 +43,23 @@ public class Respackopts implements ModInitializer, SaveHook {
|
||||||
.setPrettyPrinting()
|
.setPrettyPrinting()
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
|
public static final Scope ROOT_SCOPE = StandardLib.createScope();
|
||||||
|
|
||||||
|
static {
|
||||||
|
ROOT_SCOPE.set("version", args -> {
|
||||||
|
if (args.size() != 2) throw new IllegalArgumentException("Expected 2 arguments on version but got " + args.size());
|
||||||
|
VersionPredicate predicate;
|
||||||
|
try {
|
||||||
|
predicate = VersionPredicate.parse(args.get(1).asString().getValue());
|
||||||
|
} catch (VersionParsingException e) {
|
||||||
|
throw new IllegalArgumentException("Could not parse version predicate", e);
|
||||||
|
}
|
||||||
|
return DFinal.of(FabricLoader.getInstance().getModContainer(args.get(0).asString().getValue())
|
||||||
|
.map(c -> predicate.test(c.getMetadata().getVersion()))
|
||||||
|
.orElse(false));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static final String ID = "respackopts";
|
public static final String ID = "respackopts";
|
||||||
public static final Logger LOGGER = Logger.forName(ID);
|
public static final Logger LOGGER = Logger.forName(ID);
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ public enum DirFilterEvents implements UserResourceEvents.Open, UserResourceEven
|
||||||
if (rpo.condition == null)
|
if (rpo.condition == null)
|
||||||
return false;
|
return false;
|
||||||
try {
|
try {
|
||||||
return !rpo.condition.get(MetaCache.getParameter(key));
|
return !rpo.condition.get(MetaCache.getScope(key));
|
||||||
} catch (Condition.ConditionException e) {
|
} catch (Condition.ConditionException e) {
|
||||||
String res = "Could not evaluate condition " + file + " (pack: " + key.packName() + ")";
|
String res = "Could not evaluate condition " + file + " (pack: " + key.packName() + ")";
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class FileExclusionProvider {
|
||||||
return false;
|
return false;
|
||||||
CacheKey key = MetaCache.getKeyByPack(pack);
|
CacheKey key = MetaCache.getKeyByPack(pack);
|
||||||
try {
|
try {
|
||||||
return !rpo.condition.get(MetaCache.getParameter(key));
|
return !rpo.condition.get(MetaCache.getScope(key));
|
||||||
} catch (Condition.ConditionException e) {
|
} catch (Condition.ConditionException e) {
|
||||||
String res = "Could not evaluate condition " + file + " (pack: " + key.packName() + ")";
|
String res = "Could not evaluate condition " + file + " (pack: " + key.packName() + ")";
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class FileExpansionProvider {
|
||||||
public static InputSupplier<InputStream> replace(InputSupplier<InputStream> inputStream, ResourcePack pack, String file) {
|
public static InputSupplier<InputStream> replace(InputSupplier<InputStream> inputStream, ResourcePack pack, String file) {
|
||||||
return FileRpoSearchProvider.modifyWithRpo(file, pack, rpo -> rpo.expansions == null || rpo.expansions.isEmpty() ? inputStream : () -> {
|
return FileRpoSearchProvider.modifyWithRpo(file, pack, rpo -> rpo.expansions == null || rpo.expansions.isEmpty() ? inputStream : () -> {
|
||||||
try (InputStream is = inputStream.get()) {
|
try (InputStream is = inputStream.get()) {
|
||||||
return replace(MetaCache.getParameter(MetaCache.getKeyByPack(pack)), is, rpo.expansions);
|
return replace(MetaCache.getScope(MetaCache.getKeyByPack(pack)), is, rpo.expansions);
|
||||||
}
|
}
|
||||||
}, inputStream);
|
}, inputStream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package io.gitlab.jfronny.respackopts.model;
|
package io.gitlab.jfronny.respackopts.model;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.serialize.gson.api.Ignore;
|
import io.gitlab.jfronny.commons.serialize.gson.api.v1.Ignore;
|
||||||
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public class DirRpo {
|
public class DirRpo {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package io.gitlab.jfronny.respackopts.model;
|
package io.gitlab.jfronny.respackopts.model;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.serialize.gson.api.Ignore;
|
import io.gitlab.jfronny.commons.serialize.gson.api.v1.Ignore;
|
||||||
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
||||||
import io.gitlab.jfronny.muscript.ast.StringExpr;
|
import io.gitlab.jfronny.muscript.ast.StringExpr;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.gitlab.jfronny.respackopts.model.cache;
|
package io.gitlab.jfronny.respackopts.model.cache;
|
||||||
|
|
||||||
import io.gitlab.jfronny.muscript.data.Scope;
|
import io.gitlab.jfronny.muscript.data.Scope;
|
||||||
|
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||||
import io.gitlab.jfronny.respackopts.model.*;
|
import io.gitlab.jfronny.respackopts.model.*;
|
||||||
import io.gitlab.jfronny.respackopts.model.tree.ConfigBranch;
|
import io.gitlab.jfronny.respackopts.model.tree.ConfigBranch;
|
||||||
|
|
||||||
|
@ -18,13 +19,15 @@ public record CachedPackState(
|
||||||
Scope executionScope
|
Scope executionScope
|
||||||
) {
|
) {
|
||||||
public CachedPackState(CacheKey key, PackMeta meta, ConfigBranch branch) {
|
public CachedPackState(CacheKey key, PackMeta meta, ConfigBranch branch) {
|
||||||
this(meta.id,
|
this(
|
||||||
|
meta.id,
|
||||||
key.displayName(),
|
key.displayName(),
|
||||||
key.packName(),
|
key.packName(),
|
||||||
branch,
|
branch,
|
||||||
meta,
|
meta,
|
||||||
new HashMap<>(),
|
new HashMap<>(),
|
||||||
new HashMap<>(),
|
new HashMap<>(),
|
||||||
new Scope(branch.getDynamic()));
|
branch.addTo(Respackopts.ROOT_SCOPE.fork())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.dsl.CategoryBuilder;
|
import io.gitlab.jfronny.libjf.config.api.v1.dsl.CategoryBuilder;
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.dsl.ConfigBuilder;
|
import io.gitlab.jfronny.libjf.config.api.v1.dsl.ConfigBuilder;
|
||||||
|
import io.gitlab.jfronny.muscript.data.Scope;
|
||||||
import io.gitlab.jfronny.muscript.data.dynamic.*;
|
import io.gitlab.jfronny.muscript.data.dynamic.*;
|
||||||
|
import io.gitlab.jfronny.muscript.data.dynamic.additional.DFinal;
|
||||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||||
import io.gitlab.jfronny.respackopts.RespackoptsConfig;
|
import io.gitlab.jfronny.respackopts.RespackoptsConfig;
|
||||||
import io.gitlab.jfronny.respackopts.integration.SaveHook;
|
import io.gitlab.jfronny.respackopts.integration.SaveHook;
|
||||||
|
@ -26,8 +28,9 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
||||||
public void sync(ConfigEntry<Map<String, ConfigEntry<?>>> source, ConfigSyncMode mode) {
|
public void sync(ConfigEntry<Map<String, ConfigEntry<?>>> source, ConfigSyncMode mode) {
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : source.getValue().entrySet()) {
|
for (Map.Entry<String, ConfigEntry<?>> e : source.getValue().entrySet()) {
|
||||||
if (!has(e.getKey())) {
|
if (!has(e.getKey())) {
|
||||||
if (mode == ConfigSyncMode.RESPACK_LOAD)
|
if (mode == ConfigSyncMode.RESPACK_LOAD) {
|
||||||
add(e.getKey(), e.getValue().clone());
|
add(e.getKey(), e.getValue().clone());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ConfigEntry<?> current = get(e.getKey());
|
ConfigEntry<?> current = get(e.getKey());
|
||||||
if (e.getValue().getEntryClass().equals(current.getEntryClass())) {
|
if (e.getValue().getEntryClass().equals(current.getEntryClass())) {
|
||||||
|
@ -42,10 +45,12 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mode == ConfigSyncMode.RESPACK_LOAD)
|
if (mode == ConfigSyncMode.RESPACK_LOAD) {
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
|
getValue().forEach((key, value) -> {
|
||||||
if (!source.getValue().containsKey(e.getKey()))
|
if (!source.getValue().containsKey(key)) {
|
||||||
super.getValue().remove(e.getKey());
|
super.getValue().remove(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +70,10 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
||||||
|
|
||||||
public String getEntryName(ConfigEntry<?> entry) {
|
public String getEntryName(ConfigEntry<?> entry) {
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
|
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
|
||||||
if (e.getValue() == entry)
|
if (e.getValue() == entry) {
|
||||||
return e.getKey();
|
return e.getKey();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,26 +88,33 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildShader(StringBuilder sb, String valueName) {
|
public void buildShader(StringBuilder sb, String valueName) {
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : super.getValue().entrySet()) {
|
super.getValue().forEach((key, value) -> {
|
||||||
e.getValue().buildShader(sb, valueName + "_" + Respackopts.sanitizeString(e.getKey()));
|
value.buildShader(sb, valueName + "_" + Respackopts.sanitizeString(key));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DObject getDynamic() {
|
public DObject getDynamic() {
|
||||||
Map<String, Dynamic<?>> map = new HashMap<>();
|
Map<String, Dynamic<?>> map = new HashMap<>();
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : super.getValue().entrySet()) {
|
super.getValue().forEach((key, value) -> {
|
||||||
map.put(Respackopts.sanitizeString(e.getKey()), e.getValue().getDynamic());
|
map.put(Respackopts.sanitizeString(key), value.getDynamic());
|
||||||
}
|
});
|
||||||
return DFinal.of(map);
|
return DFinal.of(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Scope addTo(Scope scope) {
|
||||||
|
super.getValue().forEach((key, value) -> {
|
||||||
|
scope.set(Respackopts.sanitizeString(key), value.getDynamic());
|
||||||
|
});
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CategoryBuilder<?> buildEntry(GuiEntryBuilderParam builder) {
|
public CategoryBuilder<?> buildEntry(GuiEntryBuilderParam builder) {
|
||||||
return builder.builder().category(builder.name(), cb -> {
|
return builder.builder().category(builder.name(), cb -> {
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
|
getValue().forEach((key, value) -> {
|
||||||
e.getValue().buildEntry(new GuiEntryBuilderParam(cb, e.getKey(), builder.onSave()));
|
value.buildEntry(new GuiEntryBuilderParam(cb, key, builder.onSave()));
|
||||||
}
|
});
|
||||||
return cb;
|
return cb;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -109,13 +122,15 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
||||||
public <T extends ConfigBuilder<?>> T buildConfig(T builder, String packId, Path dataLocation) {
|
public <T extends ConfigBuilder<?>> T buildConfig(T builder, String packId, Path dataLocation) {
|
||||||
builder.setTranslationPrefix("rpo." + packId + ".");
|
builder.setTranslationPrefix("rpo." + packId + ".");
|
||||||
PackReloadType.Aggregator agg = new PackReloadType.Aggregator();
|
PackReloadType.Aggregator agg = new PackReloadType.Aggregator();
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
|
getValue().forEach((key, value) -> {
|
||||||
e.getValue().buildEntry(
|
value.buildEntry(
|
||||||
new GuiEntryBuilderParam(builder,
|
new GuiEntryBuilderParam(
|
||||||
e.getKey(),
|
builder,
|
||||||
() -> agg.accept(e.getValue().getReloadType()))
|
key,
|
||||||
|
() -> agg.accept(value.getReloadType())
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
builder.executeAfterWrite(cfg -> {
|
builder.executeAfterWrite(cfg -> {
|
||||||
if (RespackoptsConfig.debugLogs) Respackopts.LOGGER.info("GuiFactory SavingRunnable " + agg.get());
|
if (RespackoptsConfig.debugLogs) Respackopts.LOGGER.info("GuiFactory SavingRunnable " + agg.get());
|
||||||
MetaCache.save(new SaveHook.Arguments(agg.get() == PackReloadType.Resource, false, true));
|
MetaCache.save(new SaveHook.Arguments(agg.get() == PackReloadType.Resource, false, true));
|
||||||
|
@ -127,20 +142,20 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
||||||
@Override
|
@Override
|
||||||
public void appendString(IndentingStringBuilder sb) {
|
public void appendString(IndentingStringBuilder sb) {
|
||||||
IndentingStringBuilder ind = sb.indent();
|
IndentingStringBuilder ind = sb.indent();
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
|
getValue().forEach((key, value) -> {
|
||||||
ind.line("- " + e.getValue().getName() + ":");
|
ind.line("- " + value.getName() + ":");
|
||||||
e.getValue().appendString(ind);
|
value.appendString(ind);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigBranch clone() {
|
public ConfigBranch clone() {
|
||||||
ConfigBranch branch = new ConfigBranch();
|
ConfigBranch branch = new ConfigBranch();
|
||||||
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
|
getValue().forEach((key, value) -> {
|
||||||
ConfigEntry<?> entry = e.getValue().clone();
|
ConfigEntry<?> entry = value.clone();
|
||||||
entry.setReloadType(e.getValue().getReloadType());
|
entry.setReloadType(value.getReloadType());
|
||||||
branch.add(e.getKey(), entry);
|
branch.add(key, entry);
|
||||||
}
|
});
|
||||||
branch.setVersion(getVersion());
|
branch.setVersion(getVersion());
|
||||||
return branch;
|
return branch;
|
||||||
}
|
}
|
||||||
|
@ -169,10 +184,10 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
List<Object> source = new ArrayList<>();
|
List<Object> source = new ArrayList<>();
|
||||||
for (Map.Entry<String, ConfigEntry<?>> entry : getValue().entrySet()) {
|
getValue().forEach((key, value) -> {
|
||||||
source.add(entry.getKey());
|
source.add(key);
|
||||||
source.add(entry.getValue());
|
source.add(value);
|
||||||
}
|
});
|
||||||
source.add(super.hashCode());
|
source.add(super.hashCode());
|
||||||
return Objects.hash(source.toArray());
|
return Objects.hash(source.toArray());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package io.gitlab.jfronny.respackopts.model.tree;
|
package io.gitlab.jfronny.respackopts.model.tree;
|
||||||
|
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.dsl.CategoryBuilder;
|
import io.gitlab.jfronny.libjf.config.api.v1.dsl.CategoryBuilder;
|
||||||
import io.gitlab.jfronny.muscript.data.dynamic.DEnum;
|
import io.gitlab.jfronny.muscript.data.dynamic.additional.DEnum;
|
||||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||||
import io.gitlab.jfronny.respackopts.RespackoptsConfig;
|
import io.gitlab.jfronny.respackopts.RespackoptsConfig;
|
||||||
import io.gitlab.jfronny.respackopts.model.enums.ConfigSyncMode;
|
import io.gitlab.jfronny.respackopts.model.enums.ConfigSyncMode;
|
||||||
|
@ -10,7 +10,7 @@ import io.gitlab.jfronny.respackopts.util.IndentingStringBuilder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ConfigEnumEntry extends ConfigEntry<String> {
|
public class ConfigEnumEntry extends ConfigEntry<String> {
|
||||||
public List<String> values = new ArrayList<>();
|
public final List<String> values = new ArrayList<>();
|
||||||
private Integer nextValue;
|
private Integer nextValue;
|
||||||
|
|
||||||
public ConfigEnumEntry() {
|
public ConfigEnumEntry() {
|
||||||
|
@ -40,9 +40,7 @@ public class ConfigEnumEntry extends ConfigEntry<String> {
|
||||||
public String getDefault() {
|
public String getDefault() {
|
||||||
String v = super.getDefault();
|
String v = super.getDefault();
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
if (values.size() == 0)
|
if (values.isEmpty()) throw new NullPointerException("Could not get default entry as the entry array is empty in " + getName());
|
||||||
throw new NullPointerException("Could not get default entry as the entry array is empty in " + getName());
|
|
||||||
else
|
|
||||||
v = values.get(0);
|
v = values.get(0);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
@ -52,9 +50,9 @@ public class ConfigEnumEntry extends ConfigEntry<String> {
|
||||||
public void sync(ConfigEntry<String> source, ConfigSyncMode mode) {
|
public void sync(ConfigEntry<String> source, ConfigSyncMode mode) {
|
||||||
super.sync(source, mode);
|
super.sync(source, mode);
|
||||||
ConfigEnumEntry n = (ConfigEnumEntry) source;
|
ConfigEnumEntry n = (ConfigEnumEntry) source;
|
||||||
if (mode == ConfigSyncMode.RESPACK_LOAD) {
|
if (mode == ConfigSyncMode.RESPACK_LOAD && !n.values.isEmpty()) {
|
||||||
if (n.values != null && !n.values.isEmpty())
|
values.clear();
|
||||||
values = n.values;
|
values.addAll(n.values);
|
||||||
}
|
}
|
||||||
if (getValue() == null && nextValue != null) {
|
if (getValue() == null && nextValue != null) {
|
||||||
if (n.nextValue >= 0 && n.nextValue < values.size()) {
|
if (n.nextValue >= 0 && n.nextValue < values.size()) {
|
||||||
|
@ -79,7 +77,7 @@ public class ConfigEnumEntry extends ConfigEntry<String> {
|
||||||
public ConfigEntry<String> clone() {
|
public ConfigEntry<String> clone() {
|
||||||
ConfigEnumEntry e = new ConfigEnumEntry();
|
ConfigEnumEntry e = new ConfigEnumEntry();
|
||||||
e.nextValue = nextValue;
|
e.nextValue = nextValue;
|
||||||
e.values = List.copyOf(values);
|
e.values.addAll(values);
|
||||||
e.setValue(getValue());
|
e.setValue(getValue());
|
||||||
e.setDefault(getDefault());
|
e.setDefault(getDefault());
|
||||||
return e;
|
return e;
|
||||||
|
|
|
@ -150,14 +150,15 @@ public class MetaCache {
|
||||||
return PACK_STATES.get(key);
|
return PACK_STATES.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scope getParameter(@Nullable CacheKey key) {
|
public static Scope getScope(@Nullable CacheKey key) {
|
||||||
Scope parameter = key == null ? new Scope() : MetaCache.getState(key).executionScope();
|
Scope scope = (key == null ? Respackopts.ROOT_SCOPE : MetaCache.getState(key).executionScope()).fork();
|
||||||
MetaCache.forEach((id, state) -> {
|
MetaCache.forEach((id, state) -> {
|
||||||
String packId = Respackopts.sanitizeString(state.packId());
|
String packId = Respackopts.sanitizeString(state.packId());
|
||||||
if (!parameter.has(packId))
|
if (!scope.has(packId)) {
|
||||||
parameter.set(packId, state.configBranch().getDynamic());
|
scope.set(packId, state.configBranch().getDynamic());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return MuUtils.addDefault(parameter);
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasCapability(ResourcePack pack, PackCapability capability) {
|
public static boolean hasCapability(ResourcePack pack, PackCapability capability) {
|
||||||
|
|
|
@ -1,108 +0,0 @@
|
||||||
package io.gitlab.jfronny.respackopts.util;
|
|
||||||
|
|
||||||
import io.gitlab.jfronny.muscript.StandardLib;
|
|
||||||
import io.gitlab.jfronny.muscript.data.Scope;
|
|
||||||
import io.gitlab.jfronny.muscript.data.dynamic.*;
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.fabricmc.loader.api.VersionParsingException;
|
|
||||||
import net.fabricmc.loader.api.metadata.version.VersionPredicate;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class MuUtils {
|
|
||||||
public static Scope addDefault(Scope parameter) {
|
|
||||||
StandardLib.addTo(parameter);
|
|
||||||
parameter.set("version", args -> {
|
|
||||||
if (args.size() != 2) throw new IllegalArgumentException("Expected 2 arguments on version but got " + args.size());
|
|
||||||
VersionPredicate predicate;
|
|
||||||
try {
|
|
||||||
predicate = VersionPredicate.parse(args.get(1).asString().getValue());
|
|
||||||
} catch (VersionParsingException e) {
|
|
||||||
throw new RuntimeException("Could not parse version predicate", e);
|
|
||||||
}
|
|
||||||
return DFinal.of(FabricLoader.getInstance().getModContainer(args.get(0).asString().getValue())
|
|
||||||
.map(c -> predicate.test(c.getMetadata().getVersion()))
|
|
||||||
.orElse(false));
|
|
||||||
});
|
|
||||||
parameter.set("date", new DCallableObject(Map.of(
|
|
||||||
"today", new DDate(LocalDate::now)
|
|
||||||
), DFinal.of(args -> {
|
|
||||||
// Constructor
|
|
||||||
if (args.size() == 1) return new DDate(() -> LocalDate.ofEpochDay(args.get(0).asNumber().getValue().longValue()));
|
|
||||||
if (args.size() != 3) throw new IllegalArgumentException("Expected 3 arguments for full date constructor");
|
|
||||||
int a0 = args.get(0).asNumber().getValue().intValue();
|
|
||||||
int a1 = args.get(1).asNumber().getValue().intValue();
|
|
||||||
int a2 = args.get(2).asNumber().getValue().intValue();
|
|
||||||
return new DDate(() -> LocalDate.of(a0, a1, a2));
|
|
||||||
})));
|
|
||||||
parameter.set("time", new DCallableObject(Map.of(
|
|
||||||
"now", new DTime(LocalTime::now)
|
|
||||||
), DFinal.of(args -> {
|
|
||||||
// Constructor
|
|
||||||
if (args.size() == 1) return new DTime(() -> LocalTime.ofSecondOfDay(args.get(0).asNumber().getValue().intValue()));
|
|
||||||
if (args.size() != 3) throw new IllegalArgumentException("Expected 3 arguments for full time constructor");
|
|
||||||
int a0 = args.get(0).asNumber().getValue().intValue();
|
|
||||||
int a1 = args.get(1).asNumber().getValue().intValue();
|
|
||||||
int a2 = args.get(2).asNumber().getValue().intValue();
|
|
||||||
return new DTime(() -> LocalTime.of(a0, a1, a2));
|
|
||||||
})));
|
|
||||||
return parameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
private record DCallableObject(Map<String, Dynamic<?>> value, DCallable callable) implements DObject {
|
|
||||||
@Override
|
|
||||||
public Map<String, Dynamic<?>> getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DCallable asCallable() {
|
|
||||||
return callable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private record DDate(Supplier<LocalDate> date) implements DObject {
|
|
||||||
@Override
|
|
||||||
public Map<String, Dynamic<?>> getValue() {
|
|
||||||
return Map.of(
|
|
||||||
"year", DFinal.of(date.get().getYear()),
|
|
||||||
"month", DFinal.of(date.get().getMonthValue()),
|
|
||||||
"day", DFinal.of(date.get().getDayOfMonth())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DString asString() {
|
|
||||||
return DFinal.of(date.get().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DNumber asNumber() {
|
|
||||||
return DFinal.of(date.get().toEpochDay());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private record DTime(Supplier<LocalTime> time) implements DObject {
|
|
||||||
@Override
|
|
||||||
public Map<String, Dynamic<?>> getValue() {
|
|
||||||
return Map.of(
|
|
||||||
"hour", DFinal.of(time.get().getHour()),
|
|
||||||
"minute", DFinal.of(time.get().getMinute()),
|
|
||||||
"second", DFinal.of(time.get().getSecond())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DString asString() {
|
|
||||||
return DFinal.of(time.get().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DNumber asNumber() {
|
|
||||||
return DFinal.of(time.get().toSecondOfDay());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user