Skip to content

Commit

Permalink
Move output directory/file from PackGeneratorContext to PackWriterSet…
Browse files Browse the repository at this point in the history
…tings
  • Loading branch information
portlek committed Jul 12, 2024
1 parent 974575f commit a59a820
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 75 deletions.
28 changes: 0 additions & 28 deletions generator/src/main/java/net/infumia/pack/PackGeneratorContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public final class PackGeneratorContext {
private final PackReferenceMeta packReference;
private final Collection<PackReferencePart> packPartReferences;
private final Path rootDirectory;
private final Path outputDirectory;
private final Path outputFile;
private final ComponentSerializer<?, ?, String> serializer;

/**
Expand All @@ -29,8 +27,6 @@ public final class PackGeneratorContext {
* @param packReference the pack file reference. Cannot be null.
* @param packPartReferences the pack part references. Cannot be null.
* @param rootDirectory the root directory of the pack. Cannot be null.
* @param outputDirectory the output directory. Can be null.
* @param outputFile the output file. Can be null.
* @param serializer the serializer to serialize components when needed. Cannot be null.
*/
PackGeneratorContext(
Expand All @@ -39,17 +35,13 @@ public final class PackGeneratorContext {
final PackReferenceMeta packReference,
final Collection<PackReferencePart> packPartReferences,
final Path rootDirectory,
final Path outputDirectory,
final Path outputFile,
final ComponentSerializer<?, ?, String> serializer
) {
this.resourcePack = resourcePack;
this.pack = pack;
this.packReference = packReference;
this.packPartReferences = Collections.unmodifiableCollection(packPartReferences);
this.rootDirectory = rootDirectory;
this.outputDirectory = outputDirectory;
this.outputFile = outputFile;
this.serializer = serializer;
}

Expand Down Expand Up @@ -98,24 +90,6 @@ public Path rootDirectory() {
return this.rootDirectory;
}

/**
* Returns the output directory.
*
* @return the output directory. Can be null.
*/
public Path outputDirectory() {
return this.outputDirectory;
}

/**
* Returns the output file.
*
* @return the output file. Can be null.
*/
public Path outputFile() {
return this.outputFile;
}

/**
* Returns the component serializer.
*
Expand All @@ -132,8 +106,6 @@ public String toString() {
.add("pack=" + this.pack)
.add("packReference=" + this.packReference)
.add("packPartReferences=" + this.packPartReferences)
.add("outputDirectory=" + this.outputDirectory)
.add("outputFile=" + this.outputFile)
.add("serializer=" + this.serializer)
.toString();
}
Expand Down
2 changes: 0 additions & 2 deletions generator/src/main/java/net/infumia/pack/PackReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ private PackGeneratorContext read0(@NotNull final Stream<Path> walking) throws I
packReference,
packPartReferences,
this.settings.root(),
this.settings.outputDirectory(),
this.settings.outputFile(),
this.settings.serializer()
);
}
Expand Down
43 changes: 1 addition & 42 deletions generator/src/main/java/net/infumia/pack/PackReaderSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public final class PackReaderSettings {
private final Path root;
private final FileVisitOption[] visitOptions;
private final String packReferenceFileName;
private final Path outputDirectory;
private final Path outputFile;
private final ObjectMapper mapper;
private final Predicate<Path> readFilter;
private final ComponentSerializer<?, ?, String> serializer;
Expand All @@ -29,8 +27,6 @@ public final class PackReaderSettings {
* @param root the root path.
* @param visitOptions the visit options. Can be null.
* @param packReferenceFileName the pack reference file name. Cannot be null.
* @param outputDirectory the directory name. Can be null.
* @param outputFile the zip file name. Can be null.
* @param mapper the object mapper to read pack and pack part reference files. Cannot be null.
* @param readFilter the read filter for {@link Files#walk(Path, FileVisitOption...)}.
* @param serializer the serializer to serialize components when needed. Cannot be null.
Expand All @@ -39,17 +35,13 @@ public PackReaderSettings(
final Path root,
final FileVisitOption[] visitOptions,
final String packReferenceFileName,
final Path outputDirectory,
final Path outputFile,
final ObjectMapper mapper,
final Predicate<Path> readFilter,
final ComponentSerializer<?, ?, String> serializer
) {
this.root = root;
this.visitOptions = visitOptions;
this.packReferenceFileName = packReferenceFileName;
this.outputDirectory = outputDirectory;
this.outputFile = outputFile;
this.mapper = mapper;
this.readFilter = readFilter;
this.serializer = serializer;
Expand All @@ -60,30 +52,17 @@ public PackReaderSettings(
*
* @param root the root path.
* @param packReferenceFileName the pack reference file name. Cannot be null.
* @param outputDirectory the directory name. Can be null.
* @param outputFile the zip file name. Can be null.
* @param mapper the object mapper to read pack and pack part reference files. Cannot be null.
* @param readFilter the read filter for {@link Files#walk(Path, FileVisitOption...)}.
*/
public PackReaderSettings(
final Path root,
final String packReferenceFileName,
final Path outputDirectory,
final Path outputFile,
final ObjectMapper mapper,
final Predicate<Path> readFilter,
final ComponentSerializer<?, ?, String> serializer
) {
this(
root,
null,
packReferenceFileName,
outputDirectory,
outputFile,
mapper,
readFilter,
serializer
);
this(root, null, packReferenceFileName, mapper, readFilter, serializer);
}

/**
Expand Down Expand Up @@ -113,24 +92,6 @@ public String packReferenceFileName() {
return this.packReferenceFileName;
}

/**
* Returns the output directory.
*
* @return the directory output. Can be null.
*/
public Path outputDirectory() {
return this.outputDirectory;
}

/**
* Returns the zip file.
*
* @return the zip file. Can be null.
*/
public Path outputFile() {
return this.outputFile;
}

/**
* Returns the object mapper.
*
Expand Down Expand Up @@ -164,8 +125,6 @@ public String toString() {
.add("root=" + this.root)
.add("visitOptions=" + Arrays.toString(this.visitOptions))
.add("packReferenceFileName='" + this.packReferenceFileName + "'")
.add("outputDirectory=" + this.outputDirectory)
.add("outputFile=" + this.outputFile)
.add("mapper=" + this.mapper)
.add("readFilter=" + this.readFilter)
.add("serializer=" + this.serializer)
Expand Down
4 changes: 2 additions & 2 deletions generator/src/main/java/net/infumia/pack/PackWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ final class PackWriter {

PackGeneratedContext write(final PackGeneratorContext context) {
final MinecraftResourcePackWriter writer = this.settings.writer();
final Path outputDirectory = context.outputDirectory();
final Path outputDirectory = this.settings.outputDirectory();
final ResourcePack resourcePack = context.resourcePack();
if (outputDirectory != null) {
writer.writeToDirectory(outputDirectory.toFile(), resourcePack);
}
final Path outputFile = context.outputFile();
final Path outputFile = this.settings.outputFile();
if (outputFile != null) {
writer.writeToZipFile(outputFile, resourcePack);
}
Expand Down
31 changes: 30 additions & 1 deletion generator/src/main/java/net/infumia/pack/PackWriterSettings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.infumia.pack;

import java.nio.file.Path;
import java.util.StringJoiner;
import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter;

Expand All @@ -9,14 +10,24 @@
public final class PackWriterSettings {

private final MinecraftResourcePackWriter writer;
private final Path outputDirectory;
private final Path outputFile;

/**
* Ctor.
*
* @param writer the resource pack writer. Cannot be null.
* @param outputDirectory the output directory. Can be null.
* @param outputFile the output file. Can be null.
*/
public PackWriterSettings(final MinecraftResourcePackWriter writer) {
public PackWriterSettings(
final MinecraftResourcePackWriter writer,
final Path outputDirectory,
final Path outputFile
) {
this.writer = writer;
this.outputDirectory = outputDirectory;
this.outputFile = outputFile;
}

/**
Expand All @@ -28,6 +39,24 @@ public MinecraftResourcePackWriter writer() {
return this.writer;
}

/**
* Returns the output directory.
*
* @return the output directory. Can be null.
*/
public Path outputDirectory() {
return this.outputDirectory;
}

/**
* Returns the output file.
*
* @return the output file. Can be null.
*/
public Path outputFile() {
return this.outputFile;
}

@Override
public String toString() {
return new StringJoiner(", ", PackWriterSettings.class.getSimpleName() + "[", "]")
Expand Down

0 comments on commit a59a820

Please sign in to comment.