Skip to content

Commit

Permalink
More book convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed May 17, 2016
1 parent 214328c commit 1bd2c73
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public BookLoader() {

// Register action protocols
StringActionProcessor.registerProtocol(new ProtocolGoToPage());
StringActionProcessor.registerProtocol(new ProtocolGoToPage(true, "-rtn"));
StringActionProcessor.registerProtocol(new ProtocolGoToPage(true, ProtocolGoToPage.GO_TO_RTN));
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/slimeknights/mantle/client/book/BookTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class BookTransformer {

public static BookTransformer IndexTranformer() { return IndexTranformer.INSTANCE; }
public static BookTransformer contentTableTransformer() { return ContentTableTransformer.INSTANCE; }
public static BookTransformer contentTableTransformerForSection(String sectionName) { return new ContentTableTransformer(sectionName); }

/**
* Called when all the sections within the book are loaded.
Expand Down Expand Up @@ -72,6 +73,16 @@ protected static class ContentTableTransformer extends BookTransformer {

public static final ContentTableTransformer INSTANCE = new ContentTableTransformer();

private final String sectionToTransform;

public ContentTableTransformer(String sectionToTransform) {
this.sectionToTransform = sectionToTransform;
}

public ContentTableTransformer() {
this.sectionToTransform = null;
}

@Override
public void transform(BookData book) {
final int ENTRIES_PER_PAGE = 24;
Expand All @@ -80,6 +91,9 @@ public void transform(BookData book) {
if(section.name.equals("index")) {
continue;
}
if(sectionToTransform != null && !section.name.equals(sectionToTransform)) {
continue;
}

int genPages = (int) Math.ceil(section.getPageCount() * 1.F / ENTRIES_PER_PAGE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

public class ProtocolGoToPage extends ActionProtocol {

public static final String GO_TO = "go-to-page";
public static final String GO_TO_RTN = GO_TO + "-rtn";

private final boolean returner;

public ProtocolGoToPage() {
this(false, "");
this(false, GO_TO);
}

public ProtocolGoToPage(boolean returner, String suffix) {
super("go-to-page" + suffix);
public ProtocolGoToPage(boolean returner, String string) {
super(string);

this.returner = returner;
}
Expand Down

0 comments on commit 1bd2c73

Please sign in to comment.