Skip to content

Commit

Permalink
Fix nested subcategories
Browse files Browse the repository at this point in the history
  • Loading branch information
IotaBread committed Jun 22, 2024
1 parent 32bc24e commit 2818d5b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
26 changes: 14 additions & 12 deletions src/main/java/me/bymartrixx/vtd/data/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

@JsonAdapter(Category.CustomTypeAdapterFactory.class)
public class Category {
public static final List<String> HARD_INCOMPATIBLE_CATEGORIES = List.of("Menu Panoramas", "Options Backgrounds", "Colorful Slime");
public static final List<String> HARD_INCOMPATIBLE_CATEGORIES = List.of(
"Crosshairs", "Hearts", "Hunger Bars", "Menu Panoramas", "Options Backgrounds", // GUI
"Slimes", "Elytra", "Enchantment Glints" // World of Color
);

@SerializedName("category")
private final String name;
Expand Down Expand Up @@ -162,12 +165,6 @@ public Category getParent() {
return this.parent;
}

@Override
@Nullable
public List<SubCategory> getSubCategories() {
return null;
}

@Override
public String getId() {
return this.getParent().getId() + "." + super.getId();
Expand All @@ -191,17 +188,22 @@ public void write(JsonWriter out, T value) throws IOException {
defaultAdapter.write(out, value);
}

private void linkSubCategories(Category category) {
if (category.getSubCategories() != null && !category.getSubCategories().isEmpty()) {
for (SubCategory subCategory : category.getSubCategories()) {
subCategory.parent = category;
linkSubCategories(subCategory);
}
}
}

@Override
public T read(JsonReader in) throws IOException {
T result = defaultAdapter.read(in);

if (result instanceof Category category) {
// Link sub categories to their parents post-deserialization
if (category.getSubCategories() != null) {
for (SubCategory subCategory : category.getSubCategories()) {
subCategory.parent = category;
}
}
linkSubCategories(category);
}

return result;
Expand Down
35 changes: 17 additions & 18 deletions src/main/java/me/bymartrixx/vtd/gui/widget/PackSelectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,8 @@ public void buildIncompatibilityGroups(List<Category> categories) {

// Create all incompatibility groups
List<Pack> packs = new ArrayList<>();
for (Category c : categories) {
if (c.getSubCategories() != null) {
for (Category.SubCategory subCategory : c.getSubCategories()) {
if (subCategory.isHardIncompatible()) {
this.allIncompatibilityGroups.add(new CategoryIncompatibilityGroup(subCategory));
continue;
}

packs.addAll(subCategory.getPacks());
}
}

if (c.isHardIncompatible()) {
this.allIncompatibilityGroups.add(new CategoryIncompatibilityGroup(c));
continue;
}

packs.addAll(c.getPacks());
for (Category category : categories) {
this.collectCategoryPacks(packs, category);
}

for (Pack pack : packs) {
Expand All @@ -77,6 +61,21 @@ public void buildIncompatibilityGroups(List<Category> categories) {
}
}

private void collectCategoryPacks(List<Pack> packs, Category category) {
if (category.getSubCategories() != null && !category.getSubCategories().isEmpty()) {
for (Category subCategory : category.getSubCategories()) {
collectCategoryPacks(packs, subCategory);
}
}

if (category.isHardIncompatible()) {
this.allIncompatibilityGroups.add(new CategoryIncompatibilityGroup(category));
return;
}

packs.addAll(category.getPacks());
}

public void toggleSelection(PackSelectionListWidget.PackEntry entry) {
Pack pack = entry.getPack();
PackSelectionData data = entry.selectionData;
Expand Down

0 comments on commit 2818d5b

Please sign in to comment.