Skip to content

Commit

Permalink
Added console output when file gets skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Oct 19, 2023
1 parent e358e6c commit 1325fbd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,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 "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,23 @@ 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) {
var packMap = new HashMap<String, List<ResourceLocation>>();
Map<String, List<ResourceLocation>> packMap = new HashMap<>();

for (var resource : resourceManager.listResources("kubejs", s -> s.getPath().endsWith(".js") || s.getPath().endsWith(".ts") && !s.getPath().endsWith(".d.ts")).keySet()) {
packMap.computeIfAbsent(resource.getNamespace(), s -> new ArrayList<>()).add(resource);
Expand All @@ -94,17 +109,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);
Expand Down Expand Up @@ -137,18 +142,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);
Expand Down

0 comments on commit 1325fbd

Please sign in to comment.