Skip to content

Commit

Permalink
Merge pull request #155 from rymiel/font-tag-args-fix
Browse files Browse the repository at this point in the history
Improve font transformation control flow
  • Loading branch information
zml2008 authored Sep 26, 2021
2 parents 2333c41 + bef5e8f commit 7194722
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,15 @@ public void load(final String name, final List<TagPart> args) {
super.load(name, args);

if (args.size() == 1) {
@Subst("minecraft:empty") final String fontKey = args.get(0).value();
@Subst("empty") final String fontKey = args.get(0).value();
this.font = Key.key(fontKey);
} else if (args.size() == 2) {
@Subst(Key.MINECRAFT_NAMESPACE) final String namespaceKey = args.get(0).value();
@Subst("empty") final String fontKey = args.get(1).value();
this.font = Key.key(namespaceKey, fontKey);
} else {
throw new ParsingException("Don't know how to turn " + args + " into a font", this.argTokenArray());
}

if (args.size() != 2) {
throw new ParsingException("Doesn't know how to turn " + args + " into a click event", this.argTokenArray());
}

@Subst(Key.MINECRAFT_NAMESPACE) final String namespaceKey = args.get(0).value();
@Subst("empty") final String fontKey = args.get(1).value();
this.font = Key.key(namespaceKey, fontKey);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,32 @@ void testFont() {
this.assertParsedEquals(expected, input);
}

@Test
void testCustomFont() {
final String input = "Default <font:myfont:best_font>Custom font <font:custom:worst_font>Another custom font </font>Back to previous font";
final Component expected = text("Default ")
.append(empty().style(s -> s.font(key("myfont", "best_font")))
.append(text("Custom font "))
.append(text("Another custom font ").style(s -> s.font(key("custom", "worst_font"))))
.append(text("Back to previous font"))
);

this.assertParsedEquals(expected, input);
}

@Test
void testFontNoNamespace() {
final String input = "Nothing <font:uniform>Uniform <font:alt>Alt </font> Uniform";
final Component expected = text("Nothing ")
.append(empty().style(s -> s.font(key("uniform")))
.append(text("Uniform "))
.append(text("Alt ").style(s -> s.font(key("alt"))))
.append(text(" Uniform"))
);

this.assertParsedEquals(expected, input);
}

// GH-37
@Test
void testPhil() {
Expand Down

0 comments on commit 7194722

Please sign in to comment.