diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigChanges.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigChanges.java index 431d02d5..5bf3d436 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigChanges.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigChanges.java @@ -114,6 +114,7 @@ private Effect effect(GameState state, PackCatalog.ConfigType type, PackCatalog. return Effect.RESTART; } if (location == Location.WORLD && !state.isOpen(world)) return Effect.WORLD_OPENS; + if (restart == PackCatalog.Restart.UNKNOWN) return Effect.UNDESCRIBED; if (restart == PackCatalog.Restart.WORLD) return state.openWorld() == null ? Effect.NOW : Effect.REJOIN; return Effect.NOW; } diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigEdit.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigEdit.java index 3bcfab2e..3c4c8273 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigEdit.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigEdit.java @@ -151,21 +151,28 @@ private static BigDecimal number(String text) { } private static void checkRange(BigDecimal number, String range) { - BigDecimal minimum = null; - BigDecimal maximum = null; + String lower = null; + String upper = null; if (range.startsWith("> ")) { - minimum = number(range.substring(2)); + lower = range.substring(2); } else if (range.startsWith("< ")) { - maximum = number(range.substring(2)); + upper = range.substring(2); } else { Matcher bounds = RANGE.matcher(range); if (bounds.matches()) { - minimum = number(bounds.group(1)); - maximum = number(bounds.group(2)); + lower = bounds.group(1); + upper = bounds.group(2); } } - if (minimum != null && number.compareTo(minimum) < 0 || maximum != null && number.compareTo(maximum) > 0) { - throw new IllegalArgumentException("Accepts " + readableRange(range)); + BigDecimal minimum = lower == null ? null : number(lower); + BigDecimal maximum = upper == null ? null : number(upper); + // A bound at an int's limit reads as none, as NeoForge writes it for an int; the catalog does not know the type, + // so for a long it is a real bound, and the value refused for it names it. + if (minimum != null && number.compareTo(minimum) < 0) { + throw new IllegalArgumentException(unbounded(lower, false) ? "Accepts at least " + trimmed(lower) : "Accepts " + readableRange(range)); + } + if (maximum != null && number.compareTo(maximum) > 0) { + throw new IllegalArgumentException(unbounded(upper, true) ? "Accepts at most " + trimmed(upper) : "Accepts " + readableRange(range)); } } @@ -314,8 +321,8 @@ public static List changes(String before, String after, List entry : afterLiterals.entrySet()) { String previous = beforeLiterals.get(entry.getKey()); if (previous == null || sameValue(previous, entry.getValue())) continue; - PackCatalog.ConfigSetting setting = described.getOrDefault(entry.getKey(), new PackCatalog.ConfigSetting( - entry.getKey(), "", "", "", List.of(), PackCatalog.Restart.NONE)); + PackCatalog.ConfigSetting setting = described.getOrDefault(entry.getKey(), + PackCatalog.ConfigSetting.undescribed(entry.getKey(), "")); changes.add(new TextChange(setting, previous, entry.getValue())); } return changes; diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigLabels.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigLabels.java index 389b61f1..67b433f3 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigLabels.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigLabels.java @@ -103,7 +103,7 @@ private static PackCatalog.ConfigSetting described(CatalogIndex index, ChangeRec if (setting.path().equals(target.setting())) return setting; } } - return new PackCatalog.ConfigSetting(target.setting(), "", "", "", List.of(), PackCatalog.Restart.NONE); + return PackCatalog.ConfigSetting.undescribed(target.setting(), ""); } private static PackCatalog.ConfigType type(CatalogIndex index, ChangeRecord.Setting target) { diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigSources.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigSources.java index 0ee21069..73a20baf 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigSources.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigSources.java @@ -5,8 +5,10 @@ import com.github.minecraft_ta.totaldebug.storage.PackCatalog; import java.io.IOException; +import java.nio.file.DirectoryIteratorException; import java.nio.file.DirectoryStream; import java.nio.file.Files; +import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.attribute.FileTime; import java.util.ArrayList; @@ -28,6 +30,13 @@ public String toString() { } } + /** The copies of a configuration found, and why worlds that could not be read are missing, or empty. */ + public record Listed(List sources, String problem) { + public Listed { + sources = List.copyOf(sources); + } + } + /** A mod's configuration file and the mod it belongs to. */ public record Owner(PackCatalog.Mod mod, PackCatalog.ConfigFile file) { } @@ -79,35 +88,43 @@ private static boolean copyOf(Path workspace, PackCatalog.ConfigFile config, Pat /** * A configuration's loaded file, or for a server configuration the file of each world, the open world's first and * then the most recently changed, and then the defaults for new worlds. A server configuration's loaded file belongs to the world open when - * the catalog was captured, so every world is listed. Blocking for a server configuration; it lists the worlds. + * the catalog was captured, so every world is listed. A world that cannot be read is named in the problem and the + * others are listed. Blocking for a server configuration; it lists the worlds. */ - public static List of(GameLocation location, PackCatalog.ConfigFile file) { + public static Listed of(GameLocation location, PackCatalog.ConfigFile file) { Path workspace = location.workspace(); if (file.type() != PackCatalog.ConfigType.SERVER) { Path loaded = loaded(workspace, file); - return loaded == null ? List.of() : List.of(new Source(file.fileName(), loaded)); + return new Listed(loaded == null ? List.of() : List.of(new Source(file.fileName(), loaded)), ""); } List worlds = new ArrayList<>(); Map modified = new HashMap<>(); Set open = new HashSet<>(); + List unread = new ArrayList<>(); GameState game = location.read(); try (DirectoryStream saves = Files.newDirectoryStream(workspace.resolve("saves"), Files::isDirectory)) { for (Path world : saves) { Path path = world.resolve("serverconfig").resolve(file.fileName()); if (!Files.isRegularFile(path)) continue; - Source source = new Source(world.getFileName().toString(), path); - worlds.add(source); - modified.put(source, Files.getLastModifiedTime(path)); - if (game.isOpen(world)) open.add(source); + try { + Source source = new Source(world.getFileName().toString(), path); + modified.put(source, Files.getLastModifiedTime(path)); + worlds.add(source); + if (game.isOpen(world)) open.add(source); + } catch (IOException exception) { + unread.add(world.getFileName() + " (" + exception.getMessage() + ")"); + } } - } catch (IOException noSaves) { + } catch (NoSuchFileException noSaves) { // A pack that never created a world has no server configuration yet. + } catch (IOException | DirectoryIteratorException exception) { + unread.add("the saves folder (" + (exception.getCause() != null ? exception.getCause() : exception).getMessage() + ")"); } // The world the game has open is the one an edit is meant for. worlds.sort(Comparator.comparing((Source source) -> !open.contains(source)) .thenComparing(Comparator.comparing((Source source) -> modified.get(source)).reversed())); Path defaults = workspace.resolve("defaultconfigs").resolve(file.fileName()); if (Files.isRegularFile(defaults)) worlds.add(new Source("New worlds", defaults)); - return worlds; + return new Listed(worlds, unread.isEmpty() ? "" : "Could not read " + String.join(", ", unread)); } } diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigValues.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigValues.java index 231988e1..edd08e58 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigValues.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigValues.java @@ -94,7 +94,7 @@ private static void walk(UnmodifiableCommentedConfig level, String prefix, Map resources; private List directories; + /** The mods each listed file backs: one, several sharing an archive, or Minecraft for its own assets. */ + private Map> owners; /** Where the game keeps its keys, or null without a game directory. */ private final GameLocation location; private final Path options; @@ -116,10 +119,12 @@ List search(String query, Category category, int limit, Set modu if (category == Category.RESOURCES) { for (ModResources.Resource resource : resources()) { if (!resource.path().toLowerCase(Locale.ROOT).contains(folded)) continue; + // A mod's file owns what it holds, whatever namespace that is under. + List owners = this.owners.getOrDefault(resource.file(), List.of()); + if (moduleIds != null && owners.stream().noneMatch(owner -> moduleIds.contains(owner.module()))) continue; String namespace = namespace(resource.path()); - PackCatalog.Mod owner = this.index.mod(namespace).orElse(null); - if (moduleIds != null && (owner == null || !moduleIds.contains(owner.module()))) continue; - results.add(new ResourceResult(resource, this.index.ownerName(namespace))); + results.add(new ResourceResult(resource, owners.stream().filter(owner -> owner.id().equals(namespace)).findFirst() + .or(() -> owners.stream().findFirst()).map(PackCatalog.Mod::title).orElse(this.index.ownerName(namespace)))); } } // Every match is ranked before the limit applies, so a closer match late in the registry is kept. @@ -179,9 +184,14 @@ private static String namespace(String path) { private synchronized List resources() { if (this.resources == null) { List files = new ArrayList<>(); + Map> owners = new HashMap<>(); for (PackCatalog.Mod mod : this.index.mods()) { - for (Path file : this.index.resourceFiles(mod.id())) if (!files.contains(file)) files.add(file); + for (Path file : this.index.resourceFiles(mod.id())) { + if (!files.contains(file)) files.add(file); + owners.computeIfAbsent(file, ignored -> new ArrayList<>()).add(mod); + } } + this.owners = Map.copyOf(owners); this.directories = files.stream().filter(Files::isDirectory).toList(); this.resources = List.copyOf(listed(files.stream().filter(file -> !Files.isDirectory(file)).toList())); } diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/CopyValue.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/CopyValue.java index f3219a66..d29e1fd5 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/CopyValue.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/CopyValue.java @@ -4,6 +4,7 @@ import com.github.minecraft_ta.totalDebugCompanion.ui.components.FlatIconButton; import javax.swing.JButton; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; @@ -11,7 +12,7 @@ import java.awt.Dimension; import java.util.function.Consumer; -/** A readable value and an explicit copy action with local feedback. */ +/** A readable value, or a component showing one, and an explicit copy action with local feedback. */ public final class CopyValue extends JPanel { private final JLabel label = PopupElements.label(""); private final JButton copy = new FlatIconButton(Icons.COPY, false); @@ -24,6 +25,15 @@ public CopyValue(String actionName) { } CopyValue(String actionName, Consumer copyAction) { + this(actionName, copyAction, null); + } + + /** Copy beside {@code shown}, which its owner keeps up to date; {@link #setValue(String)} sets what is copied. */ + public CopyValue(String actionName, JComponent shown) { + this(actionName, PopupElements::copy, shown); + } + + private CopyValue(String actionName, Consumer copyAction, JComponent shown) { super(new BorderLayout(12, 0)); this.actionName = actionName; setOpaque(false); @@ -38,20 +48,29 @@ public CopyValue(String actionName) { }); feedback.setRepeats(false); label.setMinimumSize(new Dimension(0, label.getPreferredSize().height)); - add(label, BorderLayout.CENTER); + add(shown == null ? label : shown, BorderLayout.CENTER); add(copy, BorderLayout.EAST); setValue("", ""); } public void setValue(String display, String value) { - if (!this.value.equals(value)) resetFeedback(); - this.value = value; label.setText(display); label.setToolTipText(Tooltip.of("").text(value).html()); + setValue(value); + } + + /** What the copy action copies; hidden while it is empty. */ + public void setValue(String value) { + if (!this.value.equals(value)) resetFeedback(); + this.value = value; copy.setEnabled(!value.isEmpty()); setVisible(!value.isEmpty()); } + public String value() { + return this.value; + } + @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); // Fractional display scales can round the label's measured and painted widths differently. diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigPanel.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigPanel.java index 3c84c40d..8acf17f1 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigPanel.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigPanel.java @@ -69,6 +69,8 @@ public final class ConfigPanel extends JPanel { private final Consumer navigator; /** What the file could not show, such as a read error; it takes the place of {@link #status}. */ private String problem = ""; + /** The worlds whose copies of the file could not be listed, or empty; shown before the problem or status. */ + private String unlisted = ""; /** The outcome of the last edit, or why a typed value was refused. */ private String status = ""; @@ -150,7 +152,7 @@ private record ValuesRead(PackCatalog.ConfigFile file, ConfigValues values, Stri } /** The copies of a server configuration in the worlds. */ - private record SourcesRead(PackCatalog.ConfigFile file, List found) { + private record SourcesRead(PackCatalog.ConfigFile file, ConfigSources.Listed found) { } private void configureFiles() { @@ -324,13 +326,13 @@ private void showFile() { this.sources.cancel(); this.modifiedOnly.setVisible(file != null && !file.settings().isEmpty()); if (file == null || file.type() != PackCatalog.ConfigType.SERVER) { - showSources(file, file == null ? List.of() : ConfigSources.of(this.location, file), true); + showSources(file, file == null ? new ConfigSources.Listed(List.of(), "") : ConfigSources.of(this.location, file), true); return; } // A server configuration's copies are found by listing the worlds, which reads the disk. Until they are known, // the previous file's copies and values leave the page, so nothing can be edited into the wrong file. this.values.cancel(); - showSources(file, List.of(), false); + showSources(file, new ConfigSources.Listed(List.of(), ""), false); this.sources.load(); } @@ -342,12 +344,13 @@ private Callable prepareSources() { } /** Shows {@code file}'s copies; {@code known} tells whether they are all listed, so its values can be read. */ - private void showSources(PackCatalog.ConfigFile file, List found, boolean known) { + private void showSources(PackCatalog.ConfigFile file, ConfigSources.Listed found, boolean known) { + this.unlisted = found.problem(); this.updating = true; try { this.sourceModel.removeAllElements(); - found.forEach(this.sourceModel::addElement); - this.source.setVisible(file != null && file.type() == PackCatalog.ConfigType.SERVER && !found.isEmpty()); + found.sources().forEach(this.sourceModel::addElement); + this.source.setVisible(file != null && file.type() == PackCatalog.ConfigType.SERVER && !found.sources().isEmpty()); this.shownSource = this.source.getSelectedItem(); } finally { this.updating = false; @@ -380,7 +383,8 @@ private Callable prepareValues() { if (file == null) return null; if (path == null) { this.values.cancel(); - show(file, null, "", file.type() == PackCatalog.ConfigType.SERVER + // Where worlds could not be read, which of them has the file is not known. + show(file, null, "", !this.unlisted.isEmpty() ? "" : file.type() == PackCatalog.ConfigType.SERVER ? "No world has created this file yet. A world creates it with these defaults." : "This file does not exist yet. The game creates it with these defaults."); return null; @@ -418,7 +422,8 @@ private void setStatus(String status) { } private void showNotice() { - String text = this.problem.isEmpty() ? this.status : this.problem; + String own = this.problem.isEmpty() ? this.status : this.problem; + String text = this.unlisted.isEmpty() ? own : own.isEmpty() ? this.unlisted : this.unlisted + "; " + own; this.notice.setText(text); this.notice.setVisible(!text.isEmpty()); } diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigSettingsTable.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigSettingsTable.java index ce84aae1..de6262ac 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigSettingsTable.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigSettingsTable.java @@ -81,9 +81,15 @@ public enum ValueKind { NUMBER, BOOLEAN, STRING, CHOICE, LIST, TEXT } */ record Row(int depth, String path, String name, String comment, PackCatalog.ConfigSetting setting, String value, String literal) { + /** + * Whether the file sets a value other than the default. One it does not set is the default; an empty default is + * not told apart from an unknown one in the catalog (#56), so nothing counts as changed from it. The file sets a + * value it has a literal for, even an empty one; a file Companion cannot edit has none, and its empty values read + * as unset. + */ boolean modified() { - return this.setting != null && !this.setting.defaultValue().isEmpty() && !this.value.isEmpty() - && !this.value.equals(this.setting.defaultValue()); + return this.setting != null && (this.literal != null || !this.value.isEmpty()) + && !this.setting.defaultValue().isEmpty() && !this.value.equals(this.setting.defaultValue()); } String accepts() { @@ -387,7 +393,7 @@ static String tooltip(Row row, Effect pending, String before) { switch (setting.restart()) { case WORLD -> tooltip.fact("Takes effect", "after rejoining the world"); case GAME -> tooltip.fact("Takes effect", "after restarting the game"); - case NONE -> { + case NONE, UNKNOWN -> { } } } diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/PackConfigurationPanel.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/PackConfigurationPanel.java index 26304591..60f5c084 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/PackConfigurationPanel.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/PackConfigurationPanel.java @@ -132,7 +132,9 @@ private Loaded read(CatalogIndex index) { boolean modShown = false; for (PackCatalog.ConfigFile file : mod.configs()) { if (file.settings().isEmpty()) continue; - List sources = ConfigSources.of(this.location, file); + ConfigSources.Listed copies = ConfigSources.of(this.location, file); + if (!copies.problem().isEmpty() && !problems.contains(copies.problem())) problems.add(copies.problem()); + List sources = copies.sources(); if (sources.isEmpty()) continue; ConfigSources.Source source = sources.getFirst(); ConfigValues values; diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/FactsPanel.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/FactsPanel.java index 1e275cde..4759b74a 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/FactsPanel.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/FactsPanel.java @@ -1,5 +1,6 @@ package com.github.minecraft_ta.totalDebugCompanion.ui.components.inspection; +import com.github.minecraft_ta.totalDebugCompanion.ui.CopyValue; import com.github.minecraft_ta.totalDebugCompanion.ui.Tooltip; import com.github.minecraft_ta.totalDebugCompanion.catalog.CatalogIndex; import com.github.minecraft_ta.totalDebugCompanion.ui.UiMetrics; @@ -95,10 +96,18 @@ public record Origin(String name, Path script) { } } - /** A section, with the script that reported it or null for the page's own. */ - public record Part(FactSection section, Origin origin) { + /** + * A section, with the script that reported it or null for the page's own, and by label the whole text of facts it + * shows clipped, which a copy button beside them gives. + */ + public record Part(FactSection section, Origin origin, Map whole) { public Part { Objects.requireNonNull(section, "section"); + whole = Map.copyOf(whole); + } + + public Part(FactSection section, Origin origin) { + this(section, origin, Map.of()); } /** Names the section among all parts; data facts are named by it too. */ @@ -269,6 +278,8 @@ private final class SectionView extends JPanel { private final List labels = new ArrayList<>(); private final List slots = new ArrayList<>(); private final List values = new ArrayList<>(); + /** The copy buttons beside values the part keeps whole text for, by value. */ + private final Map copies = new HashMap<>(); private SectionHeading heading; private SectionView(Part part) { @@ -291,10 +302,11 @@ public Dimension getMaximumSize() { /** Updates the rows in place when the newer read has the same shape; returns false when it must be rebuilt. */ private boolean update(Part next) { - if (!Objects.equals(this.part.origin(), next.origin()) || !sameShape(this.part.section(), next.section())) { + if (!Objects.equals(this.part.origin(), next.origin()) || !sameShape(this.part.section(), next.section()) + || !this.part.whole().keySet().equals(next.whole().keySet())) { return false; } - updateRows(this.part.section(), next.section()); + updateRows(this.part.section(), next); this.part = next; return true; } @@ -353,7 +365,7 @@ private void build(FactSection section) { if (fact.kind() != Fact.Kind.STACK) { JComponent value = value(fact); this.values.add(value); - addRow(row++, fact.label(), value); + addRow(row++, fact.label(), copied(value, this.part, fact)); continue; } SlotCell cell = this.slots.get(slot++); @@ -425,28 +437,42 @@ private JComponent value(Fact fact) { }; } - private void updateRows(FactSection before, FactSection after) { + private void updateRows(FactSection before, Part next) { + FactSection after = next.section(); int slot = 0; int value = 0; for (int index = 0; index < after.facts().size(); index++) { Fact previous = before.facts().get(index); - Fact next = after.facts().get(index); - boolean changed = !previous.equals(next); - if (next.kind() == Fact.Kind.STACK) { - this.slots.get(slot++).set(next, changed); + Fact fact = after.facts().get(index); + boolean changed = !previous.equals(fact); + if (fact.kind() == Fact.Kind.STACK) { + this.slots.get(slot++).set(fact, changed); continue; } - switch (this.values.get(value++)) { - case ValueLabel label -> label.set(next, changed); - case AmountRow amount -> amount.set(next, changed); - case DataRow data -> data.set(next, changed); - case JLabel problem -> showProblem(problem, next.value()); + JComponent row = this.values.get(value++); + switch (row) { + case ValueLabel label -> label.set(fact, changed); + case AmountRow amount -> amount.set(fact, changed); + case DataRow data -> data.set(fact, changed); + case JLabel problem -> showProblem(problem, fact.value()); default -> { } } + CopyValue copy = this.copies.get(row); + if (copy != null) copy.setValue(next.whole().get(fact.label())); } } + /** {@code value}, with a copy button beside it where {@code part} keeps the fact's whole text. */ + private JComponent copied(JComponent value, Part part, Fact fact) { + String whole = part.whole().get(fact.label()); + if (whole == null) return value; + CopyValue copy = new CopyValue("Copy Value", value); + copy.setValue(whole); + this.copies.put(value, copy); + return copy; + } + private void reloadIcons() { this.slots.forEach(SlotCell::load); this.values.forEach(value -> { diff --git a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/ToolsMenu.java b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/ToolsMenu.java index a8e816d9..cb1a8acb 100644 --- a/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/ToolsMenu.java +++ b/companion/src/main/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/ToolsMenu.java @@ -17,8 +17,10 @@ import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.function.Consumer; /** @@ -34,23 +36,32 @@ private ToolsMenu() { static List parts(List reads, String problem) { List parts = new ArrayList<>(); if (!problem.isEmpty()) { - parts.add(new FactsPanel.Part(new FactSection("Tools", List.of(Fact.problem("Status", Fact.clip(problem))), 1), null)); + Map whole = new HashMap<>(); + parts.add(new FactsPanel.Part(new FactSection("Tools", List.of(Fact.problem("Status", shown(whole, "Status", problem))), 1), + null, whole)); return parts; } for (InspectionSession.ToolRead read : reads) { FactsPanel.Origin origin = new FactsPanel.Origin(read.tool().name(), read.tool().path()); for (FactSection section : read.sections()) parts.add(new FactsPanel.Part(section, origin)); List status = new ArrayList<>(); - if (!read.failure().isEmpty()) status.add(Fact.problem("Status", Fact.clip(read.failure()))); + Map whole = new HashMap<>(); + if (!read.failure().isEmpty()) status.add(Fact.problem("Status", shown(whole, "Status", read.failure()))); else if (read.sections().isEmpty()) status.add(Fact.text("Status", read.running() ? "Running…" : "No sections reported")); - if (!read.output().isEmpty()) status.add(Fact.text("Output", Fact.clip(read.output()))); + if (!read.output().isEmpty()) status.add(Fact.text("Output", shown(whole, "Output", read.output()))); if (!status.isEmpty()) { - parts.add(new FactsPanel.Part(new FactSection(read.tool().name(), status, status.size()), origin)); + parts.add(new FactsPanel.Part(new FactSection(read.tool().name(), status, status.size()), origin, whole)); } } return parts; } + /** {@code text} as a fact shows it, clipped, keeping the whole of it in {@code whole} for its copy button. */ + private static String shown(Map whole, String label, String text) { + whole.put(label, text); + return Fact.clip(text); + } + /** The Tools menu: tools running with every inspection of the subject, other scripts to run here, and a new tool. */ static JPopupMenu menu(InspectionSession session, JComponent owner, Consumer navigator) { JPopupMenu menu = new JPopupMenu(); diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiDevHarness.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiDevHarness.java index c7089403..1ce670ef 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiDevHarness.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiDevHarness.java @@ -1,5 +1,7 @@ package com.github.minecraft_ta.totalDebugCompanion; +import java.util.stream.Stream; +import com.github.minecraft_ta.totaldebug.storage.PackCatalog; import com.github.minecraft_ta.totalDebugCompanion.model.OpenedTabs; import javax.swing.JLabel; @@ -162,9 +164,23 @@ private static void installCatalogFixture(Path root) throws Exception { Path recipe = Files.createDirectories(tweaks.resolve("data/tweaks/recipe")).resolve("widget_from_goo.json"); Files.writeString(recipe, "{\"type\":\"minecraft:crafting_shapeless\",\"ingredients\":[],\"result\":{\"id\":\"testmod:widget\"}}"); LevelDatFixture.datapack(world, "Structures"); + // The test mod also keeps a server configuration, which each world holds a copy of, with the defaults for new ones. + Files.writeString(Files.createDirectories(world.resolve("serverconfig")).resolve("testmod-server.toml"), + "[rules]\n\tlimit = 64\n"); + Files.writeString(Files.createDirectories(scope.profile().workspaceDirectory().resolve("defaultconfigs")) + .resolve("testmod-server.toml"), "[rules]\n\tlimit = 64\n"); + PackCatalog fixture = CatalogFixtures.catalog(jar); + PackCatalog.ConfigFile server = new PackCatalog.ConfigFile("testmod-server.toml", PackCatalog.ConfigType.SERVER, null, + List.of(), List.of(new PackCatalog.ConfigSetting("rules.limit", "How many widgets a world allows", "64", + "1 ~ 1024", List.of(), PackCatalog.Restart.WORLD))); + List mods = fixture.mods().stream().map(mod -> !mod.id().equals("testmod") ? mod + : new PackCatalog.Mod(mod.id(), mod.name(), mod.version(), mod.description(), mod.authors(), mod.license(), + mod.urls(), mod.logo(), mod.module(), mod.file(), mod.dependencies(), + Stream.concat(mod.configs().stream(), Stream.of(server)).toList())).toList(); Path file = scope.paths().catalog(); Files.createDirectories(file.getParent()); - CatalogFixtures.catalog(jar).write(file); + new PackCatalog(fixture.inventoryId(), fixture.language(), mods, fixture.registries(), fixture.itemAppearances(), + fixture.keyBindings(), fixture.keyContexts(), fixture.keyNames()).write(file); scope.catalog().accept(CatalogFixtures.INVENTORY, file, Runnable::run); } diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiRenderScenario.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiRenderScenario.java index 55b78f52..74253b09 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiRenderScenario.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiRenderScenario.java @@ -54,6 +54,7 @@ enum UiRenderScenario { INDEXING("indexing", "Runtime index activity in the status bar"), MOD_PAGE("mod-page", "Mod page overview with its logo, facts and dependencies"), MOD_CONFIGURATION("mod-configuration", "Configuration settings with a modified value"), + CONFIGURATION_UNLISTED("configuration-unlisted", "A server configuration whose worlds could not be listed, the defaults shown"), MOD_RESOURCES("mod-resources", "Mod resources listed by category"), DEFINITION_PAGE("definition-page", "Block definition page with its files"), PACK_CONFIGURATION("pack-configuration", "Every setting of the pack under its mod and file, one of them modified"), @@ -76,7 +77,8 @@ enum UiRenderScenario { PACK_ORDER("pack-order", "The resource packs with a pack enabled at the top, waiting for Apply"), SAVE_INTO("save-into", "A mod's model open for editing with the pack it is saved into"), TEXTURE_EDITOR("texture-editor", "A resource pack's texture with the pencil chosen and a stroke drawn and saved"), - INSPECTION("inspection", "A block read from the game with storage that differs by face"); + INSPECTION("inspection", "A block read from the game with storage that differs by face"), + INSPECTION_TOOL_OUTPUT("inspection-tool-output", "A tool's failure and output too long to show whole, each with its copy button"); private final String id; private final String description; diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiScenarioDriver.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiScenarioDriver.java index d0256403..32cf51ca 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiScenarioDriver.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/UiScenarioDriver.java @@ -1,5 +1,11 @@ package com.github.minecraft_ta.totalDebugCompanion; +import com.github.minecraft_ta.totalDebugCompanion.inspection.InspectionTool; +import com.github.minecraft_ta.totalDebugCompanion.inspection.InspectionSession; +import java.util.Map; +import java.util.LinkedHashMap; +import java.lang.reflect.Method; +import java.lang.reflect.Field; import com.github.minecraft_ta.totalDebugCompanion.storage.ChangeRecord; import com.github.minecraft_ta.totalDebugCompanion.ui.HtmlText; import com.github.minecraft_ta.totalDebugCompanion.catalog.RegistryIds; @@ -648,11 +654,12 @@ private void advance(UiRenderScenario scenario, ScenarioContext context) throws } navigate(new NavigationTarget.World(WorldTab.OVERVIEW)); }); - case INSPECTION -> { + case INSPECTION, INSPECTION_TOOL_OUTPUT -> { context.once("inspection", () -> navigate(new NavigationTarget.Inspection(InspectionSample.SUBJECT))); SubjectPanel panel = findComponent(mainWindow, SubjectPanel.class); if (panel != null) { context.once("inspection-read", () -> panel.session().present(InspectionSample.read(), null, text -> text)); + if (scenario == UiRenderScenario.INSPECTION_TOOL_OUTPUT) context.once("inspection-tool", () -> finishTool(panel.session())); } } case CHANGES -> context.once("changes", () -> { @@ -667,6 +674,17 @@ private void advance(UiRenderScenario scenario, ScenarioContext context) throws }); case MOD_CONFIGURATION -> context.once("mod-configuration", () -> navigate(new NavigationTarget.ModPage("testmod", ModTab.CONFIGURATION, ""))); + case CONFIGURATION_UNLISTED -> context.once("configuration-unlisted", () -> { + Path saves = mainWindow.editorContext().project().profile().workspaceDirectory().resolve("saves"); + try { + // A file where the saves folder belongs cannot be listed. + Files.move(saves, saves.resolveSibling("saves-moved")); + Files.writeString(saves, ""); + } catch (IOException exception) { + throw new UncheckedIOException(exception); + } + navigate(new NavigationTarget.ModPage("testmod", ModTab.CONFIGURATION, "testmod-server.toml")); + }); case MOD_RESOURCES -> context.once("mod-resources", () -> navigate(new NavigationTarget.ModPage("testmod", ModTab.RESOURCES, ""))); case DEFINITION_PAGE -> context.once("definition-page", () -> navigate(new NavigationTarget.Definition( @@ -720,6 +738,26 @@ private void playOnServer(String refusal) { project.packs().datapacks("", new PackStackPayload(48, enabled, others), refusal); } + /** A tool run that failed after writing much output; tool runs need the game, so the session is told directly. */ + private static void finishTool(InspectionSession session) { + InspectionTool tool = new InspectionTool(Path.of("tools", "FurnaceTool.tdscript"), "FurnaceTool", "", List.of("testmod:*")); + try { + Field reads = InspectionSession.class.getDeclaredField("toolReads"); + reads.setAccessible(true); + Map running = new LinkedHashMap<>(); + running.put(tool.path(), new InspectionSession.ToolRead(tool, true, List.of(), "", "")); + reads.set(session, running); + Method finish = InspectionSession.class.getDeclaredMethod("finishTool", InspectionTool.class, List.class, + String.class, String.class); + finish.setAccessible(true); + finish.invoke(session, tool, List.of(), "Burn time left: 1,200 ticks; fuel: coal, 8 items; ".repeat(8).strip(), + "java.lang.IllegalStateException: The furnace at 12, 64, -3 has no recipe for its input, " + + "so its progress cannot be read".repeat(4)); + } catch (ReflectiveOperationException failure) { + throw new IllegalStateException(failure); + } + } + private boolean showsMessage(String text) { return mainWindow.getEditorTabs().getSelectedEditor() != null && findComponents(mainWindow, JLabel.class).stream() .anyMatch(label -> label.isShowing() && label.getText() != null && label.getText().startsWith(text)); @@ -790,6 +828,8 @@ private boolean ready(UiRenderScenario scenario, ScenarioContext context) { case DEFINITION_PAGE -> mainWindow.getEditorTabs().getSelectedEditor() instanceof DefinitionView view && "Widget Block".equals(view.getTitle()); case INSPECTION -> context.completedActions.contains("inspection-read"); + case INSPECTION_TOOL_OUTPUT -> context.completedActions.contains("inspection-tool"); + case CONFIGURATION_UNLISTED -> showsMessage("Could not read the saves folder"); case TAB_MENU -> visibleMenuPopup() != null && mainWindow.getEditorTabs().getSelectedIndex() == mainWindow.getEditorTabs().getTabCount() - 1; case TAB_REVEAL -> { diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigChangesTest.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigChangesTest.java index c9050b9b..a72856ba 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigChangesTest.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigChangesTest.java @@ -85,6 +85,17 @@ void aRunningGameReloadsFilesAndWaitsForARestartWhereTheSettingSaysSo() { assertNull(changes.pending(config(), "speed")); } + @Test + void aSettingNoSpecificationDescribesIsNotSaidToBeUsedAtOnce() { + ConfigChanges changes = new ConfigChanges(this.location, ChangeRecord.inMemory()); + assertEquals(Effect.GAME_STARTS, edit(changes, config(), PackCatalog.Restart.UNKNOWN, "1", "2")); + + this.location.connected(message -> true); + assertEquals(Effect.UNDESCRIBED, edit(changes, config(), PackCatalog.Restart.UNKNOWN, "2", "3")); + assertNull(changes.pending(config(), "speed")); + assertEquals(PackCatalog.Restart.UNKNOWN, PackCatalog.ConfigSetting.undescribed("widgets.speed", "").restart()); + } + @Test void editsWaitingForARestartOutlastAReconnectToTheSameGame() throws Exception { ConfigChanges changes = new ConfigChanges(this.location, ChangeRecord.inMemory()); diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigEditTest.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigEditTest.java index 9b6eb81a..690bf743 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigEditTest.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/catalog/ConfigEditTest.java @@ -76,6 +76,11 @@ void typedValuesBecomeLiteralsOfTheSettingsKind() { assertEquals("2.0", ConfigEdit.literal("0.5", setting("0.0 ~ 4.0", List.of()), "2")); assertEquals("Accepts at least 1", assertThrows(IllegalArgumentException.class, () -> ConfigEdit.literal("5", setting("> 1", List.of()), "0")).getMessage()); + // An int's limit reads as no bound, but a long ranged to it refuses a larger value, and the refusal names it. + assertEquals("Accepts at most 2147483647", assertThrows(IllegalArgumentException.class, + () -> ConfigEdit.literal("5", setting("0 ~ 2147483647", List.of()), "3000000000")).getMessage()); + assertEquals("Accepts at least 0", assertThrows(IllegalArgumentException.class, + () -> ConfigEdit.literal("5", setting("0 ~ 2147483647", List.of()), "-1")).getMessage()); assertEquals("false", ConfigEdit.literal("true", null, "False")); assertThrows(IllegalArgumentException.class, () -> ConfigEdit.literal("true", null, "yes")); diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/search/everywhere/CatalogSearchTest.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/search/everywhere/CatalogSearchTest.java index 4bbe9c7a..6767e763 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/search/everywhere/CatalogSearchTest.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/search/everywhere/CatalogSearchTest.java @@ -21,6 +21,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.zip.ZipOutputStream; +import java.util.zip.ZipEntry; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -86,6 +88,22 @@ void searchesResourcePathsOnlyInTheirCategory() throws Exception { assertTrue(search.search(null, catalog, "widget.png", Category.ALL, 20, null, null).isEmpty()); } + @Test + void aResourceBelongsToTheModWhoseFileHoldsItWhateverItsNamespace() throws Exception { + Path jar = this.directory.resolve("testmod.jar"); + try (ZipOutputStream zip = new ZipOutputStream(Files.newOutputStream(jar))) { + zip.putNextEntry(new ZipEntry("assets/c/textures/item/shared_gear.png")); + zip.closeEntry(); + } + CatalogSearch catalog = new CatalogSearch(new CatalogIndex(CatalogFixtures.catalog(jar)), null); + SearchEverywhereSearch search = new SearchEverywhereSearch(); + + ResourceResult found = assertInstanceOf(ResourceResult.class, + search.search(null, catalog, "shared_gear", Category.RESOURCES, 20, null, Set.of("testmod")).getFirst()); + assertEquals("Test Mod", found.owner()); + assertTrue(search.search(null, catalog, "shared_gear", Category.RESOURCES, 20, null, Set.of("minecraft+neoforge")).isEmpty()); + } + @Test void theBestMatchesAreKeptWhenMoreMatchThanTheLimit() throws Exception { List items = new ArrayList<>(); diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigPanelTest.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigPanelTest.java index a9660dea..1d80c06e 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigPanelTest.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/categories/configuration/ConfigPanelTest.java @@ -333,6 +333,44 @@ private static T find(Container root, Class type, Strin return null; } + @Test + void worldsThatCannotBeListedAreNamedBesideWhatAnEditSays() throws Exception { + Path defaults = Files.createDirectories(this.directory.resolve("defaultconfigs")).resolve(FILE.fileName()); + Files.writeString(defaults, "[widgets]\n\tspeed = 9\n"); + Files.writeString(this.directory.resolve("saves"), ""); + String unlisted = ConfigSources.of(GameLocations.of(this.directory, false), FILE).problem(); + ConfigPanel[] panel = new ConfigPanel[1]; + SwingUtilities.invokeAndWait(() -> { + panel[0] = new ConfigPanel("testmod", ConfigSettingsFixture.of(GameLocations.of(this.directory, false), ChangeRecord.inMemory()), target -> { }); + panel[0].setFiles(List.of(FILE)); + UiTestScope.showPages(panel[0]); + }); + ConfigSettingsTable table = component(panel[0], ConfigSettingsTable.class); + awaitOnSwing(() -> table.getRowCount() == 4 && "9".equals(table.row(1).value())); + component(panel[0], JLabel.class, unlisted); + + SwingUtilities.invokeAndWait(() -> { + assertTrue(table.edit(1)); + ((JTextField) table.getEditorComponent()).setText("20"); + assertFalse(table.getCellEditor().stopCellEditing()); + component(panel[0], JLabel.class, unlisted + "; speed: Accepts 1 to 16"); + }); + } + + @Test + void anEmptyValueTheFileSetsIsChangedFromItsDefault() throws Exception { + List rows = ConfigSettingsTable.rows(FILE, ConfigValues.parse(""" + [widgets] + mode = "" + """, FILE.fileName())); + + assertTrue(rows.get(2).modified(), "the file sets mode to an empty value"); + assertFalse(rows.get(1).modified(), "speed is not in the file, so it is the default"); + PackCatalog.ConfigSetting speed = FILE.settings().getFirst(); + assertTrue(new ConfigSettingsTable.Row(1, speed.path(), speed.name(), "", speed, "9", null).modified(), + "a file Companion cannot edit has no literals, and its values still count"); + } + @Test void aMissingFileShowsTheDefaults() { List rows = ConfigSettingsTable.rows(FILE, null); @@ -349,7 +387,21 @@ void serverConfigurationsComeFromEachWorldNewestFirstThenTheDefaults() throws Ex Files.writeString(defaults, ""); assertEquals(List.of(new ConfigSources.Source("New World", newer), new ConfigSources.Source("Old World", older), - new ConfigSources.Source("New worlds", defaults)), ConfigSources.of(GameLocations.of(this.directory, false), FILE)); + new ConfigSources.Source("New worlds", defaults)), ConfigSources.of(GameLocations.of(this.directory, false), FILE).sources()); + } + + @Test + void worldsThatCannotBeListedAreNamedAndTheDefaultsStillListed() throws Exception { + Path defaults = Files.createDirectories(this.directory.resolve("defaultconfigs")).resolve(FILE.fileName()); + Files.writeString(defaults, ""); + assertEquals(new ConfigSources.Listed(List.of(new ConfigSources.Source("New worlds", defaults)), ""), + ConfigSources.of(GameLocations.of(this.directory, false), FILE), "no saves folder is no world"); + + Files.writeString(this.directory.resolve("saves"), ""); + ConfigSources.Listed listed = ConfigSources.of(GameLocations.of(this.directory, false), FILE); + + assertEquals(List.of(new ConfigSources.Source("New worlds", defaults)), listed.sources()); + assertTrue(listed.problem().startsWith("Could not read the saves folder ("), listed.problem()); } @Test @@ -360,7 +412,7 @@ void theOpenWorldsServerConfigurationComesFirst() throws Exception { StandardOpenOption.CREATE, StandardOpenOption.WRITE); FileLock ignored = channel.lock()) { assertEquals(List.of(new ConfigSources.Source("Open World", open), new ConfigSources.Source("New World", newer)), - ConfigSources.of(GameLocations.of(this.directory, true), FILE), "an edit is meant for the world the game has open"); + ConfigSources.of(GameLocations.of(this.directory, true), FILE).sources(), "an edit is meant for the world the game has open"); } } diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/FactsPanelTest.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/FactsPanelTest.java index b61644c5..1f8a807e 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/FactsPanelTest.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/FactsPanelTest.java @@ -1,6 +1,7 @@ package com.github.minecraft_ta.totalDebugCompanion.ui.components.inspection; import com.github.minecraft_ta.totalDebugCompanion.inspection.ItemIconService; +import com.github.minecraft_ta.totalDebugCompanion.ui.CopyValue; import com.github.minecraft_ta.totaldebug.protocol.execution.Fact; import com.github.minecraft_ta.totaldebug.protocol.execution.FactSection; import org.junit.jupiter.api.Test; @@ -10,8 +11,10 @@ import java.awt.Component; import java.awt.Container; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -90,6 +93,37 @@ void suggestsAToolNameFromTheRegistryPath() { assertEquals("Tool2x2DoorTool", ToolsMenu.suggestedName("example:2x2_door")); } + @Test + void aClippedValueCopiesItsWholeTextAlsoAfterAnUpdate() throws Exception { + String output = "x".repeat(300); + String later = "y".repeat(300); + List copied = new ArrayList<>(); + try (ItemIconService icons = new ItemIconService()) { + SwingUtilities.invokeAndWait(() -> { + FactsPanel panel = new FactsPanel(List.of(tool(output)), icons, FactsPanel.Actions.NONE, new HashSet<>()); + copies(panel, copied); + assertTrue(panel.update(List.of(tool(later)))); + copies(panel, copied); + }); + } + + assertEquals(List.of(output, output, later, later), copied, "a value shown whole has no copy button"); + } + + private static FactsPanel.Part tool(String text) { + FactSection section = new FactSection("Tool", List.of(Fact.problem("Status", Fact.clip(text)), + Fact.text("Output", Fact.clip(text)), Fact.text("Plain", "short")), 3); + return new FactsPanel.Part(section, null, Map.of("Status", text, "Output", text)); + } + + /** What each row's copy button copies, in order. */ + private static void copies(Container container, List copied) { + for (Component child : container.getComponents()) { + if (child instanceof CopyValue copy) copied.add(copy.value()); + if (child instanceof Container nested) copies(nested, copied); + } + } + private static void collect(Container container, List labels, List bars) { for (Component child : container.getComponents()) { if (child instanceof JLabel label) labels.add(label.getText()); diff --git a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/SubjectPanelTest.java b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/SubjectPanelTest.java index f5b94f95..4887fda3 100644 --- a/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/SubjectPanelTest.java +++ b/companion/src/test/java/com/github/minecraft_ta/totalDebugCompanion/ui/components/inspection/SubjectPanelTest.java @@ -204,7 +204,7 @@ void aToolsSectionsFollowTheBuiltInOnesAndItsStatusOnlyShowsWhenThereIsSomething assertEquals(List.of(new FactsPanel.Part(burn, origin)), finished); assertEquals("FurnaceTool › Burning", finished.getFirst().key()); assertEquals(List.of(new FactsPanel.Part(new FactSection("FurnaceTool", - List.of(Fact.problem("Status", failure)), 1), origin)), failed); + List.of(Fact.problem("Status", failure)), 1), origin, Map.of("Status", failure))), failed); } private static ExecutionResult completed(List facts) { diff --git a/storage/src/main/java/com/github/minecraft_ta/totaldebug/storage/PackCatalog.java b/storage/src/main/java/com/github/minecraft_ta/totaldebug/storage/PackCatalog.java index e6901381..35bec48b 100644 --- a/storage/src/main/java/com/github/minecraft_ta/totaldebug/storage/PackCatalog.java +++ b/storage/src/main/java/com/github/minecraft_ta/totaldebug/storage/PackCatalog.java @@ -48,8 +48,11 @@ public record PackCatalog( private static final Pattern KEY = Pattern.compile("[a-z][a-z0-9_]*"); public enum ConfigType { COMMON, CLIENT, SERVER, STARTUP } - /** What must restart before a changed setting takes effect. */ - public enum Restart { NONE, WORLD, GAME } + /** + * What must restart before a changed setting takes effect; {@code UNKNOWN} for a setting no specification describes, + * which only Companion makes. + */ + public enum Restart { NONE, WORLD, GAME, UNKNOWN } public enum DependencyType { REQUIRED, OPTIONAL, INCOMPATIBLE, DISCOURAGED } public enum Side { CLIENT, SERVER, BOTH } @@ -127,6 +130,11 @@ public record ConfigSetting(String path, String comment, String defaultValue, St Objects.requireNonNull(restart, "restart of " + path); } + /** A setting found in a file that no specification describes, so when the game uses a change is unknown. */ + public static ConfigSetting undescribed(String path, String comment) { + return new ConfigSetting(path, comment, "", "", List.of(), Restart.UNKNOWN); + } + /** The last part of the path, such as {@code maxEnergy} for {@code machines.maxEnergy}. */ public String name() { return this.path.substring(this.path.lastIndexOf('.') + 1);