diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 156ab3832c..9980c1a156 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -21,21 +21,24 @@ android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> + - - - + + + + - - - + + + + diff --git a/android/src/io/anuke/mindustry/AndroidLauncher.java b/android/src/io/anuke/mindustry/AndroidLauncher.java index af5b9139ae..bf03462dad 100644 --- a/android/src/io/anuke/mindustry/AndroidLauncher.java +++ b/android/src/io/anuke/mindustry/AndroidLauncher.java @@ -4,11 +4,13 @@ import android.Manifest; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.provider.Settings.Secure; import android.telephony.TelephonyManager; import android.util.Log; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.badlogic.gdx.files.FileHandle; @@ -22,13 +24,21 @@ import io.anuke.kryonet.KryoClient; import io.anuke.kryonet.KryoServer; import io.anuke.mindustry.core.Platform; import io.anuke.mindustry.core.ThreadHandler.ThreadProvider; +import io.anuke.mindustry.io.SaveIO; +import io.anuke.mindustry.io.Saves.SaveSlot; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.ui.dialogs.FileChooser; import io.anuke.ucore.core.Settings; import io.anuke.ucore.function.Consumer; import io.anuke.ucore.scene.ui.TextField; import io.anuke.ucore.scene.ui.layout.Unit; +import io.anuke.ucore.util.Bundles; +import io.anuke.ucore.util.Strings; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.text.DateFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; @@ -37,6 +47,8 @@ import java.util.Date; import java.util.Locale; import java.util.Random; +import static io.anuke.mindustry.Vars.*; + public class AndroidLauncher extends AndroidApplication{ public static final int PERMISSION_REQUEST_CODE = 1; @@ -172,6 +184,8 @@ public class AndroidLauncher extends AndroidApplication{ Net.setServerProvider(new KryoServer()); initialize(new Mindustry(), config); + + checkFiles(getIntent()); } @Override @@ -186,6 +200,63 @@ public class AndroidLauncher extends AndroidApplication{ } } } + + private void checkFiles(Intent intent){ + try { + Uri uri = intent.getData(); + if (uri != null) { + File myFile = null; + String scheme = uri.getScheme(); + if (scheme.equals("file")) { + String fileName = uri.getEncodedPath(); + myFile = new File(fileName); + } else if (!scheme.equals("content")) { + //error + return; + } + + boolean save = uri.getPath().endsWith(saveExtension); + boolean map = uri.getPath().endsWith(mapExtension); + + InputStream inStream; + if (myFile != null) inStream = new FileInputStream(myFile); + else inStream = getContentResolver().openInputStream(uri); + + Gdx.app.postRunnable(() -> { + + if(save){ //open save + System.out.println("Opening save."); + FileHandle file = Gdx.files.local("temp-save." + saveExtension); + file.write(inStream, false); + + if(SaveIO.isSaveValid(file)){ + try{ + SaveSlot slot = control.getSaves().importSave(file); + ui.load.runLoadSave(slot); + }catch (IOException e){ + ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false))); + } + }else{ + ui.showError("$text.save.import.invalid"); + } + + }else if(map){ //open map + Gdx.app.postRunnable(() -> { + System.out.println("Opening map."); + if (!ui.editor.isShown()) { + ui.editor.show(); + } + + ui.editor.beginEditMap(inStream); + }); + } + }); + } + + }catch (IOException e){ + e.printStackTrace(); + } + } private boolean isPackageInstalled(String packagename) { try { diff --git a/core/src/Mindustry.gwt.xml b/core/src/Mindustry.gwt.xml index efc50b6b51..91d3560f24 100644 --- a/core/src/Mindustry.gwt.xml +++ b/core/src/Mindustry.gwt.xml @@ -11,8 +11,12 @@ + + + + diff --git a/core/src/io/anuke/mindustry/core/ContentLoader.java b/core/src/io/anuke/mindustry/core/ContentLoader.java index 0623a07ef5..c778b2fc57 100644 --- a/core/src/io/anuke/mindustry/core/ContentLoader.java +++ b/core/src/io/anuke/mindustry/core/ContentLoader.java @@ -16,64 +16,69 @@ import io.anuke.ucore.util.Log; /**Loads all game content. * Call load() before doing anything with content.*/ public class ContentLoader { + private static boolean loaded = false; + private static ContentList[] content = { + //effects + new BlockFx(), + new BulletFx(), + new EnvironmentFx(), + new ExplosionFx(), + new Fx(), + new ShootFx(), + new UnitFx(), + + //items + new Items(), + + //status effects + new StatusEffects(), + + //liquids + new Liquids(), + + //bullets + new ArtilleryBullets(), + new FlakBullets(), + new MissileBullets(), + new ShellBullets(), + new StandardBullets(), + new TurretBullets(), + + //ammotypes + new AmmoTypes(), + + //mechs + new Mechs(), + + //weapons + new Weapons(), + + //blocks + new Blocks(), + new DefenseBlocks(), + new DistributionBlocks(), + new ProductionBlocks(), + new WeaponBlocks(), + new DebugBlocks(), + new LiquidBlocks(), + new StorageBlocks(), + new UnitBlocks(), + new PowerBlocks(), + new CraftingBlocks(), + + //recipes + new Recipes(), + + //units + new UnitTypes(), + }; + public static void load(){ - - ContentList[] content = { - //effects - new BlockFx(), - new BulletFx(), - new EnvironmentFx(), - new ExplosionFx(), - new Fx(), - new ShootFx(), - new UnitFx(), - - //items - new Items(), - - //status effects - new StatusEffects(), - - //liquids - new Liquids(), - - //bullets - new ArtilleryBullets(), - new FlakBullets(), - new MissileBullets(), - new ShellBullets(), - new StandardBullets(), - new TurretBullets(), - - //ammotypes - new AmmoTypes(), - - //mechs - new Mechs(), - - //weapons - new Weapons(), - - //blocks - new Blocks(), - new DefenseBlocks(), - new DistributionBlocks(), - new ProductionBlocks(), - new WeaponBlocks(), - new DebugBlocks(), - new LiquidBlocks(), - new StorageBlocks(), - new UnitBlocks(), - new PowerBlocks(), - new CraftingBlocks(), - - //recipes - new Recipes(), - - //units - new UnitTypes(), - }; + if(loaded){ + Log.info("Content already loaded, skipping."); + return; + } for (ContentList list : content){ list.load(); @@ -89,5 +94,11 @@ public class ContentLoader { io.anuke.mindustry.type.Mech.all().size, UnitType.getAllTypes().size, io.anuke.mindustry.type.AmmoType.all().size, BulletType.all().size, StatusEffect.getAllEffects().size, io.anuke.mindustry.type.Recipe.all().size, Effects.all().size, content.length); Log.info("-------------------"); + + loaded = true; + } + + public static void dispose(){ + //TODO clear all content. } } diff --git a/core/src/io/anuke/mindustry/entities/effect/Fire.java b/core/src/io/anuke/mindustry/entities/effect/Fire.java index fdcc9539f7..c8407867e5 100644 --- a/core/src/io/anuke/mindustry/entities/effect/Fire.java +++ b/core/src/io/anuke/mindustry/entities/effect/Fire.java @@ -54,7 +54,7 @@ public class Fire extends TimedEntity implements SerializableEntity, Poolable{ } /**Deserialization use only!*/ - private Fire(){} + public Fire(){} @Override public void update() { diff --git a/core/src/io/anuke/mindustry/entities/ItemTransfer.java b/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java similarity index 97% rename from core/src/io/anuke/mindustry/entities/ItemTransfer.java rename to core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java index f7b1612a72..5296afc4bd 100644 --- a/core/src/io/anuke/mindustry/entities/ItemTransfer.java +++ b/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java @@ -1,4 +1,4 @@ -package io.anuke.mindustry.entities; +package io.anuke.mindustry.entities.effect; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Vector2; @@ -35,7 +35,7 @@ public class ItemTransfer extends TimedEntity{ tr.add(); } - private ItemTransfer(){} + public ItemTransfer(){} @Override public void reset() { diff --git a/core/src/io/anuke/mindustry/entities/effect/Puddle.java b/core/src/io/anuke/mindustry/entities/effect/Puddle.java index 3a574de1cb..3e56513651 100644 --- a/core/src/io/anuke/mindustry/entities/effect/Puddle.java +++ b/core/src/io/anuke/mindustry/entities/effect/Puddle.java @@ -125,7 +125,7 @@ public class Puddle extends Entity implements SerializableEntity, Poolable{ } /**Deserialization use only!*/ - private Puddle(){} + public Puddle(){} public float getFlammability(){ return liquid.flammability * amount; diff --git a/core/src/io/anuke/mindustry/entities/effect/Rubble.java b/core/src/io/anuke/mindustry/entities/effect/Rubble.java index 3cd542da03..160dc5fa6c 100644 --- a/core/src/io/anuke/mindustry/entities/effect/Rubble.java +++ b/core/src/io/anuke/mindustry/entities/effect/Rubble.java @@ -19,7 +19,7 @@ public class Rubble extends TimedEntity implements BelowLiquidEffect{ rubble.set(x, y).add(); } - private Rubble(){ + public Rubble(){ lifetime = 7000f; } diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 8176d41bb3..9ee29d7975 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -3,7 +3,7 @@ package io.anuke.mindustry.input; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.math.Vector2; import io.anuke.mindustry.entities.BlockBuilder.BuildRequest; -import io.anuke.mindustry.entities.ItemTransfer; +import io.anuke.mindustry.entities.effect.ItemTransfer; import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.type.Recipe; diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java index 60d93a4185..cc617ff9d4 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java @@ -5,7 +5,7 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.IntSet; import io.anuke.mindustry.core.GameState.State; -import io.anuke.mindustry.entities.ItemTransfer; +import io.anuke.mindustry.entities.effect.ItemTransfer; import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.input.InputHandler; import io.anuke.mindustry.type.Item; diff --git a/core/src/io/anuke/mindustry/world/blocks/types/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/types/storage/CoreBlock.java index 578df327bb..498d475cca 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/storage/CoreBlock.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Rectangle; import io.anuke.mindustry.Vars; import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.entities.*; +import io.anuke.mindustry.entities.effect.ItemTransfer; import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.net.Net;