From 978ea090db38000de0ac5f07148f70f646fd6ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=82=A6=E8=A7=A3=E8=AF=B4?= Date: Sun, 28 Jan 2024 19:15:11 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=94=20Weblate!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 18 +++ .../src/main/java/ziyue/tjmetro/Config.java | 7 +- .../java/ziyue/tjmetro/IDrawingExtends.java | 22 ++-- .../main/java/ziyue/tjmetro/Reference.java | 1 + .../resources/assets/tjmetro/lang/en_us.json | 1 + .../resources/assets/tjmetro/lang/zh_cn.json | 104 ------------------ 6 files changed, 36 insertions(+), 117 deletions(-) delete mode 100644 common/src/main/resources/assets/tjmetro/lang/zh_cn.json diff --git a/build.gradle b/build.gradle index 0684cc0..f3395ee 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,24 @@ task setupFiles() { System.out.println("Mod Menu: " + rootProject.mod_menu_version) System.out.println("Architectury: " + rootProject.architectury_version) + download { + src "https://weblate.ziyuesinicization.site/api/components/tianjin-metro/en-us-json/file/" + dest "lang.zip" + overwrite true + retries -1 + } + copy { + outputs.upToDateWhen { false } + from(zipTree("lang.zip")) + into "temp_lang" + } + copy { + outputs.upToDateWhen { false } + from "temp_lang/tianjin-metro/en-us-json/" + into "/" + } + delete("lang.zip", "temp_lang") + copy { outputs.upToDateWhen { false } from "checkouts/mtr-fabric.jar" diff --git a/common/src/main/java/ziyue/tjmetro/Config.java b/common/src/main/java/ziyue/tjmetro/Config.java index e9b0b5b..e5bcc2f 100644 --- a/common/src/main/java/ziyue/tjmetro/Config.java +++ b/common/src/main/java/ziyue/tjmetro/Config.java @@ -48,9 +48,10 @@ public void set(Boolean value) { protected static final Path CONFIG_FILE_PATH = Minecraft.getInstance().gameDirectory.toPath().resolve("config").resolve("tjmetro.json"); public static final List> FOOTERS = Arrays.asList( - () -> IDrawingExtends.format(Text.translatable("footer.tjmetro.sources"), style -> IDrawingExtends.LINK_STYLE.apply(Reference.GITHUB_REPO).applyTo(style)), - () -> IDrawingExtends.format(Text.translatable("footer.tjmetro.contributors"), style -> IDrawingExtends.LINK_STYLE.apply(Reference.CONTRIBUTORS).applyTo(style)), - () -> IDrawingExtends.format(Text.translatable("footer.tjmetro.forum"), style -> IDrawingExtends.LINK_STYLE.apply(Reference.FORUM).applyTo(style).withColor(TextColor.fromRgb(15946322))) + () -> IDrawingExtends.format(Text.translatable("footer.tjmetro.sources"), IDrawingExtends.LINK_STYLE.apply(Reference.GITHUB_REPO)), + () -> IDrawingExtends.format(Text.translatable("footer.tjmetro.contributors"), IDrawingExtends.LINK_STYLE.apply(Reference.CONTRIBUTORS)), + () -> IDrawingExtends.format(Text.translatable("footer.tjmetro.forum"), IDrawingExtends.LINK_STYLE.apply(Reference.FORUM).withColor(TextColor.fromRgb(15946322))), + () -> IDrawingExtends.format(Text.translatable("footer.tjmetro.weblate"), IDrawingExtends.LINK_STYLE.apply(Reference.WEBLATE)) ); public static Screen getConfigScreen() { diff --git a/common/src/main/java/ziyue/tjmetro/IDrawingExtends.java b/common/src/main/java/ziyue/tjmetro/IDrawingExtends.java index 0ac1835..91e5332 100644 --- a/common/src/main/java/ziyue/tjmetro/IDrawingExtends.java +++ b/common/src/main/java/ziyue/tjmetro/IDrawingExtends.java @@ -230,8 +230,8 @@ static List addHoldShiftTooltip(List list, MutableComponen } /** - * Formatting the component with specific styles. - * A valid format-able string should like this: {@code Hello! <1>This is an example!} + * A simple formatter for formatting the component with specific styles. Not compatible with tag-nesting. + * A valid format-able string should be like this: {@code Hello! <1>This is an example!} * * @author ZiYueCommentary * @since beta-1 @@ -239,23 +239,23 @@ static List addHoldShiftTooltip(List list, MutableComponen static MutableComponent format(Component component, Style... styles) { Style componentStyle = component.getStyle(); MutableComponent result = new TextComponent(""); - String contents = component.getString(); - int firstTagBegin = contents.indexOf('<'); + StringBuilder contents = new StringBuilder(component.getString()); + int firstTagBegin = contents.indexOf("<"); while (firstTagBegin != -1) { if (firstTagBegin != 0) { result.append(Text.literal(contents.substring(0, firstTagBegin)).withStyle(componentStyle)); - contents = contents.substring(firstTagBegin); + contents.delete(0, firstTagBegin); } else { - int firstTagEnd = contents.indexOf('>'); + int firstTagEnd = contents.indexOf(">"); int tagId = Integer.parseInt(contents.substring(firstTagBegin + 1, firstTagEnd)); - contents = contents.substring(firstTagEnd + 1); + contents.delete(0, firstTagEnd + 1); int lastTagBegin = contents.indexOf(""); result.append(Text.literal(contents.substring(0, lastTagBegin)).withStyle(styles[tagId - 1])); - contents = contents.substring(lastTagBegin + 3); + contents.delete(0, lastTagBegin + 3); } - firstTagBegin = contents.indexOf('<'); + firstTagBegin = contents.indexOf("<"); } - result.append(Text.literal(contents).withStyle(componentStyle)); + result.append(Text.literal(contents.toString()).withStyle(componentStyle)); return result; } @@ -263,7 +263,9 @@ static MutableComponent format(Component component, Style... styles) { * @author ZiYueCommentary * @see #format(Component, Style...) * @since beta-1 + * @deprecated */ + @Deprecated @SafeVarargs static MutableComponent format(Component component, UnaryOperator