Hopefully enhance condition debugging experience
This commit is contained in:
parent
ec3587977d
commit
758c2eff68
|
@ -1,16 +1,16 @@
|
|||
# https://fabricmc.net/develop/
|
||||
minecraft_version=1.19
|
||||
yarn_mappings=build.1
|
||||
loader_version=0.14.6
|
||||
yarn_mappings=build.2
|
||||
loader_version=0.14.7
|
||||
maven_group=io.gitlab.jfronny
|
||||
archives_base_name=respackopts
|
||||
fabric_version=0.55.1+1.19
|
||||
fabric_version=0.55.3+1.19
|
||||
jfapi_version=2.9.1
|
||||
muscript_version=2022.6.7+17-43-1
|
||||
muscript_version=2022.6.13+11-33-14
|
||||
|
||||
modrinth_id=TiF5QWZY
|
||||
modrinth_required_dependencies=P7dR8mSH, 9s6osm5g, WKwQAwke
|
||||
modrinth_optional_dependencies=mOgUt4GM
|
||||
modrinth_id=respackopts
|
||||
modrinth_required_dependencies=fabric-api, cloth-config, libjf
|
||||
modrinth_optional_dependencies=modmenu
|
||||
curseforge_id=430090
|
||||
curseforge_required_dependencies=fabric-api, cloth-config, libjf
|
||||
curseforge_optional_dependencies=modmenu
|
||||
|
|
|
@ -48,6 +48,7 @@ public class Respackopts implements ClientModInitializer {
|
|||
.registerTypeAdapter(Expr.class, new ExprDeserializer())
|
||||
.registerTypeAdapter(StringExpr.class, new StringExprDeserializer())
|
||||
.registerTypeAdapter(BoolExpr.class, new BoolExprDeserializer())
|
||||
.registerTypeAdapter(Condition.class, new ConditionDeserializer())
|
||||
.setLenient()
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
package io.gitlab.jfronny.respackopts.filters;
|
||||
|
||||
import io.gitlab.jfronny.libjf.ResourcePath;
|
||||
import io.gitlab.jfronny.libjf.data.manipulation.api.UserResourceEvents;
|
||||
import io.gitlab.jfronny.libjf.*;
|
||||
import io.gitlab.jfronny.libjf.data.manipulation.api.*;
|
||||
import io.gitlab.jfronny.muscript.debug.*;
|
||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||
import io.gitlab.jfronny.respackopts.*;
|
||||
import io.gitlab.jfronny.respackopts.gson.*;
|
||||
import io.gitlab.jfronny.respackopts.model.DirRpo;
|
||||
import io.gitlab.jfronny.respackopts.model.*;
|
||||
import io.gitlab.jfronny.respackopts.model.cache.*;
|
||||
import io.gitlab.jfronny.respackopts.model.enums.PackCapability;
|
||||
import io.gitlab.jfronny.respackopts.util.MetaCache;
|
||||
import io.gitlab.jfronny.respackopts.util.RpoFormatException;
|
||||
import net.minecraft.resource.ResourcePack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import io.gitlab.jfronny.respackopts.model.enums.*;
|
||||
import io.gitlab.jfronny.respackopts.util.*;
|
||||
import net.minecraft.resource.*;
|
||||
import net.minecraft.util.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class DirFilterEventImpl {
|
||||
public static void init() {
|
||||
|
@ -94,11 +91,12 @@ public class DirFilterEventImpl {
|
|||
return false;
|
||||
try {
|
||||
return !rpo.condition.get(MetaCache.getParameter(key));
|
||||
} catch (RuntimeException e) {
|
||||
} catch (Condition.ConditionException e) {
|
||||
String res = "Could not evaluate condition " + file + " (pack: " + key.packName() + ")";
|
||||
try {
|
||||
Respackopts.LOGGER.error("Could not evaluate condition " + file + " (pack: " + key.packName() + ") with condition:\n" + ObjectGraphPrinter.printGraph(rpo.condition) + ")", e);
|
||||
} catch (IllegalAccessException ex) {
|
||||
Respackopts.LOGGER.error("Could not evaluate condition " + file + " (pack: " + key.packName() + ")", e);
|
||||
Respackopts.LOGGER.error(res + " with condition:\n" + ObjectGraphPrinter.printGraph(rpo.condition) + ")", e);
|
||||
} catch (Throwable ex) {
|
||||
Respackopts.LOGGER.error(res, e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package io.gitlab.jfronny.respackopts.filters.util;
|
||||
|
||||
import io.gitlab.jfronny.muscript.debug.*;
|
||||
import io.gitlab.jfronny.respackopts.*;
|
||||
import io.gitlab.jfronny.respackopts.model.*;
|
||||
import io.gitlab.jfronny.respackopts.model.cache.*;
|
||||
import io.gitlab.jfronny.respackopts.util.MetaCache;
|
||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||
import io.gitlab.jfronny.respackopts.util.RpoFormatException;
|
||||
import net.minecraft.resource.ResourcePack;
|
||||
import io.gitlab.jfronny.respackopts.util.*;
|
||||
import net.minecraft.resource.*;
|
||||
|
||||
public class FileExclusionProvider {
|
||||
public static boolean fileHidden(ResourcePack pack, String file) {
|
||||
|
@ -15,11 +15,12 @@ public class FileExclusionProvider {
|
|||
CacheKey key = MetaCache.getKeyByPack(pack);
|
||||
try {
|
||||
return !rpo.condition.get(MetaCache.getParameter(key));
|
||||
} catch (RuntimeException e) {
|
||||
} catch (Condition.ConditionException e) {
|
||||
String res = "Could not evaluate condition " + file + " (pack: " + key.packName() + ")";
|
||||
try {
|
||||
Respackopts.LOGGER.error("Could not evaluate condition " + file + " (pack: " + key.packName() + ") with condition:\n" + ObjectGraphPrinter.printGraph(rpo.condition) + ")", e);
|
||||
} catch (IllegalAccessException ex) {
|
||||
Respackopts.LOGGER.error("Could not evaluate condition " + file + " (pack: " + key.packName() + ")", e);
|
||||
Respackopts.LOGGER.error(res + " with condition:\n" + ObjectGraphPrinter.printGraph(rpo.condition) + ")", e);
|
||||
} catch (Throwable ex) {
|
||||
Respackopts.LOGGER.error(res, e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class BoolExprDeserializer implements JsonDeserializer<BoolExpr> {
|
|||
return switch (entry.getKey().toLowerCase(Locale.ROOT)) {
|
||||
case "and", "add", "&" -> merge(context.deserialize(entry.getValue(), conditionListType), Token.And);
|
||||
case "==", "=", "equal", "eq" -> merge(context.deserialize(entry.getValue(), conditionListType), Token.EqualEqual);
|
||||
case "not", "nor", "!" -> new Not(merge(context.deserialize(entry.getValue(), conditionListType), Token.Or));
|
||||
case "not", "nor", "!" -> new Not(0, merge(context.deserialize(entry.getValue(), conditionListType), Token.Or));
|
||||
case "or", "|" -> merge(context.deserialize(entry.getValue(), conditionListType), Token.Or);
|
||||
case "^", "xor" -> merge(context.deserialize(entry.getValue(), conditionListType), Token.BangEqual);
|
||||
default -> throw new JsonParseException("Unknown condition type: " + entry.getKey());
|
||||
|
@ -44,26 +44,27 @@ public class BoolExprDeserializer implements JsonDeserializer<BoolExpr> {
|
|||
if (pr.isString()) {
|
||||
String name = pr.getAsString();
|
||||
if (name.toLowerCase(Locale.ROOT).equals("true"))
|
||||
return Expr.literal(true);
|
||||
return Expr.literal(0, true);
|
||||
if (name.toLowerCase(Locale.ROOT).equals("false"))
|
||||
return Expr.literal(false);
|
||||
return Expr.literal(0, false);
|
||||
return rpoBooleanCondition(name);
|
||||
}
|
||||
else if (pr.isBoolean()) {
|
||||
return Expr.literal(pr.getAsBoolean());
|
||||
return Expr.literal(0, pr.getAsBoolean());
|
||||
}
|
||||
}
|
||||
throw new JsonParseException("Invalid data type for condition");
|
||||
}
|
||||
|
||||
private BoolExpr merge(List<BoolExpr> expressions, Token token) {
|
||||
if (token == Token.BangEqual)
|
||||
return new Not(0, merge(expressions, Token.EqualEqual));
|
||||
BoolExpr current = expressions.get(0);
|
||||
for (BoolExpr expr : expressions.subList(1, expressions.size())) {
|
||||
current = switch (token) {
|
||||
case EqualEqual -> new Equal(current, expr);
|
||||
case BangEqual -> new Not(new Equal(current, expr));
|
||||
case And -> new And(current, expr);
|
||||
case Or -> new Or(current, expr);
|
||||
case EqualEqual -> new Equal(0, current, expr);
|
||||
case And -> new And(0, current, expr);
|
||||
case Or -> new Or(0, current, expr);
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
|
@ -75,16 +76,16 @@ public class BoolExprDeserializer implements JsonDeserializer<BoolExpr> {
|
|||
String code = name.substring("modversion:".length());
|
||||
String mod = code.substring(0, code.indexOf(':'));
|
||||
String predicate = code.substring(code.indexOf(':') + 1);
|
||||
return new Call(new Variable("version"), List.of(
|
||||
Expr.literal(mod).asDynamicExpr(),
|
||||
Expr.literal(predicate).asDynamicExpr()
|
||||
return new Call(0, new Variable(0, "version"), List.of(
|
||||
Expr.literal(0, mod).asDynamicExpr(),
|
||||
Expr.literal(0, predicate).asDynamicExpr()
|
||||
)).asBoolExpr();
|
||||
}
|
||||
DynamicExpr e = null;
|
||||
String[] arr = name.split("[:.]");
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
if (i == 0) e = new Variable(arr[i]);
|
||||
else e = new Get(e, Expr.literal(arr[i]));
|
||||
if (i == 0) e = new Variable(0, arr[i]);
|
||||
else e = new Get(0, e, Expr.literal(0, arr[i]));
|
||||
}
|
||||
if (e == null) throw new JsonParseException("Invalid RPO condition: \"" + name + "\"");
|
||||
return e.asBoolExpr();
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package io.gitlab.jfronny.respackopts.gson;
|
||||
|
||||
import io.gitlab.jfronny.gson.*;
|
||||
import io.gitlab.jfronny.muscript.compiler.expr.*;
|
||||
import io.gitlab.jfronny.respackopts.model.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
public class ConditionDeserializer implements JsonDeserializer<Condition> {
|
||||
@Override
|
||||
public Condition deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String source = "Source unavailable";
|
||||
if (json.isJsonPrimitive()) {
|
||||
JsonPrimitive primitive = json.getAsJsonPrimitive();
|
||||
if (primitive.isString()) source = primitive.getAsString();
|
||||
}
|
||||
return new Condition(source, context.deserialize(json, BoolExpr.class));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package io.gitlab.jfronny.respackopts.model;
|
||||
|
||||
import io.gitlab.jfronny.muscript.compiler.expr.*;
|
||||
import io.gitlab.jfronny.muscript.dynamic.*;
|
||||
import io.gitlab.jfronny.muscript.error.*;
|
||||
|
||||
public record Condition(String source, BoolExpr expr) {
|
||||
public boolean get(Dynamic<?> dataRoot) throws ConditionException {
|
||||
try {
|
||||
return expr.get(dataRoot);
|
||||
} catch (LocationalException e) {
|
||||
throw new ConditionException(e.asPrintable(source), e);
|
||||
} catch (RuntimeException e) {
|
||||
throw new ConditionException(LocationalError.create(source, 0, e.getMessage()), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConditionException extends Exception {
|
||||
public final LocationalError error;
|
||||
|
||||
public ConditionException(LocationalError error, Throwable cause) {
|
||||
super(error.toString(), cause);
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,11 +2,10 @@ package io.gitlab.jfronny.respackopts.model;
|
|||
|
||||
import io.gitlab.jfronny.commons.serialize.gson.api.*;
|
||||
import io.gitlab.jfronny.gson.annotations.*;
|
||||
import io.gitlab.jfronny.muscript.compiler.expr.*;
|
||||
|
||||
public class DirRpo {
|
||||
@SerializedName(value = "condition", alternate = {"conditions"})
|
||||
public BoolExpr condition;
|
||||
public Condition condition;
|
||||
@SerializedName(value = "fallback", alternate = {"fallbacks"})
|
||||
public String fallback;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.*;
|
|||
|
||||
public class FileRpo {
|
||||
@SerializedName(value = "condition", alternate = {"conditions"})
|
||||
public BoolExpr condition;
|
||||
public Condition condition;
|
||||
@SerializedName(value = "fallback", alternate = {"fallbacks"})
|
||||
public Set<String> fallbacks;
|
||||
@SerializedName(value = "expansion", alternate = {"expansions"})
|
||||
|
|
Loading…
Reference in New Issue