diff options
4 files changed, 147 insertions, 93 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index e7e75669..73472ca9 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -29,6 +29,7 @@ import javax.swing.JOptionPane; | |||
| 29 | import javax.swing.SwingUtilities; | 29 | import javax.swing.SwingUtilities; |
| 30 | 30 | ||
| 31 | import com.google.common.collect.Lists; | 31 | import com.google.common.collect.Lists; |
| 32 | import net.fabricmc.mappingio.MappingReader; | ||
| 32 | import net.fabricmc.mappingio.MappingWriter; | 33 | import net.fabricmc.mappingio.MappingWriter; |
| 33 | import net.fabricmc.mappingio.tree.MemoryMappingTree; | 34 | import net.fabricmc.mappingio.tree.MemoryMappingTree; |
| 34 | 35 | ||
| @@ -102,6 +103,7 @@ public class GuiController implements ClientPacketHandler { | |||
| 102 | 103 | ||
| 103 | private Path loadedMappingPath; | 104 | private Path loadedMappingPath; |
| 104 | private MappingFormat loadedMappingFormat; | 105 | private MappingFormat loadedMappingFormat; |
| 106 | public boolean useMappingIo; | ||
| 105 | 107 | ||
| 106 | private ClassHandleProvider chp; | 108 | private ClassHandleProvider chp; |
| 107 | 109 | ||
| @@ -152,8 +154,16 @@ public class GuiController implements ClientPacketHandler { | |||
| 152 | return ProgressDialog.runOffThread(gui.getFrame(), progress -> { | 154 | return ProgressDialog.runOffThread(gui.getFrame(), progress -> { |
| 153 | try { | 155 | try { |
| 154 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); | 156 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); |
| 157 | EntryTree<EntryMapping> mappings; | ||
| 158 | |||
| 159 | if (useMappingIo) { | ||
| 160 | MemoryMappingTree mappingTree = new MemoryMappingTree(); | ||
| 161 | MappingReader.read(path, format.getMappingIoCounterpart(), mappingTree); | ||
| 162 | mappings = MappingIoConverter.fromMappingIo(mappingTree); | ||
| 163 | } else { | ||
| 164 | mappings = format.read(path, progress, saveParameters); | ||
| 165 | } | ||
| 155 | 166 | ||
| 156 | EntryTree<EntryMapping> mappings = format.read(path, progress, saveParameters); | ||
| 157 | project.setMappings(mappings); | 167 | project.setMappings(mappings); |
| 158 | 168 | ||
| 159 | loadedMappingFormat = format; | 169 | loadedMappingFormat = format; |
| @@ -208,7 +218,12 @@ public class GuiController implements ClientPacketHandler { | |||
| 208 | loadedMappingFormat = format; | 218 | loadedMappingFormat = format; |
| 209 | loadedMappingPath = path; | 219 | loadedMappingPath = path; |
| 210 | 220 | ||
| 211 | if (saveAll) { | 221 | if (useMappingIo) { |
| 222 | MemoryMappingTree mappingTree = MappingIoConverter.toMappingIo(mapper.getObfToDeobf()); | ||
| 223 | MappingWriter writer = MappingWriter.create(path, format.getMappingIoCounterpart()); | ||
| 224 | mappingTree.accept(writer); | ||
| 225 | writer.close(); | ||
| 226 | } else if (saveAll) { | ||
| 212 | format.write(mapper.getObfToDeobf(), path, progress, saveParameters); | 227 | format.write(mapper.getObfToDeobf(), path, progress, saveParameters); |
| 213 | } else { | 228 | } else { |
| 214 | format.write(mapper.getObfToDeobf(), delta, path, progress, saveParameters); | 229 | format.write(mapper.getObfToDeobf(), delta, path, progress, saveParameters); |
| @@ -216,48 +231,6 @@ public class GuiController implements ClientPacketHandler { | |||
| 216 | }); | 231 | }); |
| 217 | } | 232 | } |
| 218 | 233 | ||
| 219 | public CompletableFuture<Void> saveMappings(Path path, net.fabricmc.mappingio.format.MappingFormat format) { | ||
| 220 | if (project == null) { | ||
| 221 | return CompletableFuture.completedFuture(null); | ||
| 222 | } | ||
| 223 | |||
| 224 | return ProgressDialog.runOffThread(this.gui.getFrame(), progress -> { | ||
| 225 | EntryRemapper mapper = project.getMapper(); | ||
| 226 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); | ||
| 227 | |||
| 228 | MappingDelta<EntryMapping> delta = mapper.takeMappingDelta(); | ||
| 229 | boolean saveAll = !path.equals(loadedMappingPath); | ||
| 230 | |||
| 231 | switch (format) { | ||
| 232 | case ENIGMA: | ||
| 233 | loadedMappingFormat = MappingFormat.ENIGMA_DIRECTORY; | ||
| 234 | loadedMappingPath = path; | ||
| 235 | break; | ||
| 236 | case PROGUARD: | ||
| 237 | loadedMappingFormat = MappingFormat.PROGUARD; | ||
| 238 | loadedMappingPath = path; | ||
| 239 | break; | ||
| 240 | case SRG: | ||
| 241 | loadedMappingFormat = MappingFormat.SRG_FILE; | ||
| 242 | loadedMappingPath = path; | ||
| 243 | break; | ||
| 244 | case TINY: | ||
| 245 | loadedMappingFormat = MappingFormat.TINY_FILE; | ||
| 246 | loadedMappingPath = path; | ||
| 247 | break; | ||
| 248 | case TINY_2: | ||
| 249 | loadedMappingFormat = MappingFormat.TINY_V2; | ||
| 250 | loadedMappingPath = path; | ||
| 251 | break; | ||
| 252 | } | ||
| 253 | |||
| 254 | MemoryMappingTree mappingTree = MappingIoConverter.toMappingIo(mapper.getObfToDeobf()); | ||
| 255 | MappingWriter writer = MappingWriter.create(path, format); | ||
| 256 | mappingTree.accept(writer); | ||
| 257 | writer.close(); | ||
| 258 | }); | ||
| 259 | } | ||
| 260 | |||
| 261 | public void closeMappings() { | 234 | public void closeMappings() { |
| 262 | if (project == null) { | 235 | if (project == null) { |
| 263 | return; | 236 | return; |
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 1d4c1ca1..3692eb3b 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 | |||
| @@ -46,7 +46,7 @@ public class MenuBar { | |||
| 46 | private final JMenu fileMenu = new JMenu(); | 46 | private final JMenu fileMenu = new JMenu(); |
| 47 | private final JMenuItem jarOpenItem = new JMenuItem(); | 47 | private final JMenuItem jarOpenItem = new JMenuItem(); |
| 48 | private final JMenuItem jarCloseItem = new JMenuItem(); | 48 | private final JMenuItem jarCloseItem = new JMenuItem(); |
| 49 | private final JMenu openMenu = new JMenu(); | 49 | private final JMenu openMappingsMenu = new JMenu(); |
| 50 | private final JMenuItem saveMappingsItem = new JMenuItem(); | 50 | private final JMenuItem saveMappingsItem = new JMenuItem(); |
| 51 | private final JMenu saveMappingsAsMenu = new JMenu(); | 51 | private final JMenu saveMappingsAsMenu = new JMenu(); |
| 52 | private final JMenuItem closeMappingsItem = new JMenuItem(); | 52 | private final JMenuItem closeMappingsItem = new JMenuItem(); |
| @@ -89,7 +89,7 @@ public class MenuBar { | |||
| 89 | 89 | ||
| 90 | this.retranslateUi(); | 90 | this.retranslateUi(); |
| 91 | 91 | ||
| 92 | prepareOpenMenu(this.openMenu, gui); | 92 | prepareOpenMappingsMenu(this.openMappingsMenu, gui); |
| 93 | prepareSaveMappingsAsMenu(this.saveMappingsAsMenu, this.saveMappingsItem, gui); | 93 | prepareSaveMappingsAsMenu(this.saveMappingsAsMenu, this.saveMappingsItem, gui); |
| 94 | prepareDecompilerMenu(this.decompilerMenu, gui); | 94 | prepareDecompilerMenu(this.decompilerMenu, gui); |
| 95 | prepareThemesMenu(this.themesMenu, gui); | 95 | prepareThemesMenu(this.themesMenu, gui); |
| @@ -99,7 +99,7 @@ public class MenuBar { | |||
| 99 | this.fileMenu.add(this.jarOpenItem); | 99 | this.fileMenu.add(this.jarOpenItem); |
| 100 | this.fileMenu.add(this.jarCloseItem); | 100 | this.fileMenu.add(this.jarCloseItem); |
| 101 | this.fileMenu.addSeparator(); | 101 | this.fileMenu.addSeparator(); |
| 102 | this.fileMenu.add(this.openMenu); | 102 | this.fileMenu.add(this.openMappingsMenu); |
| 103 | this.fileMenu.add(this.saveMappingsItem); | 103 | this.fileMenu.add(this.saveMappingsItem); |
| 104 | this.fileMenu.add(this.saveMappingsAsMenu); | 104 | this.fileMenu.add(this.saveMappingsAsMenu); |
| 105 | this.fileMenu.add(this.closeMappingsItem); | 105 | this.fileMenu.add(this.closeMappingsItem); |
| @@ -175,7 +175,7 @@ public class MenuBar { | |||
| 175 | this.startServerItem.setText(I18n.translate(connectionState != ConnectionState.HOSTING ? "menu.collab.server.start" : "menu.collab.server.stop")); | 175 | this.startServerItem.setText(I18n.translate(connectionState != ConnectionState.HOSTING ? "menu.collab.server.start" : "menu.collab.server.stop")); |
| 176 | 176 | ||
| 177 | this.jarCloseItem.setEnabled(jarOpen); | 177 | this.jarCloseItem.setEnabled(jarOpen); |
| 178 | this.openMenu.setEnabled(jarOpen); | 178 | this.openMappingsMenu.setEnabled(jarOpen); |
| 179 | this.saveMappingsItem.setEnabled(jarOpen && this.gui.enigmaMappingsFileChooser.getSelectedFile() != null && connectionState != ConnectionState.CONNECTED); | 179 | this.saveMappingsItem.setEnabled(jarOpen && this.gui.enigmaMappingsFileChooser.getSelectedFile() != null && connectionState != ConnectionState.CONNECTED); |
| 180 | this.saveMappingsAsMenu.setEnabled(jarOpen); | 180 | this.saveMappingsAsMenu.setEnabled(jarOpen); |
| 181 | this.closeMappingsItem.setEnabled(jarOpen); | 181 | this.closeMappingsItem.setEnabled(jarOpen); |
| @@ -190,7 +190,7 @@ public class MenuBar { | |||
| 190 | this.fileMenu.setText(I18n.translate("menu.file")); | 190 | this.fileMenu.setText(I18n.translate("menu.file")); |
| 191 | this.jarOpenItem.setText(I18n.translate("menu.file.jar.open")); | 191 | this.jarOpenItem.setText(I18n.translate("menu.file.jar.open")); |
| 192 | this.jarCloseItem.setText(I18n.translate("menu.file.jar.close")); | 192 | this.jarCloseItem.setText(I18n.translate("menu.file.jar.close")); |
| 193 | this.openMenu.setText(I18n.translate("menu.file.mappings.open")); | 193 | this.openMappingsMenu.setText(I18n.translate("menu.file.mappings.open")); |
| 194 | this.saveMappingsItem.setText(I18n.translate("menu.file.mappings.save")); | 194 | this.saveMappingsItem.setText(I18n.translate("menu.file.mappings.save")); |
| 195 | this.saveMappingsAsMenu.setText(I18n.translate("menu.file.mappings.save_as")); | 195 | this.saveMappingsAsMenu.setText(I18n.translate("menu.file.mappings.save_as")); |
| 196 | this.closeMappingsItem.setText(I18n.translate("menu.file.mappings.close")); | 196 | this.closeMappingsItem.setText(I18n.translate("menu.file.mappings.close")); |
| @@ -403,67 +403,88 @@ public class MenuBar { | |||
| 403 | GuiUtil.openUrl("https://github.com/FabricMC/Enigma"); | 403 | GuiUtil.openUrl("https://github.com/FabricMC/Enigma"); |
| 404 | } | 404 | } |
| 405 | 405 | ||
| 406 | private static void prepareOpenMenu(JMenu openMenu, Gui gui) { | 406 | private static void prepareOpenMappingsMenu(JMenu openMappingsMenu, Gui gui) { |
| 407 | List<MappingFormat> readableMappingIoFormats = Arrays.asList( | ||
| 408 | MappingFormat.ENIGMA_DIRECTORY, | ||
| 409 | MappingFormat.TINY_FILE, | ||
| 410 | MappingFormat.TINY_V2, | ||
| 411 | MappingFormat.SRG_FILE, | ||
| 412 | MappingFormat.TSRG_FILE, | ||
| 413 | MappingFormat.TSRG_2_FILE, | ||
| 414 | MappingFormat.PROGUARD); | ||
| 415 | |||
| 416 | // Enigma's own readers | ||
| 407 | for (MappingFormat format : MappingFormat.values()) { | 417 | for (MappingFormat format : MappingFormat.values()) { |
| 408 | if (format.getReader() != null) { | 418 | if (format.getReader() != null) { |
| 409 | JMenuItem item = new JMenuItem(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT))); | 419 | addOpenMappingsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), |
| 410 | item.addActionListener(event -> { | 420 | format, false, openMappingsMenu, gui); |
| 411 | gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); | ||
| 412 | |||
| 413 | if (gui.enigmaMappingsFileChooser.showOpenDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | ||
| 414 | File selectedFile = gui.enigmaMappingsFileChooser.getSelectedFile(); | ||
| 415 | gui.getController().openMappings(format, selectedFile.toPath()); | ||
| 416 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); | ||
| 417 | } | ||
| 418 | }); | ||
| 419 | openMenu.add(item); | ||
| 420 | } | 421 | } |
| 421 | } | 422 | } |
| 423 | |||
| 424 | openMappingsMenu.addSeparator(); | ||
| 425 | |||
| 426 | // Mapping-IO readers | ||
| 427 | for (MappingFormat format : readableMappingIoFormats) { | ||
| 428 | addOpenMappingsMenuEntry(I18n.translate(format.getMappingIoCounterpart().name + " (via Mapping-IO, experimental)"), | ||
| 429 | format, true, openMappingsMenu, gui); | ||
| 430 | } | ||
| 431 | } | ||
| 432 | |||
| 433 | private static void addOpenMappingsMenuEntry(String text, MappingFormat format, boolean mappingIo, JMenu openMappingsMenu, Gui gui) { | ||
| 434 | JMenuItem item = new JMenuItem(text); | ||
| 435 | item.addActionListener(event -> { | ||
| 436 | gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); | ||
| 437 | |||
| 438 | if (gui.enigmaMappingsFileChooser.showOpenDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | ||
| 439 | File selectedFile = gui.enigmaMappingsFileChooser.getSelectedFile(); | ||
| 440 | gui.getController().useMappingIo = mappingIo; | ||
| 441 | gui.getController().openMappings(format, selectedFile.toPath()); | ||
| 442 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); | ||
| 443 | } | ||
| 444 | }); | ||
| 445 | openMappingsMenu.add(item); | ||
| 422 | } | 446 | } |
| 423 | 447 | ||
| 424 | private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { | 448 | private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { |
| 449 | List<MappingFormat> writableMappingIoFormats = Arrays.asList( | ||
| 450 | MappingFormat.ENIGMA_DIRECTORY, | ||
| 451 | MappingFormat.TINY_V2); | ||
| 452 | |||
| 453 | // Enigma's own writers | ||
| 425 | for (MappingFormat format : MappingFormat.values()) { | 454 | for (MappingFormat format : MappingFormat.values()) { |
| 426 | if (format.getWriter() != null) { | 455 | if (format.getWriter() != null) { |
| 427 | JMenuItem item = new JMenuItem(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT))); | 456 | addSaveMappingsAsMenuEntry(I18n.translate("mapping_format." + format.name().toLowerCase(Locale.ROOT)), |
| 428 | item.addActionListener(event -> { | 457 | format, false, saveMappingsAsMenu, saveMappingsItem, gui); |
| 429 | // TODO: Use a specific file chooser for it | ||
| 430 | if (gui.enigmaMappingsFileChooser.getCurrentDirectory() == null) { | ||
| 431 | gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); | ||
| 432 | } | ||
| 433 | |||
| 434 | if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | ||
| 435 | gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); | ||
| 436 | saveMappingsItem.setEnabled(true); | ||
| 437 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); | ||
| 438 | } | ||
| 439 | }); | ||
| 440 | saveMappingsAsMenu.add(item); | ||
| 441 | } | 458 | } |
| 442 | } | 459 | } |
| 443 | 460 | ||
| 444 | saveMappingsAsMenu.addSeparator(); | 461 | saveMappingsAsMenu.addSeparator(); |
| 445 | 462 | ||
| 446 | List<net.fabricmc.mappingio.format.MappingFormat> writableMappingIoFormats = Arrays.asList( | 463 | // Mapping-IO writers |
| 447 | net.fabricmc.mappingio.format.MappingFormat.ENIGMA, | 464 | for (MappingFormat format : writableMappingIoFormats) { |
| 448 | net.fabricmc.mappingio.format.MappingFormat.TINY_2); | 465 | addSaveMappingsAsMenuEntry(format.getMappingIoCounterpart().name + " (via Mapping-IO, experimental)", |
| 449 | for (net.fabricmc.mappingio.format.MappingFormat format : writableMappingIoFormats) { | 466 | format, true, saveMappingsAsMenu, saveMappingsItem, gui); |
| 450 | JMenuItem item = new JMenuItem(format.name + " (via mapping-io, experimental)"); | ||
| 451 | item.addActionListener(event -> { | ||
| 452 | // TODO: Use a specific file chooser for it | ||
| 453 | if (gui.enigmaMappingsFileChooser.getCurrentDirectory() == null) { | ||
| 454 | gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); | ||
| 455 | } | ||
| 456 | |||
| 457 | if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | ||
| 458 | gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); | ||
| 459 | saveMappingsItem.setEnabled(true); | ||
| 460 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); | ||
| 461 | } | ||
| 462 | }); | ||
| 463 | saveMappingsAsMenu.add(item); | ||
| 464 | } | 467 | } |
| 465 | } | 468 | } |
| 466 | 469 | ||
| 470 | private static void addSaveMappingsAsMenuEntry(String text, MappingFormat format, boolean mappingIo, JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { | ||
| 471 | JMenuItem item = new JMenuItem(text); | ||
| 472 | item.addActionListener(event -> { | ||
| 473 | // TODO: Use a specific file chooser for it | ||
| 474 | if (gui.enigmaMappingsFileChooser.getCurrentDirectory() == null) { | ||
| 475 | gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); | ||
| 476 | } | ||
| 477 | |||
| 478 | if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | ||
| 479 | gui.getController().useMappingIo = mappingIo; | ||
| 480 | gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); | ||
| 481 | saveMappingsItem.setEnabled(true); | ||
| 482 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); | ||
| 483 | } | ||
| 484 | }); | ||
| 485 | saveMappingsAsMenu.add(item); | ||
| 486 | } | ||
| 487 | |||
| 467 | private static void prepareDecompilerMenu(JMenu decompilerMenu, Gui gui) { | 488 | private static void prepareDecompilerMenu(JMenu decompilerMenu, Gui gui) { |
| 468 | ButtonGroup decompilerGroup = new ButtonGroup(); | 489 | ButtonGroup decompilerGroup = new ButtonGroup(); |
| 469 | 490 | ||
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 4790fee4..5bad9298 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 | |||
| @@ -27,6 +27,8 @@ public enum MappingFormat { | |||
| 27 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), net.fabricmc.mappingio.format.MappingFormat.TINY_2), | 27 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), net.fabricmc.mappingio.format.MappingFormat.TINY_2), |
| 28 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.TINY), | 28 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.TINY), |
| 29 | SRG_FILE(SrgMappingsWriter.INSTANCE, null, net.fabricmc.mappingio.format.MappingFormat.SRG), | 29 | SRG_FILE(SrgMappingsWriter.INSTANCE, null, net.fabricmc.mappingio.format.MappingFormat.SRG), |
| 30 | TSRG_FILE(null, null, net.fabricmc.mappingio.format.MappingFormat.TSRG), | ||
| 31 | TSRG_2_FILE(null, null, net.fabricmc.mappingio.format.MappingFormat.TSRG2), | ||
| 30 | PROGUARD(null, ProguardMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.PROGUARD), | 32 | PROGUARD(null, ProguardMappingsReader.INSTANCE, net.fabricmc.mappingio.format.MappingFormat.PROGUARD), |
| 31 | RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, null); | 33 | RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, null); |
| 32 | 34 | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java index 3a864766..d3fd341f 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingIoConverter.java | |||
| @@ -6,11 +6,18 @@ import java.util.List; | |||
| 6 | 6 | ||
| 7 | import net.fabricmc.mappingio.MappedElementKind; | 7 | import net.fabricmc.mappingio.MappedElementKind; |
| 8 | import net.fabricmc.mappingio.tree.MemoryMappingTree; | 8 | import net.fabricmc.mappingio.tree.MemoryMappingTree; |
| 9 | import net.fabricmc.mappingio.tree.MappingTree.ClassMapping; | ||
| 10 | import net.fabricmc.mappingio.tree.MappingTree.FieldMapping; | ||
| 11 | import net.fabricmc.mappingio.tree.MappingTree.MethodArgMapping; | ||
| 12 | import net.fabricmc.mappingio.tree.MappingTree.MethodMapping; | ||
| 9 | 13 | ||
| 10 | import cuchaz.enigma.translation.mapping.EntryMap; | 14 | import cuchaz.enigma.translation.mapping.EntryMap; |
| 11 | import cuchaz.enigma.translation.mapping.EntryMapping; | 15 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 12 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 16 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 13 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; | 17 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; |
| 18 | import cuchaz.enigma.translation.mapping.tree.HashEntryTree; | ||
| 19 | import cuchaz.enigma.translation.representation.MethodDescriptor; | ||
| 20 | import cuchaz.enigma.translation.representation.TypeDescriptor; | ||
| 14 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 21 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 15 | import cuchaz.enigma.translation.representation.entry.Entry; | 22 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 16 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | 23 | import cuchaz.enigma.translation.representation.entry.FieldEntry; |
| @@ -123,4 +130,55 @@ public class MappingIoConverter { | |||
| 123 | mappingTree.visitDstName(MappedElementKind.METHOD_ARG, 0, methodArgMapping.targetName()); | 130 | mappingTree.visitDstName(MappedElementKind.METHOD_ARG, 0, methodArgMapping.targetName()); |
| 124 | mappingTree.visitComment(MappedElementKind.METHOD_ARG, methodArgMapping.javadoc()); | 131 | mappingTree.visitComment(MappedElementKind.METHOD_ARG, methodArgMapping.javadoc()); |
| 125 | } | 132 | } |
| 133 | |||
| 134 | public static EntryTree<EntryMapping> fromMappingIo(MemoryMappingTree mappingTree) { | ||
| 135 | EntryTree<EntryMapping> dstMappingTree = new HashEntryTree<>(); | ||
| 136 | |||
| 137 | for (ClassMapping classMapping : mappingTree.getClasses()) { | ||
| 138 | readClass(classMapping, dstMappingTree); | ||
| 139 | } | ||
| 140 | |||
| 141 | return dstMappingTree; | ||
| 142 | } | ||
| 143 | |||
| 144 | private static void readClass(ClassMapping classMapping, EntryTree<EntryMapping> mappingTree) { | ||
| 145 | ClassEntry currentClass = new ClassEntry(classMapping.getSrcName()); | ||
| 146 | String dstName = classMapping.getDstName(0); | ||
| 147 | |||
| 148 | if (dstName != null) { | ||
| 149 | dstName = dstName.substring(dstName.lastIndexOf('$') + 1); | ||
| 150 | } | ||
| 151 | |||
| 152 | mappingTree.insert(currentClass, new EntryMapping(dstName)); | ||
| 153 | |||
| 154 | for (FieldMapping fieldMapping : classMapping.getFields()) { | ||
| 155 | readField(fieldMapping, currentClass, mappingTree); | ||
| 156 | } | ||
| 157 | |||
| 158 | for (MethodMapping methodMapping : classMapping.getMethods()) { | ||
| 159 | readMethod(methodMapping, currentClass, mappingTree); | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | private static void readField(FieldMapping fieldMapping, ClassEntry parent, EntryTree<EntryMapping> mappingTree) { | ||
| 164 | mappingTree.insert(new FieldEntry(parent, fieldMapping.getSrcName(), new TypeDescriptor(fieldMapping.getSrcDesc())), | ||
| 165 | new EntryMapping(fieldMapping.getDstName(0))); | ||
| 166 | } | ||
| 167 | |||
| 168 | private static void readMethod(MethodMapping methodMapping, ClassEntry parent, EntryTree<EntryMapping> mappingTree) { | ||
| 169 | MethodEntry currentMethod; | ||
| 170 | mappingTree.insert(currentMethod = new MethodEntry(parent, methodMapping.getSrcName(), new MethodDescriptor(methodMapping.getSrcDesc())), | ||
| 171 | new EntryMapping(methodMapping.getDstName(0))); | ||
| 172 | |||
| 173 | for (MethodArgMapping methodArgMapping : methodMapping.getArgs()) { | ||
| 174 | readMethodArg(methodArgMapping, currentMethod, mappingTree); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | private static void readMethodArg(MethodArgMapping methodArgMapping, MethodEntry parent, EntryTree<EntryMapping> mappingTree) { | ||
| 179 | String methodArgSrcName = methodArgMapping.getSrcName() != null ? methodArgMapping.getSrcName() : ""; | ||
| 180 | |||
| 181 | mappingTree.insert(new LocalVariableEntry(parent, methodArgMapping.getLvIndex(), methodArgSrcName, true, null), | ||
| 182 | new EntryMapping(methodArgMapping.getDstName(0))); | ||
| 183 | } | ||
| 126 | } | 184 | } |