Skip to content

Commit

Permalink
Make chapter contents translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Jan 30, 2024
1 parent e15d64f commit d08de6f
Show file tree
Hide file tree
Showing 11 changed files with 845 additions and 631 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ protected void apply(Map<Identifier, JsonElement> data, ResourceManager manager,
}
}

private static Text readText(JsonElement json) {
return json.isJsonPrimitive() ? Text.translatable(json.getAsString()) : Text.Serializer.fromJson(json);
}

public enum Flow {
NONE, LEFT, RIGHT
}

public record Chapter (
Identifier id,
TabSide side,
Expand All @@ -103,7 +111,7 @@ private static List<Page> loadContent(JsonObject json) {
.filter(pages -> pages.size() > 0)
.stream()
.flatMap(pages -> StreamSupport.stream(pages.spliterator(), false))
.map(Page::new)
.map(Page::of)
.toList();
}

Expand All @@ -122,13 +130,19 @@ private record Page (
int level,
List<Element> elements
) {
public Page(JsonElement json) {
private static final Page EMPTY = new Page(Text.empty(), 0, List.of());

public static Page of(JsonElement json) {
return json.isJsonObject() && json.getAsJsonObject().keySet().isEmpty() ? EMPTY : new Page(json);
}

Page(JsonElement json) {
this(json.getAsJsonObject());
}

public Page(JsonObject json) {
Page(JsonObject json) {
this(
Text.Serializer.fromJson(json.get("title")),
readText(json.get("title")),
JsonHelper.getInt(json, "level", 0),
new ArrayList<>()
);
Expand All @@ -148,10 +162,6 @@ public static void write(PacketByteBuf buffer, Page page) {
}
}

public enum Flow {
NONE, LEFT, RIGHT
}

private interface Element {
void toBuffer(PacketByteBuf buffer);

Expand Down Expand Up @@ -213,7 +223,7 @@ static Element loadIngredient(JsonObject json) {
return new Multi(count, new Id((byte)4, Identifier.tryParse(json.get("spell").getAsString())));
}

return new Multi(count, new TextBlock(Text.Serializer.fromJson(json.get("text"))));
return new Multi(count, new TextBlock(readText(json.get("text"))));
}

@Override
Expand All @@ -229,7 +239,6 @@ static void write(PacketByteBuf buffer, Element element) {

static Element read(JsonElement json) {
if (!json.isJsonPrimitive()) {

JsonObject el = JsonHelper.asObject(json, "element");
if (el.has("texture")) {
return new Image(
Expand All @@ -256,7 +265,7 @@ static Element read(JsonElement json) {
}
}

return new TextBlock(Text.Serializer.fromJson(json));
return new TextBlock(readText(json));
}

private static Bounds boundsFromJson(JsonObject el) {
Expand Down
353 changes: 352 additions & 1 deletion src/main/resources/assets/unicopia/lang/en_us.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
#moj_import <matrix.glsl>

uniform sampler2D Sampler0;
uniform sampler2D Sampler1;

uniform vec4 ColorModulator;
uniform float GameTime;
uniform int EndPortalLayers;

in vec4 texProj0;
in vec4 vertexColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
"fragment": "unicopia:rendertype_portal_surface",
"attributes": [],
"samplers": [
{ "name": "Sampler0" },
{ "name": "Sampler1" }
{ "name": "Sampler0" }
],
"uniforms": [
{ "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] },
{ "name": "EndPortalLayers", "type": "int", "count": 1, "values": [ 15 ] }
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }
]
}
147 changes: 63 additions & 84 deletions src/main/resources/data/unicopia/spellbook/chapters/air_magic.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,46 @@
"content": {
"pages": [
{
"title": "Ch.4 Air Magic",
"title": "gui.unicopia.spellbook.chapter.air.p1.title",
"level": 1,
"elements": [
{ "x": 15, "y": 0, "width": 128, "height": 128, "texture": "unicopia:textures/gui/container/pages/air_magic.png" }
]
},
{
"title": "1st Hoof '12",
"title": "gui.unicopia.spellbook.chapter.air.p2.title",
"level": 1,
"elements": [
"A new month, a new chapter. Little Luna was getting bored of sitting in the tower all day (and who's to blame her? We've been on this assignment for over two months at this point).",
"So as a little treat, we've decided to go on a little trip to the Grand Marepid Falls to visit my friend, Commander Hurricane."
"gui.unicopia.spellbook.chapter.air.p1.1.body",
"gui.unicopia.spellbook.chapter.air.p1.2.body"
]
},
{
"title": "",
"level": 1,
"elements": [
"The Commander has also very graciously allowed me access to her library to continue my studies. I'm excited to see what combining unicorn and pegasus magics might bring.",
"At the princess' behest",
"- Starswirl the Bearded"
"gui.unicopia.spellbook.chapter.air.p1.3.body",
"gui.unicopia.spellbook.author1.sign_off",
"gui.unicopia.spellbook.author1.name"
]
},

{
"title": "2nd Hoof '12",
"title": "gui.unicopia.spellbook.chapter.air.p3.title",
"level": 0,
"elements": [
"Apologies for the, um, unusual entry in the appendices for today. It appears some little gremlin managed to obscond with my journal.",
"At the princess' behest, so dreadfully sorry",
"- Starswirl the Bearded"
"gui.unicopia.spellbook.chapter.air.p3.1.body",
"gui.unicopia.spellbook.author1.sign_off.b",
"gui.unicopia.spellbook.author1.name"
]
},
{
"title": "Air Magic I",
"title": "gui.unicopia.spellbook.chapter.air.p4.title",
"level": 3,
"elements": [
"Pegasus Magic",
"Air magic is to pegasi like fire is to unicorns. They're both equally hard to control but where fire is primarily focused around force, destruction, or protection, air is all about flexibility and free motion.",
"Command Hurricane has very kindly given me some tips on how to identify this trait in everyday objects.",
"gui.unicopia.spellbook.chapter.air.p4.1.body",
"gui.unicopia.spellbook.chapter.air.p4.2.body",
"gui.unicopia.spellbook.chapter.air.p4.3.body",
{ "x": 125, "y": -20, "width": 32, "height": 32, "texture": "unicopia:textures/gui/trait/air.png" },
{ "x": 125, "y": -20, "width": 16, "height": 16, "texture": "unicopia:textures/gui/trait/chaos.png" }
]
Expand All @@ -53,18 +53,18 @@
"title": "",
"level": 3,
"elements": [
"Anything relating to flight, or that originated from creatures that fly, or that comes from up above can be considered a source of the air trait.",
"Eg. Feathers.",
"At the princess' behest",
"- Starswirl the Bearded"
"gui.unicopia.spellbook.chapter.air.p4.4.body",
"gui.unicopia.spellbook.chapter.air.p4.5.body",
"gui.unicopia.spellbook.author1.sign_off",
"gui.unicopia.spellbook.author1.name"
]
},
{
"title": "Catapult",
"title": "spell.unicopia.catapult",
"level": 4,
"elements": [
"This is a straightforward application of a unicorn's telekineses. The catapult gem allows a caster to grab any block or creature and fling them into the air.",
"Use it again on something already thrown to push it away from you.",
"gui.unicopia.spellbook.chapter.air.catapult.1.body",
"gui.unicopia.spellbook.chapter.air.catapult.2.body",
{ "x": 125, "y": -20, "width": 32, "height": 32, "texture": "unicopia:textures/gui/trait/air.png" },
{ "x": 125, "y": -20, "width": 16, "height": 16, "texture": "unicopia:textures/gui/trait/chaos.png" }
]
Expand All @@ -74,23 +74,23 @@
"level": 4,
"elements": [
{ "recipe": "unicopia:spells/catapult" },
"Requires:",
"gui.unicopia.spellbook.recipe.requires",
{
"ingredients": [
{ "count": 1, "spell": "unicopia:flame" },
{ "count": 9, "trait": "unicopia:focus" },
{ "count": 9, "trait": "unicopia:air" }
]
},
"* One can add apply more force by adding the strength trait"
"gui.unicopia.spellbook.chapter.air.catapult.modifier.1"
]
},
{
"title": "Bubble",
"title": "spell.unicopia.bubble",
"level": 2,
"elements": [
"A defensive and utility spell. Bubble will trap the target in a giant soap bubble, rendering them defensless.",
"Use it again will pop the bubble.",
"gui.unicopia.spellbook.chapter.air.bubble.1.body",
"gui.unicopia.spellbook.chapter.air.bubble.2.body",
{ "x": 125, "y": -20, "width": 32, "height": 32, "texture": "unicopia:textures/gui/trait/air.png" },
{ "x": 125, "y": -20, "width": 16, "height": 16, "texture": "unicopia:textures/gui/trait/water.png" }
]
Expand All @@ -100,7 +100,7 @@
"level": 2,
"elements": [
{ "recipe": "unicopia:spells/bubble" },
"Requires:",
"gui.unicopia.spellbook.recipe.requires",
{
"ingredients": [
{ "count": 1, "spell": "unicopia:catapult" },
Expand All @@ -111,44 +111,44 @@
]
},
{
"title": "8th Hoof '12",
"title": "gui.unicopia.spellbook.chapter.air.p7.title",
"level": 4,
"elements": [
"I thought I would take a short moment to write down an entry to record my findings whilst Luna and The Commander are out.",
"Pegasi magic really is a fascinating beast. It's not like our magic, which is more of a study, with rigid rules and practices."
"gui.unicopia.spellbook.chapter.air.p7.1.body",
"gui.unicopia.spellbook.chapter.air.p7.2.body"
]
},
{
"title": "Pegasi",
"title": "gui.unicopia.spellbook.chapter.air.p8.title",
"level": 5,
"elements": [
"Pegasus magic is more about feeling. It's an art form. They don't think about what they want to do, it just happens, but it all still follows the same principle."
"gui.unicopia.spellbook.chapter.air.p8.1.body"
]
},
{
"title": "Pegasi II",
"title": "gui.unicopia.spellbook.chapter.air.p9.title",
"level": 6,
"elements": [
"Take for example their cloud homes. There are no spells I can read that would let me do this, but if you feel, not with your hooves or your horn, but properly, with your mind, your heart, you will find magic buzzing all throughout.",
"Clouds are teeming with the air and water trait, but also others, like power, strength, life, earth. All traits of the material the clouds are mimicking."
"gui.unicopia.spellbook.chapter.air.p9.1.body",
"gui.unicopia.spellbook.chapter.air.p9.2.body"
]
},
{
"title": "Pegasi III",
"title": "gui.unicopia.spellbook.chapter.air.p10.title",
"level": 7,
"elements": [
"I wish I could study this further, but I'm afraid to interfere in this magic I don't yet fully understand.",
"Commander Hurricane may never forgive me if I destroy her home the first time I'm here.",
"At the princess' behest",
"- Starswirl the Bearded"
"gui.unicopia.spellbook.chapter.air.p10.1.body",
"gui.unicopia.spellbook.chapter.air.p10.2.body",
"gui.unicopia.spellbook.author1.sign_off",
"gui.unicopia.spellbook.author1.name"
]
},
{
"title": "Feather Falling",
"title": "spell.unicopia.feather_fall",
"level": 5,
"elements": [
"Expanding on the defensive capabilities of the protection gem, I've attempted to extend its advantages to party members.",
"This one is unusual because of its complexity, but in theory it should allow one to slow their own and friends' descent.",
"gui.unicopia.spellbook.chapter.air.feather_fall.1.body",
"gui.unicopia.spellbook.chapter.air.feather_fall.2.body",
{ "x": 125, "y": -20, "width": 32, "height": 32, "texture": "unicopia:textures/gui/trait/air.png" },
{ "x": 125, "y": -20, "width": 16, "height": 16, "texture": "unicopia:textures/gui/trait/chaos.png" }
]
Expand All @@ -158,7 +158,7 @@
"level": 5,
"elements": [
{ "recipe": "unicopia:spells/feather_fall" },
"Requires:",
"gui.unicopia.spellbook.recipe.requires",
{
"ingredients": [
{ "count": 1, "spell": "unicopia:shield" },
Expand All @@ -171,68 +171,47 @@
]
},
{
"title": "10th Hoof '12",
"title": "gui.unicopia.spellbook.chapter.air.p12.title",
"level": 6,
"elements": [
"Went to dinner with Commander Huricane and Luna. We got to talking about architecture and Hurricane mentioned the Taz Marehall.",
"Luna thought it was a rather funny name of a castle. I had to remind her that not all cultures are the same.",
"At the princess' behest",
"- Starswirl the Bearded"
"gui.unicopia.spellbook.chapter.air.p12.1.body",
"gui.unicopia.spellbook.chapter.air.p12.2.body",
"gui.unicopia.spellbook.author1.sign_off",
"gui.unicopia.spellbook.author1.name"
]
},
{ },
{
"title": "",
"level": 0,
"elements": []
},
{
"title": "21st Hoof '12",
"title": "gui.unicopia.spellbook.chapter.air.p13.title",
"level": 7,
"elements": [
{
"text": "I'm writing this on the eve of my return to",
"extra": [
{ "text": "Trotholm.", "obfuscated": true },
"Though my time in Cloudopolis has been elightening, I look forward to a return to the familiar surroundings and a proper rest in my own solid bed."
]
},
"I cannot say the same for Luna, though. She is currently sitting on my bed beside me pouting over every little thing she sees me put into my saddlebag."
"gui.unicopia.spellbook.chapter.air.p13.1.body",
"gui.unicopia.spellbook.chapter.air.p13.2.body"
]
},
{
"title": "Returning Home",
"title": "gui.unicopia.spellbook.chapter.air.p14.title",
"level": 7,
"elements": [
{
"text": "She keeps insisting that we stay a little longer",
"extra": [
{ "text": "to hang out with that pegasus colt I saw her with the other day, no doubt", "strikethrough": true}
]
},
"At the princess' behest",
"- Starswirl the Bearded"
"gui.unicopia.spellbook.chapter.air.p14.1.body",
"gui.unicopia.spellbook.author1.sign_off",
"gui.unicopia.spellbook.author1.name"
]
},
{
"title": "22nd Hoof '12",
"title": "gui.unicopia.spellbook.chapter.air.p15.title",
"level": 8,
"elements": [
{
"text": "As we're flying above the mountain tops, I can't help but feel in awe the beauty that",
"extra": [
{ "text": "Mother Faust", "obfuscated": true},
"has given us."
]
},
"I had to spend the whole time keeping Luna from falling out, and of course answering questions about all the different kinds of clouds. Thankfully, the balloon operator was there to help with the subtleties."
"gui.unicopia.spellbook.chapter.air.p15.1.body",
"gui.unicopia.spellbook.chapter.air.p15.2.body"
]
},
{
"title": "",
"level": 8,
"elements": [
"Being out here, above all of our troubles, really makes me forget the rest of the world for a moment. It takes me back to a simpler time, before the--",
"Of course the flashes of explosions to the west has to ruin it all. There appears to be a storm on the horizon. I certainly hope it not to be a bad omen..."
"gui.unicopia.spellbook.chapter.air.p15.3.body",
"gui.unicopia.spellbook.chapter.air.p15.4.body"
]
}
]
Expand Down
Loading

0 comments on commit d08de6f

Please sign in to comment.