diff --git a/build.gradle b/build.gradle index a639c544..ae68c867 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ subprojects { dependencies { implementation 'com.google.guava:guava:32.1.2-jre' implementation 'com.google.code.gson:gson:2.10.1' - implementation 'net.fabricmc:mapping-io:0.5.0' + implementation 'net.fabricmc:mapping-io:0.6.1' compileOnly 'org.jetbrains:annotations:24.0.1' diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index 35129799..d7054f78 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -405,16 +405,21 @@ private void onGithubClicked() { private static void prepareOpenMappingsMenu(JMenu openMappingsMenu, Gui gui) { // Mapping-IO readers - MappingFormat.getReadableFormats().stream() - .filter(format -> format.getMappingIoCounterpart() != null) - .forEach(format -> addOpenMappingsMenuEntry(I18n.translate(format.getMappingIoCounterpart().name), - format, true, openMappingsMenu, gui)); + for (MappingFormat format : MappingFormat.values()) { + if (format.getMappingIoCounterpart() != null) { + addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), + format, true, openMappingsMenu, gui); + } + } + openMappingsMenu.addSeparator(); // Enigma's own readers + String legacySuffix = " (" + I18n.translate("legacy") + ")"; + for (MappingFormat format : MappingFormat.values()) { if (format.getReader() != null) { - addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + " (legacy)", + addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + legacySuffix, format, false, openMappingsMenu, gui); } } @@ -437,16 +442,21 @@ private static void addOpenMappingsMenuEntry(String text, MappingFormat format, private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { // Mapping-IO writers - MappingFormat.getWritableFormats().stream() - .filter(format -> format.hasMappingIoWriter()) - .forEach(format -> addSaveMappingsAsMenuEntry(format.getMappingIoCounterpart().name, - format, true, saveMappingsAsMenu, saveMappingsItem, gui)); + for (MappingFormat format : MappingFormat.values()) { + if (format.hasMappingIoWriter()) { + addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), + format, true, saveMappingsAsMenu, saveMappingsItem, gui); + } + } + saveMappingsAsMenu.addSeparator(); // Enigma's own writers + String legacySuffix = " (" + I18n.translate("legacy") + ")"; + for (MappingFormat format : MappingFormat.values()) { if (format.getWriter() != null) { - addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + " (legacy)", + addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + legacySuffix, format, false, saveMappingsAsMenu, saveMappingsItem, gui); } } diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java index c9707b9c..bb70c04e 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java @@ -34,18 +34,20 @@ import cuchaz.enigma.utils.I18n; public enum MappingFormat { - ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE, FileType.MAPPING, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_FILE, true), - ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY, FileType.DIRECTORY, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_DIR, true), - ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP, FileType.ZIP, null, false), - TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE, true), - TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE, true), - SRG_FILE(SrgMappingsWriter.INSTANCE, null, FileType.SRG, net.fabricmc.mappingio.format.MappingFormat.SRG_FILE, true), - XSRG_FILE(null, null, FileType.XSRG, net.fabricmc.mappingio.format.MappingFormat.XSRG_FILE, true), - CSRG_FILE(null, null, FileType.CSRG, net.fabricmc.mappingio.format.MappingFormat.CSRG_FILE, false), - TSRG_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_FILE, false), - TSRG_2_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_2_FILE, false), - PROGUARD(null, ProguardMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.PROGUARD_FILE, true), - RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, FileType.TXT, null, false); + ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE, FileType.MAPPING, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_FILE), + ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY, FileType.DIRECTORY, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_DIR), + ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP, FileType.ZIP, null), + TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE), + TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE), + SRG_FILE(SrgMappingsWriter.INSTANCE, null, FileType.SRG, net.fabricmc.mappingio.format.MappingFormat.SRG_FILE), + XSRG_FILE(null, null, FileType.XSRG, net.fabricmc.mappingio.format.MappingFormat.XSRG_FILE), + JAM_FILE(null, null, FileType.JAM, net.fabricmc.mappingio.format.MappingFormat.JAM_FILE), + CSRG_FILE(null, null, FileType.CSRG, net.fabricmc.mappingio.format.MappingFormat.CSRG_FILE), + TSRG_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_FILE), + TSRG_2_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_2_FILE), + PROGUARD(null, ProguardMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.PROGUARD_FILE), + RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.RECAF_SIMPLE_FILE), + JOBF_FILE(null, null, FileType.JOBF, net.fabricmc.mappingio.format.MappingFormat.JOBF_FILE); private final MappingsWriter writer; private final MappingsReader reader; @@ -54,12 +56,12 @@ public enum MappingFormat { private final boolean hasMappingIoWriter; private boolean usedMappingIoWriterLast; - MappingFormat(MappingsWriter writer, MappingsReader reader, FileType fileType, net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart, boolean hasMappingIoWriter) { + MappingFormat(MappingsWriter writer, MappingsReader reader, FileType fileType, net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart) { this.writer = writer; this.reader = reader; this.fileType = fileType; this.mappingIoCounterpart = mappingIoCounterpart; - this.hasMappingIoWriter = hasMappingIoWriter; + this.hasMappingIoWriter = mappingIoCounterpart == null ? false : mappingIoCounterpart.hasWriter; } public void write(EntryTree mappings, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { @@ -67,11 +69,7 @@ public void write(EntryTree mappings, Path path, ProgressListener } public void write(EntryTree mappings, MappingDelta delta, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { - if (!hasMappingIoWriter || !useMappingIo()) { - if (writer == null) { - throw new IllegalStateException(name() + " does not support writing"); - } - + if (!hasMappingIoWriter || (!useMappingIo() && writer != null)) { writer.write(mappings, usedMappingIoWriterLast ? MappingDelta.added(mappings) : delta, path, progressListener, saveParameters); usedMappingIoWriterLast = false; return; @@ -105,11 +103,7 @@ public EntryTree read(Path path, ProgressListener progressListener } public EntryTree read(Path path, ProgressListener progressListener, MappingSaveParameters saveParameters, JarIndex index) throws IOException, MappingParseException { - if (!useMappingIo()) { - if (reader == null) { - throw new IllegalStateException(name() + " does not support reading"); - } - + if (mappingIoCounterpart == null || (!useMappingIo() && reader != null)) { return reader.read(path, progressListener, saveParameters); } @@ -178,22 +172,18 @@ public boolean isWritable() { return writer != null || hasMappingIoWriter; } - @ApiStatus.Internal private boolean useMappingIo() { - if (mappingIoCounterpart == null) return false; return System.getProperty("enigma.use_mappingio", "true").equals("true"); } public static List getReadableFormats() { - return Arrays.asList(values()) - .stream() + return Arrays.stream(values()) .filter(MappingFormat::isReadable) .toList(); } public static List getWritableFormats() { - return Arrays.asList(values()) - .stream() + return Arrays.stream(values()) .filter(MappingFormat::isWritable) .toList(); } @@ -209,14 +199,16 @@ public static List getWritableFormats() { @ApiStatus.Internal public record FileType(List extensions) { public static final FileType DIRECTORY = new FileType(); + public static final FileType ZIP = new FileType(".zip"); public static final FileType MAPPING = new FileType(".mapping", ".mappings"); + public static final FileType TINY = new FileType(".tiny"); public static final FileType SRG = new FileType(".srg"); public static final FileType XSRG = new FileType(".xsrg"); + public static final FileType JAM = new FileType(".jam"); public static final FileType CSRG = new FileType(".csrg"); public static final FileType TSRG = new FileType(".tsrg"); - public static final FileType TINY = new FileType(".tiny"); public static final FileType TXT = new FileType(".txt"); - public static final FileType ZIP = new FileType(".zip"); + public static final FileType JOBF = new FileType(".jobf"); public FileType(String... extensions) { this(List.of(extensions)); diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index 42228144..b939e551 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json @@ -4,11 +4,19 @@ "mapping_format.enigma_file": "Enigma File", "mapping_format.enigma_directory": "Enigma Directory", "mapping_format.enigma_zip": "Enigma ZIP", - "mapping_format.tiny_v2": "Tiny v2", + "mapping_format.tiny_v2": "Tiny v2 File", "mapping_format.tiny_file": "Tiny File", "mapping_format.srg_file": "SRG File", - "mapping_format.proguard": "Proguard", - "mapping_format.recaf": "Recaf", + "mapping_format.xsrg_file": "XSRG File", + "mapping_format.jam_file": "JAM File", + "mapping_format.csrg_file": "CSRG File", + "mapping_format.tsrg_file": "TSRG File", + "mapping_format.tsrg_2_file": "TSRG v2 File", + "mapping_format.proguard": "ProGuard File", + "mapping_format.recaf": "Recaf Simple File", + "mapping_format.jobf_file": "JOBF File", + "legacy": "legacy", + "type.methods": "Methods", "type.fields": "Fields", "type.parameters": "Parameters",