feat: /rpoc execute to test muScript snippet
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2023-08-14 17:06:18 +02:00
parent e5f450eb23
commit 5cd0d91dd6
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 18 additions and 1 deletions

View File

@ -31,6 +31,7 @@ This is especially useful when using file expansion.
One common issue is that you removed an option but still use it somewhere.
The log will usually reference that option and the source.
You can use the dumped scope as a reference for what actually exists for your condition.
Aditionally, you can use `/rpoc execute` to execute muScript snippets (be aware that you will need to prefix your entries with your pack id when doing so)
## Ensure you are using the correct dots
Respackopts only supports normal dots. If you write commas or colons by accident,

View File

@ -4,6 +4,8 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
import io.gitlab.jfronny.commons.throwable.ThrowingSupplier;
import io.gitlab.jfronny.muscript.compiler.Parser;
import io.gitlab.jfronny.muscript.error.LocationalException;
import io.gitlab.jfronny.respackopts.util.MetaCache;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
@ -47,6 +49,17 @@ public class RpoClientCommand {
ctx.getSource().sendFeedback(dump(() -> MinecraftClient.getInstance().getResourceManager().open(id), id.getNamespace() + "/" + id.getPath()));
return 1;
};
Command<FabricClientCommandSource> execute = ctx -> {
String snippet = StringArgumentType.getString(ctx, "snippet");
try {
String result = Parser.parse(snippet, "snippet").asStringExpr().get(MetaCache.getScope(null));
ctx.getSource().sendFeedback(Text.translatable("respackopts.snippet.success", result));
} catch (LocationalException | Parser.ParseException e) {
Respackopts.LOGGER.error("Could not execute snippet", e);
ctx.getSource().sendError(Text.translatable("respackopts.snippet.failed", e.getMessage()));
}
return 1;
};
Command<FabricClientCommandSource> reload = ctx -> {
MetaCache.clear();
CompletableFuture.allOf(RespackoptsClient.forceReloadResources(), RespackoptsClient.reloadIntegratedServerData())
@ -65,6 +78,7 @@ public class RpoClientCommand {
.then(literal("scope").executes(dumpScope))
.then(literal("glsl").executes(dumpGlsl))
.then(literal("asset").then(argument("asset", IdentifierArgumentType.identifier()).executes(dumpAsset))))
.then(literal("execute").then(argument("snippet", StringArgumentType.greedyString()).executes(execute)))
.then(literal("version").executes(getVersion))
.then(literal("reload").executes(reload)));
});

View File

@ -12,5 +12,7 @@
"respackopts.reloadSucceeded": "Successfully reloaded resources and data",
"respackopts.reloadFailed": "Could not reload all resources, look at your log for details",
"respackopts.versionText": "Version %s using the respackotps meta version %s",
"respackopts.invalidId": "Invalid Identifier"
"respackopts.invalidId": "Invalid Identifier",
"respackopts.snippet.success": "Executed snippet and got: %s",
"respackopts.snippet.failed": "Snippet could not be executed: %s"
}