Skip to content

Commit

Permalink
Update to Mapping-IO 0.6 (#547)
Browse files Browse the repository at this point in the history
* Update to Mapping-IO 0.6

* Make `legacy` suffix translatable

* Only respect `use_mappingio=false` when Enigma has an alternative reader/writer
  • Loading branch information
NebelNidas authored Aug 27, 2024
1 parent d7ef85b commit c2ce889
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 46 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
30 changes: 20 additions & 10 deletions enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,24 +56,20 @@ 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<EntryMapping> mappings, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) {
write(mappings, MappingDelta.added(mappings), path, progressListener, saveParameters);
}

public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> 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;
Expand Down Expand Up @@ -105,11 +103,7 @@ public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener
}

public EntryTree<EntryMapping> 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);
}

Expand Down Expand Up @@ -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<MappingFormat> getReadableFormats() {
return Arrays.asList(values())
.stream()
return Arrays.stream(values())
.filter(MappingFormat::isReadable)
.toList();
}

public static List<MappingFormat> getWritableFormats() {
return Arrays.asList(values())
.stream()
return Arrays.stream(values())
.filter(MappingFormat::isWritable)
.toList();
}
Expand All @@ -209,14 +199,16 @@ public static List<MappingFormat> getWritableFormats() {
@ApiStatus.Internal
public record FileType(List<String> 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));
Expand Down
14 changes: 11 additions & 3 deletions enigma/src/main/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c2ce889

Please sign in to comment.