Skip to content

Commit

Permalink
feat: add common base for category providers
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Jun 17, 2024
1 parent 4c06ffd commit 726e81f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

public abstract class CategoryProvider extends ModonomiconProviderBase {
public abstract class CategoryProvider extends CategoryProviderBase {

protected final ModonomiconProviderBase parent;
protected CategoryEntryMap entryMap;
protected BookCategoryModel category;
protected int currentSortIndex;

public CategoryProvider(ModonomiconProviderBase parent) {
super(parent.modId(), parent.lang(), parent.langs(), parent.context(), parent.condition());
this.parent = parent;
super(parent, parent.modId(), parent.lang(), parent.langs(), parent.context(), parent.condition());
this.entryMap = new CategoryEntryMap();
this.category = null;
this.currentSortIndex = 0;
}

protected CategoryEntryMap entryMap() {
public CategoryEntryMap entryMap() {
return this.entryMap;
}

Expand All @@ -52,15 +50,15 @@ protected BookEntryParentModel parent(BookEntryModel parentEntry) {
return BookEntryParentModel.create(parentEntry.getId());
}

protected BookEntryModel add(BookEntryModel entry) {
public BookEntryModel add(BookEntryModel entry) {
if (entry.getSortNumber() == -1) {
entry.withSortNumber(this.currentSortIndex++);
}
this.category.withEntry(entry);
return entry;
}

protected List<BookEntryModel> add(List<BookEntryModel> entries) {
public List<BookEntryModel> add(List<BookEntryModel> entries) {
for (var entry : entries) {
if (entry.getSortNumber() == -1) {
entry.withSortNumber(this.currentSortIndex++);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.klikli_dev.modonomicon.api.datagen;

import com.klikli_dev.modonomicon.api.datagen.book.BookEntryModel;

import java.util.List;
import java.util.Map;

public abstract class CategoryProviderBase extends ModonomiconProviderBase {
protected final ModonomiconProviderBase parent;

protected CategoryProviderBase(ModonomiconProviderBase parent, String modId, ModonomiconLanguageProvider lang, Map<String, ModonomiconLanguageProvider> translations, BookContextHelper context, ConditionHelper conditionHelper) {
super(modId, lang, translations, context, conditionHelper);
this.parent = parent;
}

public abstract CategoryEntryMap entryMap();

public abstract BookEntryModel add(BookEntryModel entry);

public abstract List<BookEntryModel> add(List<BookEntryModel> entries);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

public abstract class EntryProvider extends ModonomiconProviderBase {

protected final CategoryProvider parent;
protected final CategoryProviderBase parent;

protected BookEntryModel entry;

public EntryProvider(CategoryProvider parent) {
public EntryProvider(CategoryProviderBase parent) {
super(parent.modId(), parent.lang(), parent.langs(), parent.context(), parent.condition());
this.parent = parent;
this.entry = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public abstract class LeafletEntryProvider extends EntryProvider {
public static final String ID = "leaflet";

public LeafletEntryProvider(CategoryProvider parent) {
public LeafletEntryProvider(CategoryProviderBase parent) {
super(parent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@
/**
* A category provider that is oriented on the legacy API for easier migration.
*/
public abstract class LegacyCategoryProvider extends ModonomiconProviderBase {
public abstract class LegacyCategoryProvider extends CategoryProviderBase {

protected final ModonomiconProviderBase parent;
protected final Map<String, List<BookPageModel<?>>> cachedPages = new Object2ObjectOpenHashMap<>();
protected CategoryEntryMap entryMap;
protected BookCategoryModel category;
protected int currentSortIndex;
protected String categoryId;

public LegacyCategoryProvider(ModonomiconProviderBase parent, String categoryId) {
super(parent.modId(), parent.lang(), parent.langs(), parent.context(), parent.condition());
this.parent = parent;
super(parent, parent.modId(), parent.lang(), parent.langs(), parent.context(), parent.condition());
this.entryMap = new CategoryEntryMap();
this.category = null;
this.currentSortIndex = 0;
Expand All @@ -48,7 +46,7 @@ public String categoryId() {
return this.categoryId;
}

protected CategoryEntryMap entryMap() {
public CategoryEntryMap entryMap() {
return this.entryMap;
}

Expand Down Expand Up @@ -120,15 +118,15 @@ protected BookEntryParentModel parent(BookEntryModel parentEntry) {
return BookEntryParentModel.create(parentEntry.getId());
}

protected BookEntryModel add(BookEntryModel entry) {
public BookEntryModel add(BookEntryModel entry) {
if (entry.getSortNumber() == -1) {
entry.withSortNumber(this.currentSortIndex++);
}
this.category.withEntry(entry);
return entry;
}

protected List<BookEntryModel> add(List<BookEntryModel> entries) {
public List<BookEntryModel> add(List<BookEntryModel> entries) {
for (var entry : entries) {
if (entry.getSortNumber() == -1) {
entry.withSortNumber(this.currentSortIndex++);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ group=com.klikli_dev
mod_id=modonomicon
mod_name=Modonomicon
mod_license=MIT AND CC-BY-4.0
mod_version=1.79.0
mod_version=1.81.0
mod_authors=Kli Kli
mod_description=Data-driven minecraft in-game documentation with progress visualization.

Expand Down

0 comments on commit 726e81f

Please sign in to comment.