diff options
| author | 2024-08-27 16:22:02 +0200 | |
|---|---|---|
| committer | 2024-08-27 15:22:02 +0100 | |
| commit | c2ce8897a5ebe3b74d3995d4ccc4c0c277e44247 (patch) | |
| tree | 4dab9e6ad486ffee4576f61b3199e1da6dec6dad | |
| parent | Bump version (diff) | |
| download | enigma-fork-c2ce8897a5ebe3b74d3995d4ccc4c0c277e44247.tar.gz enigma-fork-c2ce8897a5ebe3b74d3995d4ccc4c0c277e44247.tar.xz enigma-fork-c2ce8897a5ebe3b74d3995d4ccc4c0c277e44247.zip | |
Update to Mapping-IO 0.6 (#547)
* Update to Mapping-IO 0.6
* Make `legacy` suffix translatable
* Only respect `use_mappingio=false` when Enigma has an alternative reader/writer
| -rw-r--r-- | build.gradle | 2 | ||||
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 30 | ||||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java | 56 | ||||
| -rw-r--r-- | enigma/src/main/resources/lang/en_us.json | 14 |
4 files changed, 56 insertions, 46 deletions
diff --git a/build.gradle b/build.gradle index a639c54..ae68c86 100644 --- a/build.gradle +++ b/build.gradle | |||
| @@ -17,7 +17,7 @@ subprojects { | |||
| 17 | dependencies { | 17 | dependencies { |
| 18 | implementation 'com.google.guava:guava:32.1.2-jre' | 18 | implementation 'com.google.guava:guava:32.1.2-jre' |
| 19 | implementation 'com.google.code.gson:gson:2.10.1' | 19 | implementation 'com.google.code.gson:gson:2.10.1' |
| 20 | implementation 'net.fabricmc:mapping-io:0.5.0' | 20 | implementation 'net.fabricmc:mapping-io:0.6.1' |
| 21 | 21 | ||
| 22 | compileOnly 'org.jetbrains:annotations:24.0.1' | 22 | compileOnly 'org.jetbrains:annotations:24.0.1' |
| 23 | 23 | ||
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 3512979..d7054f7 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 @@ public class MenuBar { | |||
| 405 | 405 | ||
| 406 | private static void prepareOpenMappingsMenu(JMenu openMappingsMenu, Gui gui) { | 406 | private static void prepareOpenMappingsMenu(JMenu openMappingsMenu, Gui gui) { |
| 407 | // Mapping-IO readers | 407 | // Mapping-IO readers |
| 408 | MappingFormat.getReadableFormats().stream() | 408 | for (MappingFormat format : MappingFormat.values()) { |
| 409 | .filter(format -> format.getMappingIoCounterpart() != null) | 409 | if (format.getMappingIoCounterpart() != null) { |
| 410 | .forEach(format -> addOpenMappingsMenuEntry(I18n.translate(format.getMappingIoCounterpart().name), | 410 | addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), |
| 411 | format, true, openMappingsMenu, gui)); | 411 | format, true, openMappingsMenu, gui); |
| 412 | } | ||
| 413 | } | ||
| 414 | |||
| 412 | openMappingsMenu.addSeparator(); | 415 | openMappingsMenu.addSeparator(); |
| 413 | 416 | ||
| 414 | // Enigma's own readers | 417 | // Enigma's own readers |
| 418 | String legacySuffix = " (" + I18n.translate("legacy") + ")"; | ||
| 419 | |||
| 415 | for (MappingFormat format : MappingFormat.values()) { | 420 | for (MappingFormat format : MappingFormat.values()) { |
| 416 | if (format.getReader() != null) { | 421 | if (format.getReader() != null) { |
| 417 | addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + " (legacy)", | 422 | addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + legacySuffix, |
| 418 | format, false, openMappingsMenu, gui); | 423 | format, false, openMappingsMenu, gui); |
| 419 | } | 424 | } |
| 420 | } | 425 | } |
| @@ -437,16 +442,21 @@ public class MenuBar { | |||
| 437 | 442 | ||
| 438 | private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { | 443 | private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { |
| 439 | // Mapping-IO writers | 444 | // Mapping-IO writers |
| 440 | MappingFormat.getWritableFormats().stream() | 445 | for (MappingFormat format : MappingFormat.values()) { |
| 441 | .filter(format -> format.hasMappingIoWriter()) | 446 | if (format.hasMappingIoWriter()) { |
| 442 | .forEach(format -> addSaveMappingsAsMenuEntry(format.getMappingIoCounterpart().name, | 447 | addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), |
| 443 | format, true, saveMappingsAsMenu, saveMappingsItem, gui)); | 448 | format, true, saveMappingsAsMenu, saveMappingsItem, gui); |
| 449 | } | ||
| 450 | } | ||
| 451 | |||
| 444 | saveMappingsAsMenu.addSeparator(); | 452 | saveMappingsAsMenu.addSeparator(); |
| 445 | 453 | ||
| 446 | // Enigma's own writers | 454 | // Enigma's own writers |
| 455 | String legacySuffix = " (" + I18n.translate("legacy") + ")"; | ||
| 456 | |||
| 447 | for (MappingFormat format : MappingFormat.values()) { | 457 | for (MappingFormat format : MappingFormat.values()) { |
| 448 | if (format.getWriter() != null) { | 458 | if (format.getWriter() != null) { |
| 449 | addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + " (legacy)", | 459 | addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)) + legacySuffix, |
| 450 | format, false, saveMappingsAsMenu, saveMappingsItem, gui); | 460 | format, false, saveMappingsAsMenu, saveMappingsItem, gui); |
| 451 | } | 461 | } |
| 452 | } | 462 | } |
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 c9707b9..bb70c04 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.translation.mapping.tree.EntryTree; | |||
| 34 | import cuchaz.enigma.utils.I18n; | 34 | import cuchaz.enigma.utils.I18n; |
| 35 | 35 | ||
| 36 | public enum MappingFormat { | 36 | public enum MappingFormat { |
| 37 | ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE, FileType.MAPPING, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_FILE, true), | 37 | ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE, FileType.MAPPING, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_FILE), |
| 38 | ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY, FileType.DIRECTORY, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_DIR, true), | 38 | ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY, FileType.DIRECTORY, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_DIR), |
| 39 | ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP, FileType.ZIP, null, false), | 39 | ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP, FileType.ZIP, null), |
| 40 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE, true), | 40 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE), |
| 41 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE, true), | 41 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE), |
| 42 | SRG_FILE(SrgMappingsWriter.INSTANCE, null, FileType.SRG, net.fabricmc.mappingio.format.MappingFormat.SRG_FILE, true), | 42 | SRG_FILE(SrgMappingsWriter.INSTANCE, null, FileType.SRG, net.fabricmc.mappingio.format.MappingFormat.SRG_FILE), |
| 43 | XSRG_FILE(null, null, FileType.XSRG, net.fabricmc.mappingio.format.MappingFormat.XSRG_FILE, true), | 43 | XSRG_FILE(null, null, FileType.XSRG, net.fabricmc.mappingio.format.MappingFormat.XSRG_FILE), |
| 44 | CSRG_FILE(null, null, FileType.CSRG, net.fabricmc.mappingio.format.MappingFormat.CSRG_FILE, false), | 44 | JAM_FILE(null, null, FileType.JAM, net.fabricmc.mappingio.format.MappingFormat.JAM_FILE), |
| 45 | TSRG_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_FILE, false), | 45 | CSRG_FILE(null, null, FileType.CSRG, net.fabricmc.mappingio.format.MappingFormat.CSRG_FILE), |
| 46 | TSRG_2_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_2_FILE, false), | 46 | TSRG_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_FILE), |
| 47 | PROGUARD(null, ProguardMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.PROGUARD_FILE, true), | 47 | TSRG_2_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_2_FILE), |
| 48 | RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, FileType.TXT, null, false); | 48 | PROGUARD(null, ProguardMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.PROGUARD_FILE), |
| 49 | RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.RECAF_SIMPLE_FILE), | ||
| 50 | JOBF_FILE(null, null, FileType.JOBF, net.fabricmc.mappingio.format.MappingFormat.JOBF_FILE); | ||
| 49 | 51 | ||
| 50 | private final MappingsWriter writer; | 52 | private final MappingsWriter writer; |
| 51 | private final MappingsReader reader; | 53 | private final MappingsReader reader; |
| @@ -54,12 +56,12 @@ public enum MappingFormat { | |||
| 54 | private final boolean hasMappingIoWriter; | 56 | private final boolean hasMappingIoWriter; |
| 55 | private boolean usedMappingIoWriterLast; | 57 | private boolean usedMappingIoWriterLast; |
| 56 | 58 | ||
| 57 | MappingFormat(MappingsWriter writer, MappingsReader reader, FileType fileType, net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart, boolean hasMappingIoWriter) { | 59 | MappingFormat(MappingsWriter writer, MappingsReader reader, FileType fileType, net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart) { |
| 58 | this.writer = writer; | 60 | this.writer = writer; |
| 59 | this.reader = reader; | 61 | this.reader = reader; |
| 60 | this.fileType = fileType; | 62 | this.fileType = fileType; |
| 61 | this.mappingIoCounterpart = mappingIoCounterpart; | 63 | this.mappingIoCounterpart = mappingIoCounterpart; |
| 62 | this.hasMappingIoWriter = hasMappingIoWriter; | 64 | this.hasMappingIoWriter = mappingIoCounterpart == null ? false : mappingIoCounterpart.hasWriter; |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 65 | public void write(EntryTree<EntryMapping> mappings, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { | 67 | public void write(EntryTree<EntryMapping> mappings, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { |
| @@ -67,11 +69,7 @@ public enum MappingFormat { | |||
| 67 | } | 69 | } |
| 68 | 70 | ||
| 69 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { | 71 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { |
| 70 | if (!hasMappingIoWriter || !useMappingIo()) { | 72 | if (!hasMappingIoWriter || (!useMappingIo() && writer != null)) { |
| 71 | if (writer == null) { | ||
| 72 | throw new IllegalStateException(name() + " does not support writing"); | ||
| 73 | } | ||
| 74 | |||
| 75 | writer.write(mappings, usedMappingIoWriterLast ? MappingDelta.added(mappings) : delta, path, progressListener, saveParameters); | 73 | writer.write(mappings, usedMappingIoWriterLast ? MappingDelta.added(mappings) : delta, path, progressListener, saveParameters); |
| 76 | usedMappingIoWriterLast = false; | 74 | usedMappingIoWriterLast = false; |
| 77 | return; | 75 | return; |
| @@ -105,11 +103,7 @@ public enum MappingFormat { | |||
| 105 | } | 103 | } |
| 106 | 104 | ||
| 107 | public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener, MappingSaveParameters saveParameters, JarIndex index) throws IOException, MappingParseException { | 105 | public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener, MappingSaveParameters saveParameters, JarIndex index) throws IOException, MappingParseException { |
| 108 | if (!useMappingIo()) { | 106 | if (mappingIoCounterpart == null || (!useMappingIo() && reader != null)) { |
| 109 | if (reader == null) { | ||
| 110 | throw new IllegalStateException(name() + " does not support reading"); | ||
| 111 | } | ||
| 112 | |||
| 113 | return reader.read(path, progressListener, saveParameters); | 107 | return reader.read(path, progressListener, saveParameters); |
| 114 | } | 108 | } |
| 115 | 109 | ||
| @@ -178,22 +172,18 @@ public enum MappingFormat { | |||
| 178 | return writer != null || hasMappingIoWriter; | 172 | return writer != null || hasMappingIoWriter; |
| 179 | } | 173 | } |
| 180 | 174 | ||
| 181 | @ApiStatus.Internal | ||
| 182 | private boolean useMappingIo() { | 175 | private boolean useMappingIo() { |
| 183 | if (mappingIoCounterpart == null) return false; | ||
| 184 | return System.getProperty("enigma.use_mappingio", "true").equals("true"); | 176 | return System.getProperty("enigma.use_mappingio", "true").equals("true"); |
| 185 | } | 177 | } |
| 186 | 178 | ||
| 187 | public static List<MappingFormat> getReadableFormats() { | 179 | public static List<MappingFormat> getReadableFormats() { |
| 188 | return Arrays.asList(values()) | 180 | return Arrays.stream(values()) |
| 189 | .stream() | ||
| 190 | .filter(MappingFormat::isReadable) | 181 | .filter(MappingFormat::isReadable) |
| 191 | .toList(); | 182 | .toList(); |
| 192 | } | 183 | } |
| 193 | 184 | ||
| 194 | public static List<MappingFormat> getWritableFormats() { | 185 | public static List<MappingFormat> getWritableFormats() { |
| 195 | return Arrays.asList(values()) | 186 | return Arrays.stream(values()) |
| 196 | .stream() | ||
| 197 | .filter(MappingFormat::isWritable) | 187 | .filter(MappingFormat::isWritable) |
| 198 | .toList(); | 188 | .toList(); |
| 199 | } | 189 | } |
| @@ -209,14 +199,16 @@ public enum MappingFormat { | |||
| 209 | @ApiStatus.Internal | 199 | @ApiStatus.Internal |
| 210 | public record FileType(List<String> extensions) { | 200 | public record FileType(List<String> extensions) { |
| 211 | public static final FileType DIRECTORY = new FileType(); | 201 | public static final FileType DIRECTORY = new FileType(); |
| 202 | public static final FileType ZIP = new FileType(".zip"); | ||
| 212 | public static final FileType MAPPING = new FileType(".mapping", ".mappings"); | 203 | public static final FileType MAPPING = new FileType(".mapping", ".mappings"); |
| 204 | public static final FileType TINY = new FileType(".tiny"); | ||
| 213 | public static final FileType SRG = new FileType(".srg"); | 205 | public static final FileType SRG = new FileType(".srg"); |
| 214 | public static final FileType XSRG = new FileType(".xsrg"); | 206 | public static final FileType XSRG = new FileType(".xsrg"); |
| 207 | public static final FileType JAM = new FileType(".jam"); | ||
| 215 | public static final FileType CSRG = new FileType(".csrg"); | 208 | public static final FileType CSRG = new FileType(".csrg"); |
| 216 | public static final FileType TSRG = new FileType(".tsrg"); | 209 | public static final FileType TSRG = new FileType(".tsrg"); |
| 217 | public static final FileType TINY = new FileType(".tiny"); | ||
| 218 | public static final FileType TXT = new FileType(".txt"); | 210 | public static final FileType TXT = new FileType(".txt"); |
| 219 | public static final FileType ZIP = new FileType(".zip"); | 211 | public static final FileType JOBF = new FileType(".jobf"); |
| 220 | 212 | ||
| 221 | public FileType(String... extensions) { | 213 | public FileType(String... extensions) { |
| 222 | this(List.of(extensions)); | 214 | 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 4222814..b939e55 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json | |||
| @@ -4,11 +4,19 @@ | |||
| 4 | "mapping_format.enigma_file": "Enigma File", | 4 | "mapping_format.enigma_file": "Enigma File", |
| 5 | "mapping_format.enigma_directory": "Enigma Directory", | 5 | "mapping_format.enigma_directory": "Enigma Directory", |
| 6 | "mapping_format.enigma_zip": "Enigma ZIP", | 6 | "mapping_format.enigma_zip": "Enigma ZIP", |
| 7 | "mapping_format.tiny_v2": "Tiny v2", | 7 | "mapping_format.tiny_v2": "Tiny v2 File", |
| 8 | "mapping_format.tiny_file": "Tiny File", | 8 | "mapping_format.tiny_file": "Tiny File", |
| 9 | "mapping_format.srg_file": "SRG File", | 9 | "mapping_format.srg_file": "SRG File", |
| 10 | "mapping_format.proguard": "Proguard", | 10 | "mapping_format.xsrg_file": "XSRG File", |
| 11 | "mapping_format.recaf": "Recaf", | 11 | "mapping_format.jam_file": "JAM File", |
| 12 | "mapping_format.csrg_file": "CSRG File", | ||
| 13 | "mapping_format.tsrg_file": "TSRG File", | ||
| 14 | "mapping_format.tsrg_2_file": "TSRG v2 File", | ||
| 15 | "mapping_format.proguard": "ProGuard File", | ||
| 16 | "mapping_format.recaf": "Recaf Simple File", | ||
| 17 | "mapping_format.jobf_file": "JOBF File", | ||
| 18 | "legacy": "legacy", | ||
| 19 | |||
| 12 | "type.methods": "Methods", | 20 | "type.methods": "Methods", |
| 13 | "type.fields": "Fields", | 21 | "type.fields": "Fields", |
| 14 | "type.parameters": "Parameters", | 22 | "type.parameters": "Parameters", |