diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f42acd..372764b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +### [1.16.5-forge-1.1.0](https://github.com/KatatsumuriPan/BetterLineBreak/releases/tag/1.16.5-forge-1.1.0) - 2024-02-16 + +- Fix not break with PHRASE mode. +- Cache budouX model. + ### [1.16.5-forge-1.0.2](https://github.com/KatatsumuriPan/BetterLineBreak/releases/tag/1.16.5-forge-1.0.2) - 2024-02-07 - Fix crashing bug. diff --git a/gradle.properties b/gradle.properties index 3c67490..ce23f50 100644 --- a/gradle.properties +++ b/gradle.properties @@ -48,7 +48,7 @@ mod_name=Better Line Break # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=LGPL-2.1 # The mod version. See https://semver.org/ -mod_version=1.0.2 +mod_version=1.1.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/kpan/b_line_break/LineBreakingUtil.java b/src/main/java/kpan/b_line_break/LineBreakingUtil.java index a6d9679..7835c29 100644 --- a/src/main/java/kpan/b_line_break/LineBreakingUtil.java +++ b/src/main/java/kpan/b_line_break/LineBreakingUtil.java @@ -106,13 +106,13 @@ public static void splitLines(CharacterManager textHandler, ITextProperties stri Language language = Minecraft.getInstance().getLanguageManager().getSelected(); switch (language.getCode()) { case "ja_jp": - return Parser.loadByFileName("/models/ja_tuned.json"); + return Parser.Cache.getOrLoad("/models/ja_tuned.json"); case "zh_cn": - return Parser.loadDefaultSimplifiedChineseParser(); + return Parser.Cache.getOrLoad("/models/zh-hans.json"); case "zh_tw": - return Parser.loadDefaultTraditionalChineseParser(); + return Parser.Cache.getOrLoad("/models/zh-hant.json"); case "th_th": - return Parser.loadDefaultThaiParser(); + return Parser.Cache.getOrLoad("/models/th.json"); default: return null; } @@ -172,6 +172,8 @@ public static boolean canBreak(char prevChar, char c, int index, IntSet breakInd return false; if (isStartBracket(prevChar)) return false; + if (breakIndices.contains(index)) + return true; if (!isNormalAsciiLetter(prevChar) && isNormalAsciiLetter(c)) return true; return false; diff --git a/src/main/java/kpan/b_line_break/ModMain.java b/src/main/java/kpan/b_line_break/ModMain.java index f2d63f4..cda60a7 100644 --- a/src/main/java/kpan/b_line_break/ModMain.java +++ b/src/main/java/kpan/b_line_break/ModMain.java @@ -11,10 +11,10 @@ import org.apache.logging.log4j.Logger; // The value here should match an entry in the META-INF/mods.toml file -@Mod(ModReference.MOD_ID) +@Mod(ModReference.MODID) public class ModMain { // Directly reference a log4j logger. - public static final Logger LOGGER = LogManager.getLogger(); + public static final Logger LOGGER = LogManager.getLogger(ModReference.MODNAME); public ModMain() { diff --git a/src/main/java/kpan/b_line_break/ModReference.java b/src/main/java/kpan/b_line_break/ModReference.java index 05a4c78..d084217 100644 --- a/src/main/java/kpan/b_line_break/ModReference.java +++ b/src/main/java/kpan/b_line_break/ModReference.java @@ -1,5 +1,6 @@ package kpan.b_line_break; public class ModReference { - public static final String MOD_ID = "better_line_break"; + public static final String MODID = "better_line_break"; + public static final String MODNAME = "better_line_break"; } diff --git a/src/main/java/kpan/b_line_break/budoux/Parser.java b/src/main/java/kpan/b_line_break/budoux/Parser.java index ab39369..594725f 100644 --- a/src/main/java/kpan/b_line_break/budoux/Parser.java +++ b/src/main/java/kpan/b_line_break/budoux/Parser.java @@ -20,8 +20,8 @@ import com.google.gson.JsonIOException; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; -import kpan.b_line_break.util.ListUtil; +import javax.annotation.Nullable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -34,8 +34,9 @@ import java.util.Optional; /* -・HTMLは使用しないので、translateHTMLStringを削除しています。 -・totalScoreをキャッシュしています。 + * HTMLは使用しないので、translateHTMLStringを削除しています。 + * totalScoreをキャッシュしています。 + * シンプルなCacheクラスを作成しています。 */ public class Parser { private final Map> model; @@ -172,9 +173,25 @@ public List parse(String sentence) { if (score > 0) { result.add(""); } - ListUtil.setLast(result, ListUtil.getLast(result) + sentence.charAt(i)); + result.set(result.size() - 1, result.get(result.size() - 1) + sentence.charAt(i)); } return result; } + /* + 流石に毎回ファイルIOが走るのは良くないのでキャッシュ + */ + public static class Cache { + + private static @Nullable String modelFileName = null; + private static Parser parser; + + public static Parser getOrLoad(String modelFileName) { + if (modelFileName.equals(Cache.modelFileName)) + return parser; + Cache.modelFileName = modelFileName; + parser = Parser.loadByFileName(modelFileName); + return parser; + } + } } diff --git a/src/main/java/kpan/b_line_break/config/ConfigEntries.java b/src/main/java/kpan/b_line_break/config/ConfigEntries.java index e122dca..b127dfc 100644 --- a/src/main/java/kpan/b_line_break/config/ConfigEntries.java +++ b/src/main/java/kpan/b_line_break/config/ConfigEntries.java @@ -494,7 +494,7 @@ public PropertyEntry(ConfigScreen configScreen, ConfigEntries owningEntryList, C comment = ConfigUtil.getComment(configScreen.forgeConfigSpec, configValue); toolTip.add(name.copy().withStyle(TextFormatting.GREEN)); - String tooltip = I18n.get("config." + ModReference.MOD_ID + "." + StringUtils.join(configValue.getPath(), '.') + ".tooltip").replace("\\n", "\n"); + String tooltip = I18n.get("config." + ModReference.MODID + "." + StringUtils.join(configValue.getPath(), '.') + ".tooltip").replace("\\n", "\n"); if (I18n.exists(tooltip)) toolTip.addAll(TextComponentUtil.splitLines(new StringTextComponent(tooltip).withStyle(TextFormatting.YELLOW))); else if (comment != null) @@ -555,7 +555,7 @@ public CategoryEntry(ConfigScreen owningScreen, ConfigEntries owningEntryList, F drawLabel = false; toolTip.add(name.copy().withStyle(TextFormatting.GREEN)); - String tooltip = I18n.get("config." + ModReference.MOD_ID + "." + StringUtils.join(categoryPath, '.') + ".tooltip").replace("\\n", "\n"); + String tooltip = I18n.get("config." + ModReference.MODID + "." + StringUtils.join(categoryPath, '.') + ".tooltip").replace("\\n", "\n"); if (I18n.exists(tooltip)) toolTip.add(new StringTextComponent(tooltip).withStyle(TextFormatting.YELLOW)); else if (comment != null)