From 6a0cfdb26acd470ef0870e8549f0c5c56c341cf4 Mon Sep 17 00:00:00 2001 From: JFronny Date: Fri, 10 May 2024 14:26:32 +0200 Subject: [PATCH] chore: split visualization mode config entry into separate --- .../io/gitlab/jfronny/translater/Cfg.java | 6 +++-- .../jfronny/translater/CfgMigration.java | 25 +++++++++++++++++++ .../jfronny/translater/mixin/Plugin.java | 6 ++--- .../transformer/TransformingMap.java | 8 +++--- .../transformer/TranslatingTransformer.java | 4 +-- .../assets/translater/lang/en_us.json | 14 +++++------ 6 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 src/client/java/io/gitlab/jfronny/translater/CfgMigration.java diff --git a/src/client/java/io/gitlab/jfronny/translater/Cfg.java b/src/client/java/io/gitlab/jfronny/translater/Cfg.java index b4b29e4..df63a08 100644 --- a/src/client/java/io/gitlab/jfronny/translater/Cfg.java +++ b/src/client/java/io/gitlab/jfronny/translater/Cfg.java @@ -3,12 +3,14 @@ package io.gitlab.jfronny.translater; import io.gitlab.jfronny.libjf.config.api.v2.Entry; import io.gitlab.jfronny.libjf.config.api.v2.JfConfig; -@JfConfig(referencedConfigs = "libjf-translate-v1") +@JfConfig(referencedConfigs = "libjf-translate-v1", tweaker = CfgMigration.class) public class Cfg { @Entry public static int rounds = 5; @Entry public static boolean breakFully = false; @Entry public static String targetLanguage = "en"; - @Entry public static ProgressMode renderProgress = ProgressMode.None; + @Entry public static boolean progressGui = false; + @Entry public static boolean progressConsole = true; + @Entry public static boolean detailedProgress = false; @Entry public static boolean forceRegenerate = false; @Entry public static boolean useDefaultCache = true; diff --git a/src/client/java/io/gitlab/jfronny/translater/CfgMigration.java b/src/client/java/io/gitlab/jfronny/translater/CfgMigration.java new file mode 100644 index 0000000..e83dcbe --- /dev/null +++ b/src/client/java/io/gitlab/jfronny/translater/CfgMigration.java @@ -0,0 +1,25 @@ +package io.gitlab.jfronny.translater; + +import io.gitlab.jfronny.libjf.config.api.v2.dsl.ConfigBuilder; +import io.gitlab.jfronny.libjf.config.api.v2.dsl.Migration; + +public class CfgMigration { + public static ConfigBuilder tweak(ConfigBuilder cb) { + return cb.addMigration("renderProgress", Migration.of(reader -> { + String renderMode = reader.nextString(); + if (renderMode == null) return; + switch (renderMode.toLowerCase()) { + case "full" -> Cfg.progressGui = Cfg.progressConsole = Cfg.detailedProgress = true; + case "gui" -> { + Cfg.progressConsole = Cfg.detailedProgress = false; + Cfg.progressGui = true; + } + case "console" -> { + Cfg.progressGui = Cfg.detailedProgress = false; + Cfg.progressConsole = true; + } + case "none" -> Cfg.progressGui = Cfg.progressConsole = Cfg.detailedProgress = false; + } + })); + } +} diff --git a/src/client/java/io/gitlab/jfronny/translater/mixin/Plugin.java b/src/client/java/io/gitlab/jfronny/translater/mixin/Plugin.java index fdce4d9..0db7ab3 100644 --- a/src/client/java/io/gitlab/jfronny/translater/mixin/Plugin.java +++ b/src/client/java/io/gitlab/jfronny/translater/mixin/Plugin.java @@ -1,7 +1,7 @@ package io.gitlab.jfronny.translater.mixin; import io.gitlab.jfronny.libjf.LibJf; -import io.gitlab.jfronny.translater.Translater; +import io.gitlab.jfronny.translater.Cfg; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; @@ -28,9 +28,9 @@ public class Plugin implements IMixinConfigPlugin { || Objects.equals(mixinClassName, TranslationStorageAccessor.class.getName())) return true; else if (Objects.equals(mixinClassName, MinecraftClientAccessor.class.getName())) - return Translater.progressUIEnabled(); + return Cfg.progressGui; else if (Objects.equals(mixinClassName, SplashScreenMixin.class.getName())) - return Translater.progressUIEnabled(); + return Cfg.progressGui; else throw new IllegalStateException("Unrecognized mixin! This should never happen"); } diff --git a/src/client/java/io/gitlab/jfronny/translater/transformer/TransformingMap.java b/src/client/java/io/gitlab/jfronny/translater/transformer/TransformingMap.java index 4ad0c2f..c6de36d 100644 --- a/src/client/java/io/gitlab/jfronny/translater/transformer/TransformingMap.java +++ b/src/client/java/io/gitlab/jfronny/translater/transformer/TransformingMap.java @@ -37,8 +37,10 @@ public class TransformingMap implements Map { initProgress = new AtomicInteger(); transformer.transformMultiple(strings.parallelStream(), (str, translation) -> { int i = initProgress.incrementAndGet(); - if (Translater.progressLogsEnabled()) Translater.LOGGER.info(getInitProgress()); - if (Translater.progressUIEnabled() && i % 10 == 0) renderScheduler.scheduleRender(); + if (i % 10 == 0 || Cfg.detailedProgress) { + if (Cfg.progressConsole) Translater.LOGGER.info(getInitProgress()); + if (Cfg.progressGui && i % 10 == 0) renderScheduler.scheduleRender(); + } }); renderScheduler.deschedule(); initProgress = null; @@ -46,7 +48,7 @@ public class TransformingMap implements Map { public String getInitProgress() { if (initProgress == null || !initializing) throw new IllegalStateException("Tried to get init progress while not initializing"); - return "Transforming " + initProgress.get() + "/" + maxProgress; + return "Transforming %d/%d".formatted(initProgress.get(), maxProgress); } @Override diff --git a/src/client/java/io/gitlab/jfronny/translater/transformer/TranslatingTransformer.java b/src/client/java/io/gitlab/jfronny/translater/transformer/TranslatingTransformer.java index 69d84c9..b935373 100644 --- a/src/client/java/io/gitlab/jfronny/translater/transformer/TranslatingTransformer.java +++ b/src/client/java/io/gitlab/jfronny/translater/transformer/TranslatingTransformer.java @@ -90,7 +90,7 @@ public class TranslatingTransformer implements Transformer { private String translateMultiple(String str) throws TranslateException { Matcher m = SURROUNDING_SPACE_PATTERN.matcher(str); if (!m.find()) { - Translater.LOGGER.info("Skipping translation of \"{}\"", str); + if (Cfg.detailedProgress) Translater.LOGGER.info("Skipping translation of \"{}\"", str); return str; } try { @@ -106,7 +106,7 @@ public class TranslatingTransformer implements Transformer { } currentState = ts.translate(currentState, currentLang, startLang == languageAuto ? languageEnglish : startLang); // Translate to starting language currentState = m.group(1) + currentState + m.group(3); // Add back surrounding white space - Translater.LOGGER.info("Transformed: \"{}\" to: \"{}\"", str, currentState); + if (Cfg.detailedProgress) Translater.LOGGER.info("Transformed: \"{}\" to: \"{}\"", str, currentState); return currentState; } catch (Exception e) { Translater.LOGGER.warn("Failed to break: \"{}\" ({} characters). Is your API key valid?", m.group(2), m.group(2).length()); diff --git a/src/client/resources/assets/translater/lang/en_us.json b/src/client/resources/assets/translater/lang/en_us.json index 3e700a7..d59cb5c 100644 --- a/src/client/resources/assets/translater/lang/en_us.json +++ b/src/client/resources/assets/translater/lang/en_us.json @@ -6,14 +6,14 @@ "translater.jfconfig.breakFully.tooltip": "Whether to fully break the texts content by translating from the wrong language (enable for complete breaking)", "translater.jfconfig.targetLanguage": "Target Language", "translater.jfconfig.targetLanguage.tooltip": "The language to translate to - Leave empty for auto-detection (might break text even more)", - "translater.jfconfig.renderProgress": "Progress Renderer", - "translater.jfconfig.renderProgress.tooltip": "Significantly slows down the loading time but gives a visual of the progress. Values: Full, Console, None", + "translater.jfconfig.progressGui": "Progress GUI", + "translater.jfconfig.progressGui.tooltip": "Significantly slows down the loading time but gives an in-game visual of the progress", + "translater.jfconfig.progressConsole": "Progress Console", + "translater.jfconfig.progressConsole.tooltip": "Slightly slows down the loading time but logs the progress", + "translater.jfconfig.detailedProgress": "Detailed Progress", + "translater.jfconfig.renderProgress.tooltip": "Significantly slows down the loading time but provides information about individual translations", "translater.jfconfig.forceRegenerate": "Force Regenerate", "translater.jfconfig.forceRegenerate.tooltip": "Use this if something is broken. This initiates the regeneration of the cache", "translater.jfconfig.useDefaultCache": "Use default Cache", - "translater.jfconfig.useDefaultCache.tooltip": "Use pre-generated translations shipped with the mod if the config permits to save time", - "translater.jfconfig.enum.ProgressMode.Full": "Full", - "translater.jfconfig.enum.ProgressMode.Gui": "Gui", - "translater.jfconfig.enum.ProgressMode.Console": "Console", - "translater.jfconfig.enum.ProgressMode.None": "None" + "translater.jfconfig.useDefaultCache.tooltip": "Use pre-generated translations shipped with the mod if the config permits to save time" } \ No newline at end of file