mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-22 12:38:05 +07:00
Implemented loading map/save files on launch (Android)
This commit is contained in:
parent
23d07600f7
commit
c4ae6121b4
@ -21,21 +21,24 @@
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.EDIT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.msav" android:mimeType="application/io.anuke.mindustry.save" />
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:mimeType="application/octet-stream"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.EDIT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.mmap" android:mimeType="application/io.anuke.mindustry.map" />
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:mimeType="*/*"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -11,8 +11,12 @@
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.game.EventType" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.io.SaveFileVersion" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.type.Recipe" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.ucore.entities.EffectEntity" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.net.Packets" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.net.Packet" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities.effect" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities.Bullet" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.type.Recipe" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.net.Streamable" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.BlockBar" />
|
||||
<extend-configuration-property name="gdx.reflect.include" value="com.badlogic.gdx.utils.Predicate" />
|
||||
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class Fire extends TimedEntity implements SerializableEntity, Poolable{
|
||||
}
|
||||
|
||||
/**Deserialization use only!*/
|
||||
private Fire(){}
|
||||
public Fire(){}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
@ -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() {
|
@ -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;
|
||||
|
@ -19,7 +19,7 @@ public class Rubble extends TimedEntity implements BelowLiquidEffect{
|
||||
rubble.set(x, y).add();
|
||||
}
|
||||
|
||||
private Rubble(){
|
||||
public Rubble(){
|
||||
lifetime = 7000f;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user