add name declaration to the dependency section

This commit is contained in:
moehreag 2024-06-03 20:59:24 +02:00
parent 5a312eaba3
commit b82e6bceae
5 changed files with 41 additions and 23 deletions

View file

@ -12,7 +12,7 @@ credits = [
[frog.dependencies]
depends = [
{ id = "other_mod", versions = ">=0.2.0 <0.5.2 || 0.1.1 || 1.x || 3 || ~5 || ^6.x", link = "https://example.com" }
{ id = "other_mod", name = "Other Mod", versions = ">=0.2.0 <0.5.2 || 0.1.1 || 1.x || 3 || ~5 || ^6.x", link = "https://example.com" }
]
breaks = [
{ id = "old_mod", versions = "*" }

View file

@ -53,7 +53,7 @@ public final class ModDependencies {
}
}
public record Entry(String id, String range, String link) {
public record Entry(String id, String range, String link, String name) {
}

View file

@ -122,27 +122,46 @@ public class LoaderGui {
public static final ContentType<ModDependencyResolver.UnfulfilledDependencyException> INFO_UNFULFILLED_DEP = new ContentType<>((frame, ex) -> {
JPanel pane = new JPanel(new BorderLayout());
JTextPane title = new JTextPane();
title.setContentType("text/html");
//title.setContentType("text/html");
title.setBackground(pane.getBackground());
title.setEditable(false);
int size = ex.getDependencies().size();
title.setText("<html><h3>Found "+size+" Error"+(size > 1 ? "s:":":")+"</h3></html>");
//title.setText("<html><h3>Found "+size+" Error"+(size > 1 ? "s:":":")+"</h3></html>");
title.setText("Found "+size+" Error"+(size > 1 ? "s:":":"));
title.setFont(title.getFont().deriveFont(Font.BOLD, 16f));
title.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0));
pane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
pane.add(title, BorderLayout.NORTH);
JPanel list = new JPanel();
list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
Box list = Box.createVerticalBox();
ex.getDependencies().forEach(e -> {
StringBuilder description = new StringBuilder();
if (e.presentVersion() != null){
description.append("Mod %s (%s) depends on a Mod with id %s with a version matching %s, but a different version is present or provided: %s".formatted(e.source().id(), e.source().name(), e.dependency(), printVersionRange(e.range()), e.presentVersion()));
description.append("Mod ").append(e.source().id()).append(" (").append(e.source().name()).append(") depends on ");
if (e.dependencyName() != null){
description.append(e.dependencyName()).append(" (").append(e.dependency()).append(") ");
} else {
description.append("a Mod with id ").append(e.dependency());
}
description.append(" with a version matching ").append(printVersionRange(e.range())).append(", but a different version is present or provided: ").append(e.presentVersion());
} else {
description.append(String.format("Mod %s (%s) depends on a Mod with id %s with a version matching %s. \nNo version is currently available.", e.source().id(), e.source().name(), e.dependency(), printVersionRange(e.range())));
description.append("Mod ").append(e.source().id()).append(" (").append(e.source().name()).append(") depends on ");
if (e.dependencyName() != null){
description.append(e.dependencyName()).append(" (").append(e.dependency()).append(") ");
} else {
description.append("a Mod with id ").append(e.dependency());
}
description.append(" with a version matching ").append(printVersionRange(e.range())).append(". \nNo version is currently available.");
}
description.append("\nSuggested Solution: Install ")
.append(e.range().maxCompatible().or(e.range()::minCompatible).map(Objects::toString)
.map(s -> "0.0.0".equals(s) ? "any version" : "version " + s).orElse("<unknown>"))
.append(" of Mod with id ").append(e.dependency());
.append(" of ");
if (e.dependencyName() != null){
description.append(e.dependencyName()).append(" (").append(e.dependency()).append(") ");
} else {
description.append("Mod with id ").append(e.dependency());
}
List<JButton> actions = new ArrayList<>();
if (e.link() != null) {
boolean install = e.link().endsWith(FrogLoaderImpl.MOD_FILE_EXTENSION);
@ -176,8 +195,7 @@ public class LoaderGui {
pane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
pane.add(title, BorderLayout.NORTH);
JPanel list = new JPanel();
list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
Box list = Box.createVerticalBox();
ex.getBreaks().forEach(e -> {
String description = "Mod %s (%s) breaks with mod %s (%s) for versions matching %s \n(present: %s)".formatted(e.source().id(), e.source().name(), e.broken().id(), e.broken().name(), printVersionRange(e.range()), e.broken().version()) +
"\nSuggested Solution: Install " +

View file

@ -36,13 +36,13 @@ public class ModDependencyResolver {
private void load() throws ResolverException {
for (ModProperties props : original) {
for (ModDependencies.Entry entry : props.dependencies().getForType(ModDependencies.Type.DEPEND)) {
dependencies.put(entry.id(), new DependencyEntry(entry.range(), props, entry.link()));
dependencies.put(entry.id(), new DependencyEntry(entry.range(), props, entry.link(), entry.name()));
}
for (ModDependencies.Entry entry : props.dependencies().getForType(ModDependencies.Type.BREAK)) {
breakings.put(entry.id(), new DependencyEntry(entry.range(), props, entry.link()));
breakings.put(entry.id(), new DependencyEntry(entry.range(), props, entry.link(), entry.name()));
}
for (ModDependencies.Entry entry : props.dependencies().getForType(ModDependencies.Type.SUGGEST)) {
suggests.put(entry.id(), new DependencyEntry(entry.range(), props, entry.link()));
suggests.put(entry.id(), new DependencyEntry(entry.range(), props, entry.link(), entry.name()));
}
props.dependencies().getForType(ModDependencies.Type.PROVIDE).forEach(e -> {
try {
@ -115,7 +115,7 @@ public class ModDependencyResolver {
if (!(presentMods.containsKey(s) && value.range.versionMatches(presentOrProvided.get(s)))) { // The dependency isn't fulfilled by any present mods
if (!(provides.containsKey(s) && value.range.versionMatches(provides.get(s).version()))) { // The dependency also isn't fulfilled by any provided mods
if (value.origin.extensions().getOrDefault(BuiltinExtensions.LOADING_TYPE, "required").equals("required")) {
unfulfilled.add(new UnfulfilledDependencyException.Entry(value.origin, s, value.range, presentOrProvided.get(s), value.link()));
unfulfilled.add(new UnfulfilledDependencyException.Entry(value.origin, s, value.range, presentOrProvided.get(s), value.link(), value.name()));
} else {
continue;
}
@ -197,7 +197,7 @@ public class ModDependencyResolver {
}
public record Entry(ModProperties source, String dependency, VersionRange range, SemVer presentVersion,
@Nullable String link) {
@Nullable String link, String dependencyName) {
}
}
@ -207,10 +207,10 @@ public class ModDependencyResolver {
}
}
private record DependencyEntry(VersionRange range, ModProperties origin, String link) {
private record DependencyEntry(VersionRange range, ModProperties origin, String link, String name) {
public DependencyEntry(String range, ModProperties origin, @Nullable String link) throws ResolverException {
this(VersionRange.parse(range), origin, link);
public DependencyEntry(String range, ModProperties origin, @Nullable String link, @Nullable String name) throws ResolverException {
this(VersionRange.parse(range), origin, link, name);
}
}

View file

@ -76,25 +76,25 @@ public class ModPropertiesReader {
Collection<ModDependencies.Entry> depends = new HashSet<>();
List<UnmodifiableConfig> dependsConfig = config.get("frog.dependencies.depends");
if (dependsConfig != null) {
dependsConfig.forEach(entry -> depends.add(new ModDependencies.Entry(entry.get("id"), entry.get("versions"), entry.get("link"))));
dependsConfig.forEach(entry -> depends.add(new ModDependencies.Entry(entry.get("id"), entry.get("versions"), entry.get("link"), entry.get("name"))));
}
Collection<ModDependencies.Entry> breaks = new HashSet<>();
List<UnmodifiableConfig> breaksConfig = config.get("frog.dependencies.breaks");
if (breaksConfig != null) {
breaksConfig.forEach(entry -> breaks.add(new ModDependencies.Entry(entry.get("id"), entry.get("versions"), entry.get("link"))));
breaksConfig.forEach(entry -> breaks.add(new ModDependencies.Entry(entry.get("id"), entry.get("versions"), entry.get("link"), entry.get("name"))));
}
Collection<ModDependencies.Entry> suggests = new HashSet<>();
List<UnmodifiableConfig> suggestsConfig = config.get("frog.dependencies.suggests");
if (suggestsConfig != null) {
suggestsConfig.forEach(entry -> suggests.add(new ModDependencies.Entry(entry.get("id"), entry.get("versions"), entry.get("link"))));
suggestsConfig.forEach(entry -> suggests.add(new ModDependencies.Entry(entry.get("id"), entry.get("versions"), entry.get("link"), entry.get("name"))));
}
Collection<ModDependencies.Entry> provides = new HashSet<>();
List<UnmodifiableConfig> providesConfig = config.get("frog.dependencies.provides");
if (providesConfig != null) {
providesConfig.forEach(entry -> provides.add(new ModDependencies.Entry(entry.get("id"), entry.get("version"), entry.get("link"))));
providesConfig.forEach(entry -> provides.add(new ModDependencies.Entry(entry.get("id"), entry.get("version"), entry.get("link"), entry.get("name"))));
}
UnmodifiableConfig extensionsConfig = config.get("frog.extensions");