-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a collection illustration type instead of lists
This allows more flexible illustration definitions in the map.
- Loading branch information
1 parent
5d430e0
commit 0ebf44a
Showing
13 changed files
with
151 additions
and
48 deletions.
There are no files selected for viewing
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
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
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
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
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
74 changes: 74 additions & 0 deletions
74
.../java/org/ladysnake/blabber/impl/common/illustrations/DialogueIllustrationCollection.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,74 @@ | ||
/* | ||
* Blabber | ||
* Copyright (C) 2022-2024 Ladysnake | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; If not, see <https://www.gnu.org/licenses>. | ||
*/ | ||
package org.ladysnake.blabber.impl.common.illustrations; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.ladysnake.blabber.api.DialogueIllustration; | ||
import org.ladysnake.blabber.api.DialogueIllustrationType; | ||
import org.ladysnake.blabber.impl.common.BlabberRegistrar; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public record DialogueIllustrationCollection(List<DialogueIllustration> sub) implements DialogueIllustration { | ||
private static final Codec<DialogueIllustrationCollection> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.list(DialogueIllustrationType.CODEC).fieldOf("sub").forGetter(DialogueIllustrationCollection::sub) | ||
).apply(instance, DialogueIllustrationCollection::new)); | ||
|
||
public static final DialogueIllustrationType<DialogueIllustrationCollection> TYPE = new DialogueIllustrationType<>( | ||
CODEC, | ||
buf -> new DialogueIllustrationCollection(buf.readList(b -> { | ||
DialogueIllustrationType<?> type = b.readRegistryValue(BlabberRegistrar.ILLUSTRATION_REGISTRY); | ||
assert type != null; | ||
return type.readFromPacket(b); | ||
})), | ||
(buf, item) -> | ||
buf.writeCollection(item.sub, (b, i) -> { | ||
// Write the type, then the packet itself. | ||
b.writeRegistryValue(BlabberRegistrar.ILLUSTRATION_REGISTRY, i.getType()); | ||
i.getType().writeToPacketUnsafe(b, i); | ||
}) | ||
); | ||
|
||
@Override | ||
public void render(DrawContext context, TextRenderer textRenderer, int x, int y, int mouseX, int mouseY, float tickDelta) { | ||
for (DialogueIllustration i : sub) { | ||
i.render(context, textRenderer, x, y, mouseX, mouseY, tickDelta); | ||
} | ||
} | ||
|
||
@Override | ||
public DialogueIllustrationType<? extends DialogueIllustration> getType() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public DialogueIllustration parseText(@Nullable ServerCommandSource source, @Nullable Entity sender) { | ||
List<DialogueIllustration> parsedSub = new ArrayList<>(sub.size()); | ||
for (DialogueIllustration illustration : sub) { | ||
parsedSub.add(illustration.parseText(source, sender)); | ||
} | ||
return new DialogueIllustrationCollection(parsedSub); | ||
} | ||
} |
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
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
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
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
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
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,20 @@ | ||
{ | ||
"states": { | ||
"start": { | ||
"text": "It takes determination to ascend to the top of this world, mortal. What do you want?", | ||
"choices": [ | ||
{ | ||
"text": "I came here to demand a favour.", | ||
"next": "b" | ||
} | ||
], | ||
"illustrations": ["nonexistent"] | ||
}, | ||
"b": { | ||
"text": "", | ||
"choices": [], | ||
"type": "end_dialogue" | ||
} | ||
}, | ||
"start_at": "start" | ||
} |
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