mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed issues loading spellbook chapters
This commit is contained in:
parent
6594e30d18
commit
667b6056f5
12 changed files with 21 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.minelittlepony.unicopia.client.gui.spellbook;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*;
|
||||
import com.minelittlepony.unicopia.client.gui.spellbook.element.DynamicContent;
|
||||
import com.minelittlepony.unicopia.container.spellbook.SpellbookChapter;
|
||||
|
|
|
@ -91,7 +91,7 @@ public class DynamicContent implements Content {
|
|||
rightPanel.init(screen, pageIndex + 1);
|
||||
}
|
||||
|
||||
class Page implements Drawable {
|
||||
public class Page implements Drawable {
|
||||
private final Text title;
|
||||
private final int level;
|
||||
private final int color;
|
||||
|
@ -197,5 +197,10 @@ public class DynamicContent implements Content {
|
|||
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DynamicContents$Page[title=" + title + ",elements=" + elements + "]";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@ public interface PageElement extends Drawable {
|
|||
byte t = b.readByte();
|
||||
return switch (t) {
|
||||
case 1 -> formatLine(capture(b.readIdentifier(), id -> Registries.ITEM.get(id).getDefaultStack().getName()), "item", count);
|
||||
case 2 -> formatLine(Trait.PACKET_CODEC.decode(b)::getShortName, "trait", count);
|
||||
case 2 -> formatLine(Trait.fromId(b.readIdentifier()).get()::getShortName, "trait", count);
|
||||
case 3 -> Suppliers.ofInstance(TextCodecs.PACKET_CODEC.decode(b));
|
||||
case 4 -> formatLine(SpellType.getKey(b.readIdentifier())::getName, "spell", count);
|
||||
default -> throw new IllegalArgumentException("Unexpected value: " + t);
|
||||
|
|
|
@ -20,7 +20,7 @@ public record Chapter (
|
|||
TabSide.CODEC.fieldOf("side").forGetter(Chapter::side),
|
||||
Codec.INT.fieldOf("y_position").forGetter(Chapter::tabY),
|
||||
Codec.INT.optionalFieldOf("color", 0).forGetter(Chapter::color),
|
||||
Contents.CODEC.fieldOf("contents").forGetter(Chapter::contents)
|
||||
Contents.CODEC.fieldOf("content").forGetter(Chapter::contents)
|
||||
).apply(instance, Chapter::new));
|
||||
|
||||
record Contents(List<Page> pages) {
|
||||
|
@ -35,10 +35,10 @@ public record Chapter (
|
|||
List<ChapterPageElement> elements
|
||||
) {
|
||||
public static final Codec<Page> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
TextCodecs.CODEC.fieldOf("title").forGetter(Page::title),
|
||||
Codec.INT.fieldOf("level").forGetter(Page::level),
|
||||
TextColor.CODEC.fieldOf("color").xmap(TextColor::getRgb, TextColor::fromRgb).forGetter(Page::level),
|
||||
ChapterPageElement.CODEC.listOf().fieldOf("elements").forGetter(Page::elements)
|
||||
TextCodecs.CODEC.optionalFieldOf("title", Text.empty()).forGetter(Page::title),
|
||||
Codec.INT.optionalFieldOf("level", 0).forGetter(Page::level),
|
||||
TextColor.CODEC.xmap(TextColor::getRgb, TextColor::fromRgb).optionalFieldOf("color", 0).forGetter(Page::color),
|
||||
ChapterPageElement.CODEC.listOf().optionalFieldOf("elements", List.of()).forGetter(Page::elements)
|
||||
).apply(instance, Page::new));
|
||||
|
||||
public void toBuffer(RegistryByteBuf buffer) {
|
||||
|
|
|
@ -61,6 +61,7 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
|
|||
try {
|
||||
chapters = data.entrySet().stream().map(entry -> {
|
||||
return Chapter.CODEC.decode(JsonOps.INSTANCE, entry.getValue())
|
||||
.ifError(error -> LOGGER.error("Could not load spellbook chapters due to exception {}", error))
|
||||
.result()
|
||||
.map(Pair::getFirst)
|
||||
.map(chapter -> new IdentifiableChapter(entry.getKey(), chapter))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"side": "RIGHT",
|
||||
"side": "right",
|
||||
"y_position": 4,
|
||||
"color": 0,
|
||||
"content": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"side": "RIGHT",
|
||||
"side": "right",
|
||||
"y_position": 7,
|
||||
"color": 0,
|
||||
"content": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"side": "RIGHT",
|
||||
"side": "right",
|
||||
"y_position": 5,
|
||||
"color": 0,
|
||||
"content": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"side": "RIGHT",
|
||||
"side": "right",
|
||||
"y_position": 2,
|
||||
"color": 0,
|
||||
"content": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"side": "RIGHT",
|
||||
"side": "right",
|
||||
"y_position": 3,
|
||||
"color": 0,
|
||||
"content": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"side": "RIGHT",
|
||||
"side": "right",
|
||||
"y_position": 0,
|
||||
"color": 0,
|
||||
"content": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"side": "RIGHT",
|
||||
"side": "right",
|
||||
"y_position": 6,
|
||||
"color": 0,
|
||||
"content": {
|
||||
|
|
Loading…
Reference in a new issue