-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for a page to be module dependent if using a moduleFileRe…
…pository Will be used in Tinkers Complement as its added modifiers are dependent on certain mods/modules being loaded
- Loading branch information
1 parent
95918e9
commit d9291f5
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/main/java/slimeknights/mantle/client/book/data/PageDataModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package slimeknights.mantle.client.book.data; | ||
|
||
public class PageDataModule extends PageData { | ||
/** Module required to load this section, see {@link slimeknights.mantle.pulsar.control.PulseManager#isPulseLoaded(String)} for more details */ | ||
public String module = ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/slimeknights/mantle/client/book/data/SectionDataModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
package slimeknights.mantle.client.book.data; | ||
|
||
import slimeknights.mantle.client.book.BookLoader; | ||
import slimeknights.mantle.client.book.repository.ModuleFileRepository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
public class SectionDataModule extends SectionData { | ||
/** Module required to load this section, see {@link slimeknights.mantle.pulsar.control.PulseManager#isPulseLoaded(String)} for more details */ | ||
public String module = ""; | ||
|
||
@Override | ||
protected ArrayList<PageData> getPages(String data) { | ||
// this should always be the case, but just for safety | ||
if(source instanceof ModuleFileRepository) { | ||
// just filters out pages where the module is not loaded | ||
Predicate<String> manager = ((ModuleFileRepository)source).getManager(); | ||
return new ArrayList<>(Arrays.stream(BookLoader.GSON.fromJson(data, PageDataModule[].class)) | ||
.filter((page)->page.module.isEmpty() || manager.test(page.module)) | ||
.collect(Collectors.toList())); | ||
} | ||
return super.getPages(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters