mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Autocomplete more command parameters
- Suggest pack folders for pack validate, cleanup, restore, status and compat - Suggest preview and apply for pack restore mode - Suggest versions and installed datapack ids for datapack export and remove - Suggest structure keys for structure info, place, jigsaw convert and adopt inspect - Suggest workcell ids for jigsaw save and goto - Suggest formats for jigsaw export - Suggest subterrain families, marker keys and world slots
This commit is contained in:
1 parent
cdb4e68708
commit
a1bf501c30
19 files changed
+239
-25
No files matched your search
@@ -0,0 +1,18 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportTargets;
|
||||
|
||||
public final class ExportVersionHandler extends FixedChoiceHandler {
|
||||
public ExportVersionHandler() {
|
||||
super(WorldgenExportTargets.SUPPORTED.stream().map(DataVersion::getVersion).toArray(String[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String canonicalize(String input) {
|
||||
if (input == null || input.isBlank()) {
|
||||
return "";
|
||||
}
|
||||
return WorldgenExportTargets.resolve(input).getVersion();
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.pack.datapack.DatapackIngestService;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public final class InstalledDatapackHandler extends OpenSuggestionHandler {
|
||||
@Override
|
||||
protected Collection<String> suggestions() {
|
||||
return DatapackIngestService.installed().stream().map(entry -> entry.id).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public final class MarkerHandler extends OpenSuggestionHandler {
|
||||
@Override
|
||||
protected Collection<String> suggestions() {
|
||||
Engine activeEngine = engine();
|
||||
if (activeEngine == null || activeEngine.getData() == null) {
|
||||
return List.of();
|
||||
}
|
||||
return Arrays.stream(activeEngine.getData().getMarkerLoader().getPossibleKeys()).sorted().toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.command.DirectorParameterHandler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class OpenSuggestionHandler implements DirectorParameterHandler<String> {
|
||||
protected abstract Collection<String> suggestions();
|
||||
|
||||
@Override
|
||||
public KList<String> getPossibilities() {
|
||||
return new KList<>(suggestions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(String input, boolean force) {
|
||||
return input == null ? "" : input.trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> type) {
|
||||
return type == String.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.pack.PackDirectoryResolver;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
public class PackFolderHandler extends OpenSuggestionHandler {
|
||||
@Override
|
||||
protected Collection<String> suggestions() {
|
||||
return PackDirectoryResolver.listVisiblePackDirectories(IrisPlatforms.get().packsFolder())
|
||||
.stream()
|
||||
.map(File::getName)
|
||||
.sorted()
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public final class PackFolderOrAllHandler extends PackFolderHandler {
|
||||
private static final String ALL_PACKS = "*";
|
||||
|
||||
@Override
|
||||
protected Collection<String> suggestions() {
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add(ALL_PACKS);
|
||||
options.addAll(super.suggestions());
|
||||
return options;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -2,8 +2,8 @@ package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class CleanupModeHandler extends FixedChoiceHandler {
|
||||
public CleanupModeHandler() {
|
||||
public final class PreviewApplyModeHandler extends FixedChoiceHandler {
|
||||
public PreviewApplyModeHandler() {
|
||||
super("preview", "apply");
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public final class CleanupModeHandler extends FixedChoiceHandler {
|
||||
protected String canonicalize(String input) {
|
||||
String mode = input.trim().toLowerCase(Locale.ROOT);
|
||||
if (!mode.equals("preview") && !mode.equals("apply")) {
|
||||
throw new IllegalArgumentException("Cleanup mode must be preview or apply.");
|
||||
throw new IllegalArgumentException("Mode must be preview or apply.");
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public final class RegisteredStructureKeyHandler extends OpenSuggestionHandler {
|
||||
@Override
|
||||
protected Collection<String> suggestions() {
|
||||
return IrisPlatforms.get().structureHooks().structureKeys().stream().sorted().toList();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.generation.subterrain.IrisSubterrainFamily;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class SubterrainFeatureHandler extends OpenSuggestionHandler {
|
||||
@Override
|
||||
protected Collection<String> suggestions() {
|
||||
return Arrays.stream(IrisSubterrainFamily.values())
|
||||
.map(family -> family.name().toLowerCase(Locale.ROOT))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
+11
-2
@@ -26,10 +26,19 @@ public class FixedChoiceHandlerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanupModeSuggestsAndRejectsUnknownModes() throws Exception {
|
||||
CleanupModeHandler handler = new CleanupModeHandler();
|
||||
public void previewApplyModeSuggestsAndRejectsUnknownModes() throws Exception {
|
||||
PreviewApplyModeHandler handler = new PreviewApplyModeHandler();
|
||||
assertEquals(List.of("preview", "apply"), handler.getPossibilities());
|
||||
assertEquals("apply", handler.parse("Apply", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("delete", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportVersionKeepsBlankAsLatestAndRejectsOlderTargets() throws Exception {
|
||||
ExportVersionHandler handler = new ExportVersionHandler();
|
||||
assertEquals(List.of("26.3"), handler.getPossibilities());
|
||||
assertEquals("", handler.parse("", false));
|
||||
assertEquals("26.3", handler.parse("26.3.0", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("26.2", false));
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class OpenSuggestionHandlerTest {
|
||||
@Test
|
||||
public void subterrainSuggestsFamiliesButAcceptsFeatureIds() {
|
||||
SubterrainFeatureHandler handler = new SubterrainFeatureHandler();
|
||||
assertEquals(List.of("tectonic_fault", "cenote", "lava_tube", "travertine_terraces"), handler.getPossibilities());
|
||||
assertEquals("my_feature:room", handler.parse(" my_feature:room ", false));
|
||||
assertEquals("", handler.parse(null, false));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user