Automatic external bundle loading

This commit is contained in:
Anuken
2018-07-09 11:24:24 -04:00
parent d6969d2c74
commit 3d9c9e639d
2 changed files with 15 additions and 14 deletions
+1 -1
View File
@@ -168,7 +168,7 @@ public class Vars{
for(EntityGroup<?> group : Entities.getAllGroups()){ for(EntityGroup<?> group : Entities.getAllGroups()){
group.setRemoveListener(entity -> { group.setRemoveListener(entity -> {
if(entity instanceof SyncTrait && Net.client()){ if(entity instanceof SyncTrait && Net.client()){
netClient.addRemovedEntity(((SyncTrait) entity).getID()); netClient.addRemovedEntity((entity).getID());
} }
}); });
} }
@@ -3,9 +3,10 @@ package io.anuke.mindustry.io;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.I18NBundle; import com.badlogic.gdx.utils.I18NBundle;
import io.anuke.mindustry.core.Platform; import io.anuke.mindustry.Vars;
import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Settings; import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Log; import io.anuke.ucore.util.Log;
import java.util.Locale; import java.util.Locale;
@@ -13,7 +14,6 @@ import java.util.Locale;
import static io.anuke.mindustry.Vars.headless; import static io.anuke.mindustry.Vars.headless;
public class BundleLoader { public class BundleLoader {
private static final boolean externalBundle = false;
public static void load(){ public static void load(){
Settings.defaults("locale", "default"); Settings.defaults("locale", "default");
@@ -40,20 +40,20 @@ public class BundleLoader {
private static void loadBundle(){ private static void loadBundle(){
I18NBundle.setExceptionOnMissingKey(false); I18NBundle.setExceptionOnMissingKey(false);
try {
//try loading external bundle
FileHandle handle = Gdx.files.local("bundle");
if(externalBundle){ Locale locale = Locale.ENGLISH;
try { Core.bundle = I18NBundle.createBundle(handle, locale);
FileHandle handle = Gdx.files.local("bundle");
Locale locale = Locale.ENGLISH; Log.info("NOTE: external translation bundle has been loaded.");
Core.bundle = I18NBundle.createBundle(handle, locale); if(!headless){
}catch (Exception e){ Timers.run(10f, () -> Vars.ui.showInfo("Note: You have successfully loaded an external translation bundle."));
Log.err(e);
Platform.instance.showError("Failed to find bundle!\nMake sure you have bundle.properties in the same directory\nas the jar file.\n\nIf the problem persists, try running it through the command prompt:\n" +
"Hold left-shift, then right click and select 'open command prompt here'.\nThen, type in 'java -jar mindustry.jar' without quotes.");
Gdx.app.exit();
} }
}else{ }catch (Throwable e){
//no external bundle found
FileHandle handle = Gdx.files.internal("bundles/bundle"); FileHandle handle = Gdx.files.internal("bundles/bundle");
Locale locale = getLocale(); Locale locale = getLocale();
@@ -61,5 +61,6 @@ public class BundleLoader {
if(!headless) Log.info("Got locale: {0}", locale); if(!headless) Log.info("Got locale: {0}", locale);
Core.bundle = I18NBundle.createBundle(handle, locale); Core.bundle = I18NBundle.createBundle(handle, locale);
} }
} }
} }