protected PageData addPage(SectionData data, String name, String type, PageContent content) { PageData page = new PageData(true); page.source = data.source; page.parent = data; page.name = name; page.type = type; page.content = content; page.load(); data.pages.add(page); return page; } }
public static List<ContentPageIconList> getPagesNeededForItemCount(int count, SectionData data, String title) { List<ContentPageIconList> listPages = Lists.newArrayList(); while(count > 0) { ContentPageIconList overview = new ContentPageIconList(); PageData page = new PageData(true); page.source = data.source; page.parent = data; page.content = overview; page.load(); data.pages.add(page); overview.title = title; listPages.add(overview); count -= overview.getMaxIconCount(); } // ensure same size for all if(listPages.size() > 1) { listPages.forEach(page -> page.maxScale = 1f); } return listPages; } }
@Override public void transform(BookData book, SectionData data) { ContentListing listing = new ContentListing(); listing.title = book.translate(sectionName); PageData listingPage = new PageData(true); listingPage.name = sectionName; listingPage.source = data.source; listingPage.parent = data; listingPage.content = listing; data.pages.forEach(sectionPage -> processPage(book, listing, sectionPage)); if(listing.hasEntries()) { listingPage.load(); data.pages.add(0, listingPage); } }
@Override public void update(GuiBook.AdvancementCache advancementCache) { pages.clear(); List<SectionData> visibleSections = parent.getVisibleSections(advancementCache); if(visibleSections.isEmpty()) { return; } visibleSections.remove(0); PageData[] pages = new PageData[(int) Math.ceil(visibleSections.size() / 9F)]; for(int i = 0; i < pages.length; i++) { pages[i] = new PageData(true); pages[i].name = "page" + (i + 1); ContentSectionList content = new ContentSectionList(); pages[i].content = content; for(int j = i * 9; j - i * 9 < 9 && j < visibleSections.size(); j++) { content.addSection(visibleSections.get(j)); } } this.pages = new ArrayList<>(Arrays.asList(pages)); } };
@Override public void load() { if(name == null) { name = "section" + parent.unnamedSectionCounter++; } name = name.toLowerCase(); if(!data.equals("no-load")) { IResource pagesInfo = source.getResource(source.getResourceLocation(data)); if(pagesInfo != null) { String data = source.resourceToString(pagesInfo); if(!data.isEmpty()) { try { pages = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(data, PageData[].class))); } catch(Exception e) { pages = new ArrayList<>(); PageData pdError = new PageData(true); pdError.name = "errorrenous"; pdError.content = new ContentError("Failed to load section " + name + ".", e); pages.add(pdError); } } } } for(PageData page : pages) { page.parent = this; page.source = source; page.load(); } icon.location = source.getResourceLocation(icon.file, true); }
pages[i] = new PageData(true); pages[i].name = "tableofcontents" + i; TextData[] text = new TextData[i > pages.length - 1 ? ENTRIES_PER_PAGE : section
SectionData error = new SectionData(); error.name = "errorenous"; PageData page = new PageData(true); page.name = "errorenous"; page.content = new ContentError("Failed to load repository " + repo.toString() + ".", e); SectionData section = new SectionData(true); section.name = "errorenous"; PageData page = new PageData(true); page.name = "errorenous"; page.content = new ContentError("Failed to load the book due to an unexpected error.", e);