Skip to content

Commit

Permalink
Merge pull request #23 from KatatsumuriPan/1.16.5/forge-dev
Browse files Browse the repository at this point in the history
Update to v1.1.0(1.16.5Forge)
  • Loading branch information
KatatsumuriPan authored Feb 16, 2024
2 parents 550e156 + bd2a901 commit d8bd146
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/kpan/b_line_break/LineBreakingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/kpan/b_line_break/ModMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/kpan/b_line_break/ModReference.java
Original file line number Diff line number Diff line change
@@ -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";
}
25 changes: 21 additions & 4 deletions src/main/java/kpan/b_line_break/budoux/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,8 +34,9 @@
import java.util.Optional;

/*
・HTMLは使用しないので、translateHTMLStringを削除しています。
・totalScoreをキャッシュしています。
* HTMLは使用しないので、translateHTMLStringを削除しています。
* totalScoreをキャッシュしています。
* シンプルなCacheクラスを作成しています。
*/
public class Parser {
private final Map<String, Map<String, Integer>> model;
Expand Down Expand Up @@ -172,9 +173,25 @@ public List<String> 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;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/kpan/b_line_break/config/ConfigEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d8bd146

Please sign in to comment.