diff --git a/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java b/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java index fdcf5a1b5..86e61c894 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java @@ -165,7 +165,7 @@ public static void loadScripts(ScriptPack pack, Path dir, String path) { for (var file : Files.walk(dir, 10, FileVisitOption.FOLLOW_LINKS).filter(Files::isRegularFile).toList()) { var fileName = dir.relativize(file).toString().replace(File.separatorChar, '/'); - if (fileName.endsWith(".js")) { + if (fileName.endsWith(".js") || fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) { pack.info.scripts.add(new ScriptFileInfo(pack.info, pathPrefix + fileName)); } } diff --git a/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java b/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java index e60fdf52f..67257bde6 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java @@ -4,7 +4,6 @@ import dev.latvian.mods.kubejs.CommonProperties; import dev.latvian.mods.kubejs.util.UtilsJS; import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -42,18 +41,11 @@ public ScriptFileInfo(ScriptPackInfo p, String f) { lines = UtilsJS.EMPTY_STRING_ARRAY; } - @Nullable - public Throwable preload(ScriptSource source) { + public void preload(ScriptSource source) throws Throwable { properties.clear(); priority = 0; ignored = false; - lines = UtilsJS.EMPTY_STRING_ARRAY; - - try { - lines = source.readSource(this).toArray(UtilsJS.EMPTY_STRING_ARRAY); - } catch (Throwable ex) { - return ex; - } + lines = source.readSource(this).toArray(UtilsJS.EMPTY_STRING_ARRAY); for (int i = 0; i < lines.length; i++) { var tline = lines[i].trim(); @@ -71,16 +63,10 @@ public Throwable preload(ScriptSource source) { } } - try { - priority = Integer.parseInt(getProperty("priority", "0")); - ignored = getProperty("ignored", "false").equals("true") || getProperty("ignore", "false").equals("true"); - packMode = getProperty("packmode", "default"); - requiredMods.addAll(getProperties("requires")); - } catch (Exception ex) { - return ex; - } - - return null; + priority = Integer.parseInt(getProperty("priority", "0")); + ignored = getProperty("ignored", "false").equals("true") || getProperty("ignore", "false").equals("true"); + packMode = getProperty("packmode", "default"); + requiredMods.addAll(getProperties("requires")); } public List getProperties(String s) { @@ -96,23 +82,23 @@ public int getPriority() { return priority; } - public boolean skipLoading() { + public String skipLoading() { if (ignored) { - return true; + return "Ignored"; } if (!packMode.isEmpty() && !packMode.equals(CommonProperties.get().packMode)) { - return true; + return "Pack mode mismatch"; } if (!requiredMods.isEmpty()) { for (String mod : requiredMods) { if (!Platform.isModLoaded(mod)) { - return true; + return "Mod " + mod + " is not loaded"; } } } - return false; + return ""; } } \ No newline at end of file diff --git a/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java b/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java index dfc4bde48..530084988 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java @@ -80,6 +80,21 @@ public void reload(@Nullable ResourceManager resourceManager) { load(); } + private void loadFile(ScriptPack pack, ScriptFileInfo fileInfo, ScriptSource source) { + try { + fileInfo.preload(source); + var skip = fileInfo.skipLoading(); + + if (skip.isEmpty()) { + pack.scripts.add(new ScriptFile(pack, fileInfo, source)); + } else { + scriptType.console.info("Skipped " + fileInfo.location + ": " + skip); + } + } catch (Throwable error) { + scriptType.console.error("Failed to pre-load script file " + fileInfo.location + ": " + error); + } + } + private void loadFromResources(ResourceManager resourceManager) { Map> packMap = new HashMap<>(); @@ -96,17 +111,7 @@ private void loadFromResources(ResourceManager resourceManager) { for (var fileInfo : pack.info.scripts) { var scriptSource = (ScriptSource.FromResource) info -> resourceManager.getResourceOrThrow(info.id); - var error = fileInfo.preload(scriptSource); - - if (fileInfo.skipLoading()) { - continue; - } - - if (error == null) { - pack.scripts.add(new ScriptFile(pack, fileInfo, scriptSource)); - } else { - scriptType.console.error("Failed to pre-load script file " + fileInfo.location + ": " + error); - } + loadFile(pack, fileInfo, scriptSource); } pack.scripts.sort(null); @@ -139,18 +144,7 @@ public void loadFromDirectory() { for (var fileInfo : pack.info.scripts) { var scriptSource = (ScriptSource.FromPath) info -> directory.resolve(info.file); - - var error = fileInfo.preload(scriptSource); - - if (fileInfo.skipLoading()) { - continue; - } - - if (error == null) { - pack.scripts.add(new ScriptFile(pack, fileInfo, scriptSource)); - } else { - KubeJS.LOGGER.error("Failed to pre-load script file " + fileInfo.location + ": " + error); - } + loadFile(pack, fileInfo, scriptSource); } pack.scripts.sort(null);