Skip to content

Commit

Permalink
Worksession from stream on 11/9/2024 (#228)
Browse files Browse the repository at this point in the history
Here, I reworked the debug section, and fixes a few bugs.

Fixed #216
Fixed #227
  • Loading branch information
CoryBorek authored Nov 10, 2024
2 parents 37c6fbe + 29a0eb3 commit 46f21ee
Show file tree
Hide file tree
Showing 28 changed files with 193 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Options {

public static final OptionSpec<Path> INPUT_DIR = PARSER.acceptsAll(Arrays.asList("i", "input", "input-dir"), "Input directory for the packs").withRequiredArg().withValuesConvertedBy(new PathConverter()).defaultsTo(Paths.get("./"));

public static final OptionSpec<Boolean> DEBUG = PARSER.accepts("debug", "Displays other output").withRequiredArg().ofType(Boolean.class).defaultsTo(true);
public static final OptionSpec<Boolean> DEBUG = PARSER.accepts("debug", "Displays other output").withRequiredArg().ofType(Boolean.class).defaultsTo(false);

public static final OptionSpec<String> TO = PARSER.accepts("to", "Updates to version").withRequiredArg().ofType(String.class).defaultsTo("1.13");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public GUI() {
convertButton.setVisible(false);
try {
if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, to))
new BackwardsPackConverter(from, to, light, minify, Paths.get("./"), true, out).runDir();
new BackwardsPackConverter(from, to, light, minify, Paths.get("./"), false, out).runDir();
else
new ForwardsPackConverter(from, to, light, minify, Paths.get("./"), true, out).runDir();
} catch (IOException ioException) {
out.println(Arrays.toString(ioException.getStackTrace()));
new ForwardsPackConverter(from, to, light, minify, Paths.get("./"), false, out).runDir();
} catch (Exception exception) {
out.println(Arrays.toString(exception.getStackTrace()));
}
convertButton.setVisible(true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ public BackwardsPackConverter(String from, String to, String light, boolean mini
if (!minify)
gsonBuilder.setPrettyPrinting();
gson = gsonBuilder.create();
DEBUG = debug;
Logger.setDebug(debug);
Logger.setStream(out);
Logger.log(from);
Logger.log(to);
Logger.log("Converting packs from: " + from + " to " + to);
this.INPUT_DIR = input;
converterRunner(from, to, light);
}
Expand Down Expand Up @@ -88,15 +87,19 @@ private void converterRunner(String from, String to, String light) {
public void runPack(Pack pack) {
try {
Logger.log("Converting " + pack);
Logger.addTab();
pack.getHandler().setup();
Logger.log(" Running Converters");
Logger.log("Running Converters");
for (Converter converter : converters.values()) {
if (DEBUG)
Logger.log(" Running " + converter.getClass().getSimpleName());
Logger.addTab();
Logger.log("Running " + converter.getClass().getSimpleName());
converter.convert(pack);
Logger.subTab();
}
pack.getHandler().finish();
Logger.subTab();
} catch (Throwable t) {
Logger.resetTab();
Logger.log("Failed to convert!");
Util.propagate(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public void convert(Pack pack) throws IOException {
}
if (anyChanges) {
JsonUtil.writeJson(packConverter.getGson(), file, json);
if (PackConverter.DEBUG)
Logger.log(" Converted " + file.getFileName());
Logger.debug("Converted " + file.getFileName());
}
} catch (IOException e) {
Util.propagate(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void convert(Pack pack) throws IOException {
try {
int modelNoJson = model.getFileName().toString().indexOf(".json");
String file2 = model.getFileName().toString().substring(0, modelNoJson);
Logger.log("Saving: " + file2 + ".lang");
Logger.debug("Saving: " + file2 + ".lang");
out.store(
new FileOutputStream(
pack.getWorkingPath()
Expand All @@ -103,7 +103,7 @@ public void convert(Pack pack) throws IOException {
for (int i = 0; i < models.size(); i++) {
Path langFilePath = pack.getWorkingPath()
.resolve(("assets/minecraft/lang/" + models.get(i)).replace("/", File.separator));
Logger.log("Deleting: " + langFilePath);
Logger.debug("Deleting: " + langFilePath);
Files.delete(langFilePath);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ protected void remapProperties(Path path) throws IOException {
.filter(path1 -> path1.toString().endsWith(".properties"))
.forEach(model -> {
try (InputStream input = new FileInputStream(model.toString())) {
if (PackConverter.DEBUG)
Logger.log("Updating:" + model.getFileName());
Logger.debug("Updating:" + model.getFileName());
PropertiesEx prop = new PropertiesEx();
prop.load(input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ protected void remapModelJson(Path models) throws IOException {
&& JsonUtil.readJson(packConverter.getGson(), model).isJsonObject())
jsonObject = JsonUtil.readJson(packConverter.getGson(), model);
else {
if (PackConverter.DEBUG) {
Logger.log("Could not convert model: " + model.getFileName());
Logger.debug("Could not convert model: " + model.getFileName());
Logger.addTab();
if (JsonUtil.readJson(packConverter.getGson(), model) == null)
Logger.log("Check for Syntax Errors in file.");
Logger.debug("Check for Syntax Errors in file.");
else
Logger.log("File is not JSON Object.");
}
Logger.debug("File is not JSON Object.");
Logger.subTab();
return;
}

Expand Down Expand Up @@ -223,8 +223,7 @@ else if (value.startsWith("item/"))
}

if (!JsonUtil.readJson(packConverter.getGson(), model).equals(jsonObject)) {
if (PackConverter.DEBUG)
Logger.log("Updating Model: " + model.getFileName());
Logger.debug("Updating Model: " + model.getFileName());
JsonUtil.writeJson(packConverter.getGson(), model, jsonObject);
}
} catch (IOException e) {
Expand Down Expand Up @@ -354,7 +353,7 @@ protected String setParent(String prefix, String path, String parent, String ite
String parent2 = parent.replace(prefix, "");
JsonObject file = JsonUtil.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item);
if (file == null) {
Logger.log("Prefix Failed on: " + parent);
Logger.debug("Prefix Failed on: " + parent);
return "";
}
return file.has(parent2) ? prefix + file.get(parent2).getAsString() : parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ public void convert(Pack pack) throws IOException {
&& from > Util.getVersionProtocol(packConverter.getGson(), "1.13")) {
// OptiFine conversion
if (minecraftPath.resolve("mcpatcher").toFile().exists()) {
if (PackConverter.DEBUG)
Logger.log("MCPatcher exists, switching to optifine");
Logger.debug("MCPatcher exists, switching to optifine");
if (minecraftPath.resolve("optifine").toFile().exists()) {
if (PackConverter.DEBUG)
Logger.log("OptiFine exists, merging directories");
Logger.debug("OptiFine exists, merging directories");
FileUtil.mergeDirectories(minecraftPath.resolve("optifine").toFile(),
minecraftPath.resolve("mcpatcher").toFile());
} else
Expand Down Expand Up @@ -182,8 +180,7 @@ public void convert(Pack pack) throws IOException {
// Less than 1.12
if (from > Util.getVersionProtocol(packConverter.getGson(), "1.13")
&& to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) {
if (PackConverter.DEBUG)
Logger.log("Finding files that are greater than 1.12");
Logger.debug("Finding files that are greater than 1.12");
findFiles(texturesPath);
}
}
Expand Down Expand Up @@ -220,14 +217,12 @@ protected void findFiles(Path path) throws IOException {
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
if (file.getName().equals("item")) {
if (PackConverter.DEBUG)
Logger.log("Found Items folder, renaming");
Logger.debug("Found Items folder, renaming");
FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("item", "items"));
}

if (file.getName().equals("block")) {
if (PackConverter.DEBUG)
Logger.log("Found blocks folder, renaming");
Logger.debug("Found blocks folder, renaming");
FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("block", "blocks"));
}

Expand All @@ -238,8 +233,7 @@ protected void findFiles(Path path) throws IOException {
FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("[()]", ""));

if (!file.getName().equals(file.getName().toLowerCase()))
if (PackConverter.DEBUG)
Logger.log("Renamed: " + file.getName() + "->" + file.getName().toLowerCase());
Logger.debug("Renamed: " + file.getName() + "->" + file.getName().toLowerCase());

FileUtil.renameFile(path.resolve(file.getName()), file.getName().toLowerCase());
}
Expand All @@ -266,8 +260,8 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO
newName + extension);
if (ret == null)
return;
if (ret && PackConverter.DEBUG)
Logger.log(" Renamed: " + name + extension + "->" + newName + extension);
if (ret)
Logger.debug("Renamed: " + name + extension + "->" + newName + extension);
else if (!ret)
System.err.println(" Failed to rename: " + name + extension + "->" + newName + extension);
});
Expand All @@ -282,11 +276,10 @@ else if (!ret)
newName + extension);
if (ret == null)
return;
if (ret && PackConverter.DEBUG)
Logger.log(" Renamed: " + name + extension + "->" + newName + extension);
if (ret)
Logger.debug("Renamed: " + name + extension + "->" + newName + extension);
else if (!ret)
System.err.println(
" Failed to rename: " + name + extension + "->" + newName + extension);
Logger.log("Failed to rename: " + name + extension + "->" + newName + extension);
}
});
}
Expand All @@ -307,9 +300,8 @@ else if (!ret)
Boolean ret = FileUtil.renameFile(path1, newName + extension);
if (ret == null)
return;
if (ret && PackConverter.DEBUG)
Logger.log(
" Renamed: " + path1.getFileName().toString() + "->" + newName + extension);
if (ret)
Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newName + extension);
else if (!ret)
System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newName
+ extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void convert(Pack pack) throws IOException {

int newX = (int) (mapped >> 32);
int newY = (int) (long) mapped;
Logger.log(" Mapping " + x + "," + y + " to " + newX + "," + newY);
Logger.log("Mapping " + x + "," + y + " to " + newX + "," + newY);

g2d.drawImage(image.getSubimage(x * scale, y * scale, 8 * scale, 8 * scale), newX * scale, newY * scale,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ public ForwardsPackConverter(String from, String to, String light, boolean minif
if (!minify)
gsonBuilder.setPrettyPrinting();
gson = gsonBuilder.create();
DEBUG = debug;
Logger.setDebug(debug);
Logger.setStream(out);
Logger.log(from);
Logger.log(to);
Logger.log("Converting packs from: " + from + " to " + to);
this.INPUT_DIR = input;
converterRunner(from, to, light);
}
Expand Down Expand Up @@ -122,14 +121,18 @@ public void runPack(Pack pack) {
try {
Logger.log("Converting " + pack);
pack.getHandler().setup();
Logger.log(" Running Converters");
Logger.addTab();
Logger.log("Running Converters");
for (Converter converter : converters.values()) {
if (DEBUG)
Logger.log(" Running " + converter.getClass().getSimpleName());
Logger.addTab();
Logger.log("Running " + converter.getClass().getSimpleName());
converter.convert(pack);
Logger.subTab();
}
Logger.subTab();
pack.getHandler().finish();
} catch (Throwable t) {
Logger.resetTab();
Logger.log("Failed to convert!");
Util.propagate(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,28 @@ protected void fixAnimations(Path animations) throws IOException {
try {
JsonObject json = JsonUtil.readJson(packConverter.getGson(), file);

boolean anyChanges = false;
JsonElement animationElement = json.get("animation");
if (animationElement instanceof JsonObject) {
JsonObject animationObject = (JsonObject) animationElement;
if (json != null) {
boolean anyChanges = false;
JsonElement animationElement = json.get("animation");
if (animationElement instanceof JsonObject) {
JsonObject animationObject = (JsonObject) animationElement;

// TODO: Confirm this doesn't break any packs
animationObject.remove("width");
animationObject.remove("height");
// TODO: Confirm this doesn't break any packs
animationObject.remove("width");
animationObject.remove("height");

anyChanges = true;
}
anyChanges = true;
}

if (anyChanges) {
JsonUtil.writeJson(packConverter.getGson(), file, json);
if (PackConverter.DEBUG)
Logger.log(" Converted " + file.getFileName());
if (anyChanges) {
JsonUtil.writeJson(packConverter.getGson(), file, json);
Logger.debug("Converted " + file.getFileName());
}
} else {
Logger.log("File: " + file.getFileName() + " is not a valid JSON file.");
}
} catch (IOException e) {
Logger.log("Failed to convert file: " + file.getFileName());
Util.propagate(e);
}
});
Expand Down
Loading

0 comments on commit 46f21ee

Please sign in to comment.