-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3330c1
commit 866311b
Showing
8 changed files
with
148 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.github.ijustleyxo.packmake; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class Duo<A, B> { | ||
private @NotNull A a; | ||
private @NotNull B b; | ||
|
||
public Duo(@NotNull A a, @NotNull B b) { | ||
this.a = a; | ||
this.b = b; | ||
} | ||
|
||
public @NotNull A a() { | ||
return this.a; | ||
} | ||
|
||
public @NotNull B b() { | ||
return this.b; | ||
} | ||
|
||
public void a(@NotNull A a) { | ||
this.a = a; | ||
} | ||
|
||
public void b(@NotNull B b) { | ||
this.b = b; | ||
} | ||
} |
106 changes: 98 additions & 8 deletions
106
src/main/java/com/github/ijustleyxo/packmake/PackMake.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,110 @@ | ||
package com.github.ijustleyxo.packmake; | ||
|
||
import com.github.ijustleyxo.packmake.util.console.Console; | ||
import com.github.ijustleyxo.packmake.util.console.Type; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
|
||
/** | ||
* Minecraft resource pack compiler | ||
*/ | ||
public final class PackMake { | ||
private static final @NotNull File SRC = new File("./src/"); | ||
private static final @NotNull File TAR = new File("./target/"); | ||
|
||
public static void main(String[] args) { | ||
// TODO: Resource pack creation logic | ||
PackMake.exit(); | ||
Yaml yaml = new Yaml(); | ||
List<Integer> formats = null; | ||
try { | ||
formats = yaml.load(new FileInputStream("./pm.yml")); | ||
} catch (IOException e) { | ||
System.out.println("Config load from pm.yml failed"); | ||
System.exit(1); | ||
} | ||
SRC.mkdirs(); | ||
TAR.mkdirs(); | ||
File[] files = SRC.listFiles(); | ||
if (files == null) return; | ||
for (File file : files) make( | ||
null, null, | ||
SRC, formats.stream().map(b -> new Duo<>(b, new File(TAR, b + "/"))).toList(), | ||
new File(""), new File(""), new File(file.getName())); | ||
} | ||
|
||
private static void make( | ||
@Nullable Byte lower, @Nullable Byte upper, | ||
@NotNull File srcBase, @NotNull List<Duo<Integer, File>> packBase, | ||
@NotNull File srcFolder, @NotNull File packFolder, | ||
@NotNull File srcFile) { | ||
@NotNull String name = srcFile.getName(); | ||
int start = name.indexOf('#'); // Start of config | ||
if (0 <= start) { | ||
int i = start + 1; // Skip '#' | ||
Duo<Byte, Integer> first = parseByte(name, i); // Parse first bound | ||
if (first != null) { | ||
lower = first.a(); | ||
i = first.b(); | ||
} | ||
if (name.startsWith("...", i)) { // Parse separator | ||
i += 3; | ||
|
||
Duo<Byte, Integer> second = parseByte(name, i); // Parse second bound | ||
if (second != null) { | ||
upper = second.a(); | ||
i = second.b(); | ||
} else if (first == null) | ||
System.out.println("Config warning: \"...\" is redundant in " + srcFile); // No bounds case | ||
} else if (first != null) upper = first.a(); // Single format bound | ||
name = name.substring(0, start) + name.substring(i); // Remove config from name | ||
} | ||
|
||
@Nullable Byte fLower = lower; // Filter which pack formats are still in range | ||
@Nullable Byte fUpper = upper; | ||
List<Duo<Integer, File>> selected = packBase.stream() | ||
.filter(d -> (fLower == null || fLower <= d.a()) && (fUpper == null || d.a() <= fUpper)).toList(); | ||
if (selected.isEmpty()) return; // Nothing to do | ||
|
||
File src = new File(srcBase + "/" + srcFolder + "/" + srcFile); | ||
|
||
if (src.isDirectory()) { // Descend into directory | ||
|
||
File[] files = src.listFiles(); | ||
if (files == null || files.length == 0) return; | ||
for (File f : files) make( | ||
lower, upper, | ||
srcBase, packBase, | ||
new File(srcFolder + "/" + srcFile), | ||
new File(packFolder + "/" + name), new File(f.getName())); | ||
} else { // Copy file to packs | ||
for (Duo<Integer, File> pack : selected) { | ||
File destFolder = new File(pack.b() + "/" + packFolder); | ||
File dest = new File(destFolder + "/" + name); | ||
if (dest.exists()) System.out.println(src + " is over defining " + dest); | ||
else try { | ||
destFolder.mkdirs(); | ||
Files.copy(src.toPath(), dest.toPath()); | ||
} catch (IOException e) { | ||
System.out.println("Failed to copy " + src + " to " + dest); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void exit() { | ||
Console.log(Type.DEBUG, "Exiting\n"); | ||
Console.sep(); | ||
System.exit(0); | ||
private static @Nullable Duo<Byte, Integer> parseByte(@NotNull String string, int i) { | ||
Byte result = null; | ||
int k = i + 1; | ||
while (k <= string.length()) try { | ||
result = Byte.parseByte(string.substring(i, k)); | ||
k++; | ||
} catch (NumberFormatException e) { | ||
break; | ||
} | ||
if (result == null) return null; | ||
else return new Duo<>(result, k - 1); | ||
} | ||
} |
156 changes: 0 additions & 156 deletions
156
src/main/java/com/github/ijustleyxo/packmake/util/console/Console.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/main/java/com/github/ijustleyxo/packmake/util/console/Detail.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.