From a0bf600a7bf38ef485bd21719b88aef4a8565df6 Mon Sep 17 00:00:00 2001 From: TimeBather Date: Sat, 30 Nov 2024 16:17:33 +0800 Subject: [PATCH 1/2] feat: implement assets for production packages --- .../kasuga/lib/core/addons/node/AssetReader.java | 14 +++++++++++++- .../frontend/commands/MetroModuleLoader.java | 4 ++-- .../engine/javet/JavetJavascriptModule.java | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/kasuga/lib/core/addons/node/AssetReader.java b/src/main/java/kasuga/lib/core/addons/node/AssetReader.java index 9f24a42c..f23d2c97 100644 --- a/src/main/java/kasuga/lib/core/addons/node/AssetReader.java +++ b/src/main/java/kasuga/lib/core/addons/node/AssetReader.java @@ -17,14 +17,16 @@ public class AssetReader implements BiFunction { private final HashMap assets; private final JavascriptContext context; private final String dirname; + private final String assetRoot; ResourceProvider provider; - public AssetReader(String dirname, JavascriptContext context, ResourceProvider provider, HashMap assets) { + public AssetReader(String dirname, JavascriptContext context, ResourceProvider provider, HashMap assets, String assetRoot) { this.provider = provider; this.context = context; this.assets = assets; this.dirname = dirname; + this.assetRoot = assetRoot == null ? "/" : assetRoot; } @HostAccess.Export @@ -45,6 +47,16 @@ public String apply(String path, String resourceType){ ) ); } + path = PackageScanner.joinPath( + PackageScanner.resolve( + PackageScanner.splitPath( + assetRoot + ), + PackageScanner.splitPath( + path + ) + ) + ); UUID uuid; do{ uuid = UUID.randomUUID(); diff --git a/src/main/java/kasuga/lib/core/client/frontend/commands/MetroModuleLoader.java b/src/main/java/kasuga/lib/core/client/frontend/commands/MetroModuleLoader.java index c70d04f3..8aacf364 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/commands/MetroModuleLoader.java +++ b/src/main/java/kasuga/lib/core/client/frontend/commands/MetroModuleLoader.java @@ -106,8 +106,8 @@ protected JavascriptEngineModule load( module.getDirectoryName(), javascriptContext, moduleInfo.getProvider(), - KasugaLib.STACKS.JAVASCRIPT.ASSETS.get() - )); + KasugaLib.STACKS.JAVASCRIPT.ASSETS.get(), + "/")); return module; }catch (IOException e){ diff --git a/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetJavascriptModule.java b/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetJavascriptModule.java index 3dc50fed..f14a549a 100644 --- a/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetJavascriptModule.java +++ b/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetJavascriptModule.java @@ -37,7 +37,8 @@ public JavetJavascriptModule( directoryName, context, nodePackage.reader, - KasugaLib.STACKS.JAVASCRIPT.ASSETS.get() + KasugaLib.STACKS.JAVASCRIPT.ASSETS.get(), + nodePackage.minecraft.assetsFolder() ): null, absolutePath, directoryName, context); } public JavetJavascriptModule( From 4ac55ab5d5f7e663b167b0c5f2819c47d8a85b11 Mon Sep 17 00:00:00 2001 From: TimeBather Date: Sat, 30 Nov 2024 20:12:30 +0800 Subject: [PATCH 2/2] fix: cannot read assets in local modules --- .../lib/core/javascript/engine/javet/JavetJavascriptModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetJavascriptModule.java b/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetJavascriptModule.java index f14a549a..79102c60 100644 --- a/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetJavascriptModule.java +++ b/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetJavascriptModule.java @@ -54,6 +54,7 @@ public JavetJavascriptModule( this.nodePackage = nodePackage; this.directoryName = directoryName; this.context = context; + this.assetReader = reader; } public JavetJavascriptModule(