chore: split visualization mode config entry into separate

This commit is contained in:
Johannes Frohnmeyer 2024-05-10 14:26:32 +02:00
parent c93a60965f
commit 6a0cfdb26a
Signed by: Johannes
GPG Key ID: E76429612C2929F4
6 changed files with 46 additions and 17 deletions

View File

@ -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.Entry;
import io.gitlab.jfronny.libjf.config.api.v2.JfConfig; 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 { public class Cfg {
@Entry public static int rounds = 5; @Entry public static int rounds = 5;
@Entry public static boolean breakFully = false; @Entry public static boolean breakFully = false;
@Entry public static String targetLanguage = "en"; @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 forceRegenerate = false;
@Entry public static boolean useDefaultCache = true; @Entry public static boolean useDefaultCache = true;

View File

@ -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;
}
}));
}
}

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.translater.mixin; package io.gitlab.jfronny.translater.mixin;
import io.gitlab.jfronny.libjf.LibJf; 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.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
@ -28,9 +28,9 @@ public class Plugin implements IMixinConfigPlugin {
|| Objects.equals(mixinClassName, TranslationStorageAccessor.class.getName())) || Objects.equals(mixinClassName, TranslationStorageAccessor.class.getName()))
return true; return true;
else if (Objects.equals(mixinClassName, MinecraftClientAccessor.class.getName())) else if (Objects.equals(mixinClassName, MinecraftClientAccessor.class.getName()))
return Translater.progressUIEnabled(); return Cfg.progressGui;
else if (Objects.equals(mixinClassName, SplashScreenMixin.class.getName())) else if (Objects.equals(mixinClassName, SplashScreenMixin.class.getName()))
return Translater.progressUIEnabled(); return Cfg.progressGui;
else else
throw new IllegalStateException("Unrecognized mixin! This should never happen"); throw new IllegalStateException("Unrecognized mixin! This should never happen");
} }

View File

@ -37,8 +37,10 @@ public class TransformingMap implements Map<String, String> {
initProgress = new AtomicInteger(); initProgress = new AtomicInteger();
transformer.transformMultiple(strings.parallelStream(), (str, translation) -> { transformer.transformMultiple(strings.parallelStream(), (str, translation) -> {
int i = initProgress.incrementAndGet(); int i = initProgress.incrementAndGet();
if (Translater.progressLogsEnabled()) Translater.LOGGER.info(getInitProgress()); if (i % 10 == 0 || Cfg.detailedProgress) {
if (Translater.progressUIEnabled() && i % 10 == 0) renderScheduler.scheduleRender(); if (Cfg.progressConsole) Translater.LOGGER.info(getInitProgress());
if (Cfg.progressGui && i % 10 == 0) renderScheduler.scheduleRender();
}
}); });
renderScheduler.deschedule(); renderScheduler.deschedule();
initProgress = null; initProgress = null;
@ -46,7 +48,7 @@ public class TransformingMap implements Map<String, String> {
public String getInitProgress() { public String getInitProgress() {
if (initProgress == null || !initializing) throw new IllegalStateException("Tried to get init progress while not initializing"); 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 @Override

View File

@ -90,7 +90,7 @@ public class TranslatingTransformer<T extends Language> implements Transformer {
private String translateMultiple(String str) throws TranslateException { private String translateMultiple(String str) throws TranslateException {
Matcher m = SURROUNDING_SPACE_PATTERN.matcher(str); Matcher m = SURROUNDING_SPACE_PATTERN.matcher(str);
if (!m.find()) { if (!m.find()) {
Translater.LOGGER.info("Skipping translation of \"{}\"", str); if (Cfg.detailedProgress) Translater.LOGGER.info("Skipping translation of \"{}\"", str);
return str; return str;
} }
try { try {
@ -106,7 +106,7 @@ public class TranslatingTransformer<T extends Language> implements Transformer {
} }
currentState = ts.translate(currentState, currentLang, startLang == languageAuto ? languageEnglish : startLang); // Translate to starting language 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 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; return currentState;
} catch (Exception e) { } catch (Exception e) {
Translater.LOGGER.warn("Failed to break: \"{}\" ({} characters). Is your API key valid?", m.group(2), m.group(2).length()); Translater.LOGGER.warn("Failed to break: \"{}\" ({} characters). Is your API key valid?", m.group(2), m.group(2).length());

View File

@ -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.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": "Target Language",
"translater.jfconfig.targetLanguage.tooltip": "The language to translate to - Leave empty for auto-detection (might break text even more)", "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.progressGui": "Progress GUI",
"translater.jfconfig.renderProgress.tooltip": "Significantly slows down the loading time but gives a visual of the progress. Values: Full, Console, None", "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": "Force Regenerate",
"translater.jfconfig.forceRegenerate.tooltip": "Use this if something is broken. This initiates the regeneration of the cache", "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": "Use default Cache",
"translater.jfconfig.useDefaultCache.tooltip": "Use pre-generated translations shipped with the mod if the config permits to save time", "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"
} }