Skip to content

Commit

Permalink
move all unified recipes to own namespace (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlnt authored Aug 24, 2022
2 parents 55921aa + 06c2df5 commit a8d365d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ public void dump(boolean dumpOverview, boolean dumpUnify, boolean dumpDuplicate)
String last = "# Last execution: " + format.format(new Date(startTime));

if (dumpOverview) {
StringBuilder overviewBuilder = new StringBuilder();
overviewBuilder.append(last).append("\n");
dumpOverview(overviewBuilder);
write(overviewBuilder, AlmostUnifiedPlatform.INSTANCE.getLogPath(), "overview_dump.txt");
FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getLogPath(), "overview_dump.txt", sb -> {
sb.append(last).append("\n");
dumpOverview(sb);
});
}

if (dumpUnify) {
StringBuilder unifyStringBuilder = new StringBuilder();
unifyStringBuilder.append(last).append("\n");
dumpUnifyRecipes(unifyStringBuilder, true);
write(unifyStringBuilder, AlmostUnifiedPlatform.INSTANCE.getLogPath(), "unify_dump.txt");
FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getLogPath(), "unify_dump.txt", sb -> {
sb.append(last).append("\n");
dumpUnifyRecipes(sb);
});
}

if (dumpDuplicate) {
StringBuilder duplicatesStringBuilder = new StringBuilder();
duplicatesStringBuilder.append(last).append("\n");
dumpDuplicates(duplicatesStringBuilder);
write(duplicatesStringBuilder, AlmostUnifiedPlatform.INSTANCE.getLogPath(), "duplicates_dump.txt");
FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getLogPath(), "duplicates_dump.txt", sb -> {
sb.append(last).append("\n");
dumpDuplicates(sb);
});
}

}
Expand All @@ -61,17 +61,22 @@ private void dumpDuplicates(StringBuilder stringBuilder) {
.toList();
if (duplicates.isEmpty()) return;

stringBuilder.append(duplicates.stream().map(link -> link
.getRecipes()
stringBuilder.append(duplicates
.stream()
.sorted(Comparator.comparing(r -> r.getId().toString()))
.map(recipe -> "\t\t- " + recipe.getId() + "\n")
.collect(Collectors.joining("",
"\t" + link.getMaster().getId() + " (Renamed to: " + link.createNewRecipeId() + ")\n",
"\n"))).collect(Collectors.joining("", type + " {\n", "}\n\n")));
.map(this::createDuplicatesDump)
.collect(Collectors.joining("", type + " {\n", "}\n\n")));
});
}

private String createDuplicatesDump(RecipeLink.DuplicateLink link) {
return link
.getRecipes()
.stream()
.sorted(Comparator.comparing(r -> r.getId().toString()))
.map(r -> "\t\t- " + r.getId() + "\n")
.collect(Collectors.joining("", String.format("\t%s\n", link.getMaster().getDumpInfo()), "\n"));
}

private void dumpOverview(StringBuilder stringBuilder) {
stringBuilder
.append("# Overview:\n")
Expand Down Expand Up @@ -127,22 +132,21 @@ private void dumpOverview(StringBuilder stringBuilder) {
});
}

private void dumpUnifyRecipes(StringBuilder stringBuilder, boolean full) {
private void dumpUnifyRecipes(StringBuilder stringBuilder) {
getSortedUnifiedRecipeTypes().forEach(type -> {
stringBuilder.append(type.toString()).append(" {\n");

getSortedUnifiedRecipes(type).forEach(recipe -> {
stringBuilder.append("\t- ").append(recipe.getId()).append("\n");
if (full) {
stringBuilder
.append("\t\t Original: ")
.append(recipe.getOriginal().toString())
.append("\n");
stringBuilder
.append("\t\t Transformed: ")
.append(recipe.getUnified() == null ? "NOT UNIFIED" : recipe.getUnified().toString())
.append("\n\n");
}
stringBuilder
.append("\t- ")
.append(recipe.getDumpInfo())
.append("\n")
.append("\t\t Original: ")
.append(recipe.getOriginal().toString())
.append("\n")
.append("\t\t Transformed: ")
.append(recipe.getUnified() == null ? "NOT UNIFIED" : recipe.getUnified().toString())
.append("\n\n");
});

stringBuilder.append("}\n\n");
Expand All @@ -165,13 +169,7 @@ private Stream<RecipeLink> getSortedUnifiedRecipes(ResourceLocation type) {
return result.getUnifiedRecipes(type).stream().sorted(Comparator.comparing(r -> r.getId().toString()));
}

private void write(StringBuilder stringBuilder, Path path, String fileName) {
FileUtils.write(path, fileName, sb -> sb.append(stringBuilder));
}

private long getTotalTime() {
return endTime - startTime;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ public JsonObject getActual() {
return getUnified() != null ? getUnified() : getOriginal();
}

public ResourceLocation createNewRecipeId() {
StringBuilder sb = new StringBuilder();
if (isUnified()) sb.append("u");
if (hasDuplicateLink()) sb.append("d");
if (!sb.isEmpty()) sb.append("/");
sb.append(getId().getNamespace()).append("/").append(getId().getPath());
return new ResourceLocation(BuildConfig.MOD_ID, sb.toString());
}

public String getDumpInfo() {
if (isUnified() || hasDuplicateLink()) {
return getId() + " (Renamed to: " + createNewRecipeId() + ")";
}

return getId().toString();
}

public static final class DuplicateLink {
private final Set<RecipeLink> recipes = new HashSet<>();
private RecipeLink currentMaster;
Expand Down Expand Up @@ -200,10 +217,5 @@ public Set<RecipeLink> getRecipes() {
public String toString() {
return "Link{currentMaster=" + currentMaster + ", recipes=" + recipes.size() + "}";
}

public ResourceLocation createNewRecipeId() {
String id = String.format("%s_%s", currentMaster.getId().getNamespace(), currentMaster.getId().getPath());
return new ResourceLocation(BuildConfig.MOD_ID, id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ private void transformRecipes(List<RecipeLink> recipeLinks, BiConsumer<ResourceL
}

for (RecipeLink.DuplicateLink link : duplicates) {
link.getRecipes().forEach(recipe -> onRemove.accept(recipe.getId()));
onAdd.accept(link.createNewRecipeId(), link.getMaster().getActual());
link.getRecipes().forEach(recipe -> {
onRemove.accept(recipe.getId());
unified.remove(recipe);
});
onAdd.accept(link.getMaster().createNewRecipeId(), link.getMaster().getActual());
}
for (RecipeLink link : unified) {
onRemove.accept(link.getId());
onAdd.accept(link.createNewRecipeId(), link.getActual());
}
}

Expand Down

0 comments on commit a8d365d

Please sign in to comment.