improve mod list
All checks were successful
Publish to snapshot maven / build (push) Successful in 19s
All checks were successful
Publish to snapshot maven / build (push) Successful in 19s
This commit is contained in:
parent
8a3267ffbe
commit
e67ee70cb5
|
@ -75,7 +75,8 @@ public class LoaderGui extends JFrame {
|
||||||
|
|
||||||
public static void execUnfulfilledDep(Path reportPath, ModDependencyResolver.UnfulfilledDependencyException ex, boolean keepRunning) {
|
public static void execUnfulfilledDep(Path reportPath, ModDependencyResolver.UnfulfilledDependencyException ex, boolean keepRunning) {
|
||||||
exec(gui -> {
|
exec(gui -> {
|
||||||
gui.setHeader("Found " + ex.getDependencies().size() + " problems");
|
int count = ex.getDependencies().size();
|
||||||
|
gui.setHeader("Found " + count + " problem"+(count > 1 ? "s" : ""));
|
||||||
gui.addTab("Info", new UnfulfilledDepPage(ex));
|
gui.addTab("Info", new UnfulfilledDepPage(ex));
|
||||||
addReport(gui, reportPath);
|
addReport(gui, reportPath);
|
||||||
}, keepRunning);
|
}, keepRunning);
|
||||||
|
@ -83,7 +84,8 @@ public class LoaderGui extends JFrame {
|
||||||
|
|
||||||
public static void execBreakingDep(Path reportPath, ModDependencyResolver.BreakingModException ex, boolean keepRunning) {
|
public static void execBreakingDep(Path reportPath, ModDependencyResolver.BreakingModException ex, boolean keepRunning) {
|
||||||
exec(gui -> {
|
exec(gui -> {
|
||||||
gui.setHeader("Found " + ex.getBreaks().size() + " problems");
|
int count = ex.getBreaks().size();
|
||||||
|
gui.setHeader("Found " + count + " problem"+(count > 1 ? "s" : ""));
|
||||||
gui.addTab("Info", new BreakingDepPage(ex));
|
gui.addTab("Info", new BreakingDepPage(ex));
|
||||||
addReport(gui, reportPath);
|
addReport(gui, reportPath);
|
||||||
}, keepRunning);
|
}, keepRunning);
|
||||||
|
|
|
@ -15,8 +15,9 @@ public class ReportPage extends JScrollPane {
|
||||||
getHorizontalScrollBar().setUnitIncrement(16);
|
getHorizontalScrollBar().setUnitIncrement(16);
|
||||||
getVerticalScrollBar().setUnitIncrement(16);
|
getVerticalScrollBar().setUnitIncrement(16);
|
||||||
|
|
||||||
JTextPane text = new JTextPane();
|
JTextArea text = new JTextArea();
|
||||||
text.setEditable(false);
|
text.setEditable(false);
|
||||||
|
text.setTabSize(2);
|
||||||
try {
|
try {
|
||||||
text.setText(Files.readString(reportPath, StandardCharsets.UTF_8));
|
text.setText(Files.readString(reportPath, StandardCharsets.UTF_8));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -25,6 +26,7 @@ public class ReportPage extends JScrollPane {
|
||||||
printer.printf("Could not load contents of %s:%n", reportPath);
|
printer.printf("Could not load contents of %s:%n", reportPath);
|
||||||
e.printStackTrace(printer);
|
e.printStackTrace(printer);
|
||||||
}
|
}
|
||||||
|
text.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));
|
||||||
setViewportView(text);
|
setViewportView(text);
|
||||||
SwingUtilities.invokeLater(() -> getViewport().setViewPosition(new Point(0, 0)));
|
SwingUtilities.invokeLater(() -> getViewport().setViewPosition(new Point(0, 0)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class ModPropertiesReader {
|
||||||
|
|
||||||
for (UnmodifiableConfig entry : dependenciesConfig) {
|
for (UnmodifiableConfig entry : dependenciesConfig) {
|
||||||
String entryId = entry.get("id");
|
String entryId = entry.get("id");
|
||||||
String entryVersions = entry.get("versions");
|
String entryVersions = entry.get(key.equals("provides") ? "version" : "versions");
|
||||||
|
|
||||||
if (entryId == null || entryId.isEmpty())
|
if (entryId == null || entryId.isEmpty())
|
||||||
badProperties.add("frog.dependencies." + key + '.' + i + ".id");
|
badProperties.add("frog.dependencies." + key + '.' + i + ".id");
|
||||||
|
|
|
@ -1,52 +1,69 @@
|
||||||
package dev.frogmc.frogloader.impl.mod;
|
package dev.frogmc.frogloader.impl.mod;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.*;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import dev.frogmc.frogloader.api.FrogLoader;
|
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class ModUtil {
|
public class ModUtil {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ModUtil.class);
|
|
||||||
|
|
||||||
public static String getModList(Collection<ModProperties> mods) {
|
public static String getModList(Collection<ModProperties> mods) {
|
||||||
int size = mods.size();
|
int size = mods.size();
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
return "No mods loaded.";
|
return "No mods loaded.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, ModProperties> modIdMap = mods.stream().collect(Collectors.toMap(ModProperties::id, m -> m));
|
||||||
|
AtomicInteger indent = new AtomicInteger(1);
|
||||||
|
Map<ModProperties, Collection<String>> parentToChildIdMap = getParentMods(mods);
|
||||||
|
Collection<String> containedIds = parentToChildIdMap.values().stream().flatMap(Collection::stream).collect(Collectors.toUnmodifiableSet());
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("Loaded ").append(size).append(" mod");
|
List<ModProperties> parents = parentToChildIdMap.keySet().stream().filter(p -> !containedIds.contains(p.id()))
|
||||||
|
.sorted(Comparator.comparing(ModProperties::id)).toList();
|
||||||
|
int parentCount = parents.size();
|
||||||
|
builder.append("Loaded ").append(parentCount).append(" (").append(size).append(")").append(" mod");
|
||||||
if (size > 1) {
|
if (size > 1) {
|
||||||
builder.append("s");
|
builder.append("s");
|
||||||
}
|
}
|
||||||
builder.append(":");
|
builder.append(":");
|
||||||
AtomicInteger i = new AtomicInteger();
|
parents.forEach(p -> printMod(modIdMap, p, builder, indent, parentToChildIdMap));
|
||||||
mods.stream().sorted(Comparator.comparing(ModProperties::id)).forEach(p -> {
|
|
||||||
builder.append("\n\t");
|
|
||||||
if (i.get() < size - 1) {
|
|
||||||
builder.append("|- ");
|
|
||||||
} else {
|
|
||||||
builder.append("\\- ");
|
|
||||||
}
|
|
||||||
builder.append(p.id()).append(" (").append(p.name()).append(") ").append(" ").append(p.version());
|
|
||||||
i.getAndIncrement();
|
|
||||||
});
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void installMod(String url) {
|
private static void printMod(Map<String, ModProperties> mods, ModProperties p, StringBuilder builder, AtomicInteger indent, Map<ModProperties, Collection<String>> parentToChildIdMap) {
|
||||||
try {
|
builder.append("\n").append("\t".repeat(indent.getAndIncrement()));
|
||||||
Files.copy(URI.create(url).toURL().openStream(), FrogLoader.getInstance().getModsDir().resolve(url.substring(url.lastIndexOf("/" + 1))));
|
Collection<String> children = parentToChildIdMap.get(p);
|
||||||
} catch (IOException e) {
|
if (!children.isEmpty()) {
|
||||||
LOGGER.error("Failed to install mod:", e);
|
builder.append("\\- ");
|
||||||
|
} else {
|
||||||
|
builder.append("|- ");
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append(p.id()).append(" (").append(p.name()).append(") ").append(" ").append(p.version());
|
||||||
|
for (String s : children) {
|
||||||
|
printMod(mods, mods.get(s), builder, indent, parentToChildIdMap);
|
||||||
|
}
|
||||||
|
indent.getAndDecrement();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<ModProperties, Collection<String>> getParentMods(Collection<ModProperties> mods) {
|
||||||
|
Map<ModProperties, Collection<String>> children = new HashMap<>();
|
||||||
|
for (ModProperties mod : mods) {
|
||||||
|
List<List<UnmodifiableConfig>> entries = mod.extensions().get(BuiltinExtensions.INCLUDED_JARS);
|
||||||
|
if (entries != null) {
|
||||||
|
for (var jars : entries) {
|
||||||
|
for (var jar : jars) {
|
||||||
|
String id = jar.get("id");
|
||||||
|
children.computeIfAbsent(mod, m -> new HashSet<>()).add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
children.computeIfAbsent(mod, m -> new HashSet<>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return children;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.net.MalformedURLException;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import dev.frogmc.frogloader.api.FrogLoader;
|
import dev.frogmc.frogloader.api.FrogLoader;
|
||||||
import dev.frogmc.frogloader.api.extensions.PreLaunchExtension;
|
import dev.frogmc.frogloader.api.extensions.PreLaunchExtension;
|
||||||
|
@ -123,13 +124,13 @@ public class Minecraft implements FrogPlugin {
|
||||||
ModProperties p = opt.get();
|
ModProperties p = opt.get();
|
||||||
modProperties.add(p);
|
modProperties.add(p);
|
||||||
modPaths.put(mod, p);
|
modPaths.put(mod, p);
|
||||||
List<List<Map<String, String>>> entries = p.extensions().getOrDefault(BuiltinExtensions.INCLUDED_JARS, Collections.emptyList());
|
List<List<UnmodifiableConfig>> entries = p.extensions().getOrDefault(BuiltinExtensions.INCLUDED_JARS, Collections.emptyList());
|
||||||
if (entries.isEmpty()) {
|
if (entries.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (FileSystem fs = FileSystems.newFileSystem(mod)) {
|
try (FileSystem fs = FileSystems.newFileSystem(mod)) {
|
||||||
for (var jars : entries) {
|
for (List<UnmodifiableConfig> jars : entries) {
|
||||||
for (Map<String, String> jar : jars) {
|
for (UnmodifiableConfig jar : jars) {
|
||||||
Path path = fs.getPath(jar.get("path")).toAbsolutePath();
|
Path path = fs.getPath(jar.get("path")).toAbsolutePath();
|
||||||
mods.add(path);
|
mods.add(path);
|
||||||
findJiJMods(path, mods, modPaths);
|
findJiJMods(path, mods, modPaths);
|
||||||
|
|
Loading…
Reference in a new issue