diff --git a/assets/bundles/bundle.properties b/assets/bundles/bundle.properties index f0e853b..5ca9374 100644 --- a/assets/bundles/bundle.properties +++ b/assets/bundles/bundle.properties @@ -1369,7 +1369,7 @@ setting.meld-unit-light-scale = Unit light radius multiplier setting.meld-highvis-overlay = High-vis block overlay\n(Turret ranges and etc... over Fow/Lighting) setting.meld-bulbhead-omnimove = Bulbhead Omnimovement\n(Move like a non-naval) setting.meld-port-saves = Port Saves\n[red]HIGHLY EXPERIMENTAL\nallows you to load a meld hjson map in meld java[] - +setting.meld-shitpost-bundles = Shitpost Bundles unit.ticks = ticks diff --git a/src/meld/SettingKeys.java b/src/meld/SettingKeys.java index 69eff57..5465a5e 100644 --- a/src/meld/SettingKeys.java +++ b/src/meld/SettingKeys.java @@ -10,6 +10,7 @@ public static String pref(String in){ connectedSonar = pref("connected-sonar"), unitLightScale = pref("unit-light-scale"), overlayOverFog = pref("highvis-overlay"), + shitpostBundles = pref("shitpost-bundles"), //Expirimental- doesn't sync in multiplayer and off by default bulbheadOmnimove = pref("bulbhead-omnimove"), diff --git a/src/meld/core/Bundles.java b/src/meld/core/Bundles.java index 9f11fbb..821712f 100644 --- a/src/meld/core/Bundles.java +++ b/src/meld/core/Bundles.java @@ -2,43 +2,82 @@ import java.util.*; import arc.*; +import arc.files.*; import arc.struct.*; import arc.util.*; import arc.util.io.*; import meld.*; import mindustry.*; -import mindustry.ui.dialogs.*; +import mindustry.ctype.*; +import mindustry.mod.*; -import static arc.Core.*; - -// very hacky dont do this +// still very hacky, dont do this public final class Bundles{ - private static final Locale locale = new Locale("shitpost"); + private static final Locale shitpostLocale = new Locale("shitpost"); private Bundles(){} public static void load(){ - setupLocale(); - loadBundle(); + var enabled = Core.settings.getBool(SettingKeys.shitpostBundles, false); + shitpost(enabled); } - private static void setupLocale(){ - Vars.locales = new Seq<>(Vars.locales).add(locale).toArray(); - LanguageDialog.displayNames.put(locale.toString(), "Meld Shitpost"); + public static void shitpost(boolean enable){ + // since when is this valid syntax???? + if(enable) enable(); else disable(); + + reloadModBundles(); + reloadContentFields(); } - private static void loadBundle(){ - if(!settings.getString("locale").equals(locale.toString())) return; - Log.info("loading meld shitpost bundle"); + private static void enable(){ + if(isShitpost()) return; - var modRoot = Vars.mods.getMod(Meld.name).root; - var bundleFile = modRoot.child("bundles").child("bundle_" + locale + ".properties"); - if(!bundleFile.exists()){ - Log.warn("couldn't find shitpost bundle"); - return; - } + var bundle = I18NBundle.createEmptyBundle(); + Reflect.set(bundle, "locale", shitpostLocale); + Reflect.set(bundle, "parent", Core.bundle); + Reflect.set(bundle, "formatter", new TextFormatter(shitpostLocale, !I18NBundle.getSimpleFormatter())); + Core.bundle = bundle; + } + + private static void disable(){ + if(!isShitpost()) return; - Reflect.set(bundle, "locale", locale); - PropertiesUtils.load(bundle.getProperties(), bundleFile.reader()); + Core.bundle = Reflect.get(Core.bundle, "parent"); + } + + private static void reloadModBundles(){ + var bundles = Reflect.>>get(Vars.mods, "bundles"); + + /// 1:1 copied from {@link Mods#buildFiles()} + I18NBundle bundle = Core.bundle; + while(bundle != null){ + String str = bundle.getLocale().toString(); + String locale = "bundle" + (str.isEmpty() ? "" : "_" + str); + for(Fi file : bundles.get(locale, Seq::new)){ + try{ + PropertiesUtils.load(bundle.getProperties(), file.reader()); + }catch(Throwable e){ + Log.err("Error loading bundle: " + file + "/" + locale, e); + } + } + bundle = bundle.getParent(); + } + } + + /// 1:1 copied from {@link UnlockableContent#UnlockableContent(String)} + private static void reloadContentFields(){ + Vars.content.each(it -> { + if(it instanceof UnlockableContent uc){ + uc.localizedName = Core.bundle.get(uc.getContentType() + "." + uc.name + ".name", uc.name); + uc.description = Core.bundle.getOrNull(uc.getContentType() + "." + uc.name + ".description"); + uc.details = Core.bundle.getOrNull(uc.getContentType() + "." + uc.name + ".details"); + uc.credit = Core.bundle.getOrNull(uc.getContentType() + "." + uc.name + ".credit"); + } + }); + } + + private static boolean isShitpost(){ + return Core.bundle.getLocale() == shitpostLocale; } } diff --git a/src/meld/ui/MeldSettings.java b/src/meld/ui/MeldSettings.java index 9ecccb0..e1abc49 100644 --- a/src/meld/ui/MeldSettings.java +++ b/src/meld/ui/MeldSettings.java @@ -7,6 +7,7 @@ import meld.Meld; import meld.SettingKeys; import meld.content.MeldUnits; +import meld.core.*; import mindustry.Vars; import mindustry.content.Blocks; import mindustry.ctype.UnlockableContent; @@ -14,7 +15,7 @@ import mindustry.ui.dialogs.SettingsMenuDialog; public class MeldSettings { - public static boolean replaceLighting, invertAmbient, connectedSonar, overlayOverFog, + public static boolean replaceLighting, invertAmbient, connectedSonar, overlayOverFog, shitpostBundles, //The expirimental settings bulbheadOmnimove, portSaves; @@ -33,6 +34,7 @@ public static void loadSettings(){ invertAmbient = Core.settings.getBool(SettingKeys.invertAmbient, false); connectedSonar = Core.settings.getBool(SettingKeys.connectedSonar, true); overlayOverFog = Core.settings.getBool(SettingKeys.overlayOverFog, true); + shitpostBundles = Core.settings.getBool(SettingKeys.shitpostBundles, false); float newLightScale = Core.settings.getInt(SettingKeys.unitLightScale, 100); MeldUnits.lightRadiusMultiplier(newLightScale); @@ -62,6 +64,11 @@ public static void loadSettings(){ check(t, SettingKeys.invertAmbient, false, b -> invertAmbient = b); check(t, SettingKeys.connectedSonar, true, b -> connectedSonar = b); check(t, SettingKeys.overlayOverFog, true, b -> overlayOverFog = b); + check(t, SettingKeys.shitpostBundles, false, b -> { + Vars.ui.loadAnd(() -> { + Bundles.shitpost(shitpostBundles = b); + }); + }); t.sliderPref(Core.bundle.get(SettingKeys.unitLightScale), 100, 1, 200, f -> { MeldUnits.lightRadiusMultiplier(f);