Skip to content

Commit

Permalink
Update to Mapping-IO 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas committed Aug 24, 2024
1 parent d7ef85b commit 329dbcb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 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
22 changes: 14 additions & 8 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,10 +405,13 @@ 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
Expand Down Expand Up @@ -437,10 +440,13 @@ 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
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,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<EntryMapping> mappings, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) {
Expand Down Expand Up @@ -185,15 +187,13 @@ private boolean useMappingIo() {
}

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 +209,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 329dbcb

Please sign in to comment.