diff options
Diffstat (limited to 'enigma/src/main/java')
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java | 62 |
1 files changed, 49 insertions, 13 deletions
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 4521591..aeac9db 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 | |||
| @@ -33,28 +33,30 @@ import cuchaz.enigma.translation.mapping.tree.EntryTree; | |||
| 33 | import cuchaz.enigma.utils.I18n; | 33 | import cuchaz.enigma.utils.I18n; |
| 34 | 34 | ||
| 35 | public enum MappingFormat { | 35 | public enum MappingFormat { |
| 36 | ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_FILE, true), | 36 | ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE, FileType.MAPPING, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_FILE, true), |
| 37 | ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_DIR, true), | 37 | ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY, FileType.DIRECTORY, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_DIR, true), |
| 38 | ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP, null, false), | 38 | ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP, FileType.ZIP, null, false), |
| 39 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE, true), | 39 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE, true), |
| 40 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE, true), | 40 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE, true), |
| 41 | SRG_FILE(SrgMappingsWriter.INSTANCE, null, net.fabricmc.mappingio.format.MappingFormat.SRG_FILE, true), | 41 | SRG_FILE(SrgMappingsWriter.INSTANCE, null, FileType.SRG, net.fabricmc.mappingio.format.MappingFormat.SRG_FILE, true), |
| 42 | XSRG_FILE(null, null, net.fabricmc.mappingio.format.MappingFormat.XSRG_FILE, true), | 42 | XSRG_FILE(null, null, FileType.XSRG, net.fabricmc.mappingio.format.MappingFormat.XSRG_FILE, true), |
| 43 | CSRG_FILE(null, null, net.fabricmc.mappingio.format.MappingFormat.CSRG_FILE, false), | 43 | CSRG_FILE(null, null, FileType.CSRG, net.fabricmc.mappingio.format.MappingFormat.CSRG_FILE, false), |
| 44 | TSRG_FILE(null, null, net.fabricmc.mappingio.format.MappingFormat.TSRG_FILE, false), | 44 | TSRG_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_FILE, false), |
| 45 | TSRG_2_FILE(null, null, net.fabricmc.mappingio.format.MappingFormat.TSRG_2_FILE, false), | 45 | TSRG_2_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_2_FILE, false), |
| 46 | PROGUARD(null, ProguardMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.PROGUARD_FILE, true), | 46 | PROGUARD(null, ProguardMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.PROGUARD_FILE, true), |
| 47 | RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, null, false); | 47 | RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, FileType.TXT, null, false); |
| 48 | 48 | ||
| 49 | private final MappingsWriter writer; | 49 | private final MappingsWriter writer; |
| 50 | private final MappingsReader reader; | 50 | private final MappingsReader reader; |
| 51 | private final FileType fileType; | ||
| 51 | private final net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart; | 52 | private final net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart; |
| 52 | private final boolean hasMappingIoWriter; | 53 | private final boolean hasMappingIoWriter; |
| 53 | private boolean lastUsedMappingIoWriter; | 54 | private boolean lastUsedMappingIoWriter; |
| 54 | 55 | ||
| 55 | MappingFormat(MappingsWriter writer, MappingsReader reader, net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart, boolean hasMappingIoWriter) { | 56 | MappingFormat(MappingsWriter writer, MappingsReader reader, FileType fileType, net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart, boolean hasMappingIoWriter) { |
| 56 | this.writer = writer; | 57 | this.writer = writer; |
| 57 | this.reader = reader; | 58 | this.reader = reader; |
| 59 | this.fileType = fileType; | ||
| 58 | this.mappingIoCounterpart = mappingIoCounterpart; | 60 | this.mappingIoCounterpart = mappingIoCounterpart; |
| 59 | this.hasMappingIoWriter = hasMappingIoWriter; | 61 | this.hasMappingIoWriter = hasMappingIoWriter; |
| 60 | } | 62 | } |
| @@ -126,6 +128,11 @@ public enum MappingFormat { | |||
| 126 | return reader; | 128 | return reader; |
| 127 | } | 129 | } |
| 128 | 130 | ||
| 131 | @ApiStatus.Internal | ||
| 132 | public FileType getFileType() { | ||
| 133 | return fileType; | ||
| 134 | } | ||
| 135 | |||
| 129 | @Nullable | 136 | @Nullable |
| 130 | @ApiStatus.Internal | 137 | @ApiStatus.Internal |
| 131 | public net.fabricmc.mappingio.format.MappingFormat getMappingIoCounterpart() { | 138 | public net.fabricmc.mappingio.format.MappingFormat getMappingIoCounterpart() { |
| @@ -164,4 +171,33 @@ public enum MappingFormat { | |||
| 164 | .filter(MappingFormat::isWritable) | 171 | .filter(MappingFormat::isWritable) |
| 165 | .toList(); | 172 | .toList(); |
| 166 | } | 173 | } |
| 174 | |||
| 175 | /** | ||
| 176 | * A file type. It can be either a single file with an extension, or a directory | ||
| 177 | * with a {@code null} extension. | ||
| 178 | * | ||
| 179 | * <p>If a file type has multiple extensions, the default for saving will be the first one. | ||
| 180 | * | ||
| 181 | * @param extensions the file extensions with the leading dot {@code .}, or an empty list for a directory | ||
| 182 | */ | ||
| 183 | @ApiStatus.Internal | ||
| 184 | public record FileType(List<String> extensions) { | ||
| 185 | public static final FileType DIRECTORY = new FileType(); | ||
| 186 | public static final FileType MAPPING = new FileType(".mapping", ".mappings"); | ||
| 187 | public static final FileType SRG = new FileType(".srg"); | ||
| 188 | public static final FileType XSRG = new FileType(".xsrg"); | ||
| 189 | public static final FileType CSRG = new FileType(".csrg"); | ||
| 190 | public static final FileType TSRG = new FileType(".tsrg"); | ||
| 191 | public static final FileType TINY = new FileType(".tiny"); | ||
| 192 | public static final FileType TXT = new FileType(".txt"); | ||
| 193 | public static final FileType ZIP = new FileType(".zip"); | ||
| 194 | |||
| 195 | public FileType(String... extensions) { | ||
| 196 | this(List.of(extensions)); | ||
| 197 | } | ||
| 198 | |||
| 199 | public boolean isDirectory() { | ||
| 200 | return extensions.isEmpty(); | ||
| 201 | } | ||
| 202 | } | ||
| 167 | } | 203 | } |