Skip to content

Commit

Permalink
add readMappings api methods in Enigma
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Dec 24, 2024
1 parent af6a262 commit 51bc301
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions enigma/src/main/java/org/quiltmc/enigma/api/Enigma.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.quiltmc.enigma.api.analysis.index.jar.MainJarIndex;
import org.quiltmc.enigma.api.analysis.index.mapping.MappingsIndex;
import org.quiltmc.enigma.api.class_provider.ProjectClassProvider;
import org.quiltmc.enigma.api.translation.mapping.serde.MappingParseException;
import org.quiltmc.enigma.impl.analysis.ClassLoaderClassProvider;
import org.quiltmc.enigma.api.service.EnigmaService;
import org.quiltmc.enigma.api.service.EnigmaServiceContext;
Expand Down Expand Up @@ -197,6 +198,31 @@ public Optional<ReadWriteService> getReadWriteService(Path path) {
return this.parseFileType(path).flatMap(this::getReadWriteService);
}

/**
* Automatically determines the file type of and reads the provided mappings.
* @param path the path to read
* @return the read mappings
*/
public Optional<EntryTree<EntryMapping>> readMappings(Path path) throws MappingParseException, IOException {
return this.readMappings(path, ProgressListener.createEmpty());
}

/**
* Automatically determines the file type of and reads the provided mappings.
* @param path the path to read
* @param progress a progress listener to use when reading
* @return the read mappings
*/
public Optional<EntryTree<EntryMapping>> readMappings(Path path, ProgressListener progress) throws MappingParseException, IOException {
var service = this.getReadWriteService(path);

if (service.isPresent()) {
return Optional.ofNullable(service.get().read(path, progress));
}

return Optional.empty();
}

/**
* Searches for and returns a service with a matching id to the provided {@code id}.
* @param type the type of the searched service
Expand Down

0 comments on commit 51bc301

Please sign in to comment.