Skip to content

Commit

Permalink
Add table-template argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Meeples10 committed May 10, 2022
1 parent 4fe3b00 commit eced35e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Several command line arguments may be used to modify the behavior of the program

- `no-hack`: The program attempts to compensate for the aforementioned inaccuracies at high Y values by assuming that empty chunk sections are filled with air. Use this argument to disable this hack.
- `table`: Generates a simple HTML table with the collected data.
- `table-template=<path>`: When used in conjunction with `table`, the generated table will replace any instances of the string `{{{TABLE}}}` in a copy of the template file. Note that the table will not include `<table></table>` tags when using this argument.
- `version-select`: Use this argument if you want to analyze a world that was not generated with the latest version of Minecraft. Shows a popup on launch that allows the version in which the region files were generated to be selected. Selecting a version that does not match the version in which the regions were generated may result in unexpected behavior.
Alternatively, to explicitly specify a version from the command line and skip the popup, use the argument `version-select=<version>` where `<version>` is one of the following:
- `ANVIL_118` for 1.18
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/io/github/meeples10/mcresourceanalyzer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -39,6 +40,8 @@ public boolean accept(File dir, String name) {
static boolean inputOverride = false;
static boolean silent = false;
static String outputPrefix = "";
static String tableTemplatePath = "";
static String tableTemplate = "";

public static void main(String[] args) {
DECIMAL_FORMAT.setMaximumFractionDigits(10);
Expand Down Expand Up @@ -95,6 +98,19 @@ public static void main(String[] args) {
outputPrefix = arg.split("=", 2)[1].trim();
} else if(arg.equalsIgnoreCase("silent")) {
silent = true;
} else if(arg.toLowerCase().startsWith("table-template=")) {
File template = new File(arg.split("=", 2)[1].trim());
if(!template.exists() || template.isDirectory()) {
System.err.println("Invalid table template: " + template.getPath());
System.exit(1);
}
tableTemplatePath = template.getPath();
try {
tableTemplate = String.join("\n", Files.readAllLines(template.toPath()));
} catch(IOException e) {
e.printStackTrace();
System.exit(1);
}
} else {
System.err.println("Unknown argument: " + arg);
}
Expand All @@ -106,11 +122,14 @@ public static void main(String[] args) {
e.printStackTrace();
}
Main.println("Save statistics: " + saveStatistics + "\nAllow empty section hack: " + allowHack
+ "\nGenerate HTML table: " + generateTable + "\nVersion select: "
+ (versionOverride ? selectedVersion : versionSelect) + "\nModernize block IDs: " + modernizeIDs
+ "\nBlock IDs: " + BLOCK_NAMES.size() + "\nBlock IDs to merge: " + BLOCKS_TO_MERGE.size() + "\nInput: "
+ inputFile.getPath() + "\nOutput prefix: " + (outputPrefix.equals("") ? "(default)" : outputPrefix)
+ "\n--------------------------------");
+ "\nGenerate HTML table: " + generateTable
+ (generateTable
? ("\nTable template: " + (tableTemplatePath.equals("") ? "(none)" : tableTemplatePath))
: "")
+ "\nVersion select: " + (versionOverride ? selectedVersion : versionSelect) + "\nModernize block IDs: "
+ modernizeIDs + "\nBlock IDs: " + BLOCK_NAMES.size() + "\nBlock IDs to merge: "
+ BLOCKS_TO_MERGE.size() + "\nInput: " + inputFile.getPath() + "\nOutput prefix: "
+ (outputPrefix.equals("") ? "(default)" : outputPrefix) + "\n--------------------------------");
RegionAnalyzer analyzer;
if(versionSelect) {
Object returnedVersion = JOptionPane.showInputDialog(null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public String generateTable(double totalBlocks, double totalExcludingAir) {
int minY = getMinimumY();
int maxY = getMaximumY();
StringBuilder data = new StringBuilder();
data.append("<table>\n<tr><th>id</th><th>");
if(Main.tableTemplate.isEmpty()) {
data.append("<table>\n");
}
data.append("<tr><th>id</th><th>");
for(int i = minY; i < maxY; i++) {
data.append(i);
data.append("</th><th>");
Expand Down Expand Up @@ -158,7 +161,12 @@ public String generateTable(double totalBlocks, double totalExcludingAir) {
}
data.append("</tr>\n<tr>");
}
return data.substring(0, data.length() - 4) + "</table>";
String out = data.substring(0, data.length() - 4);
if(Main.tableTemplate.isEmpty()) {
return out + "</table>";
} else {
return Main.tableTemplate.replace("{{{TABLE}}}", out);
}
}

public long getStartTime() {
Expand Down

0 comments on commit eced35e

Please sign in to comment.