.mmap file importing / Better exception parsing
This commit is contained in:
@@ -12,6 +12,7 @@ import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.arc.scene.ui.layout.Unit;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.pooling.Pools;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -31,6 +32,11 @@ public class FileChooser extends FloatingDialog{
|
||||
private boolean open;
|
||||
private int lastWidth = Core.graphics.getWidth(), lastHeight = Core.graphics.getHeight();
|
||||
|
||||
public static final Predicate<String> pngFiles = str -> str.equals("png");
|
||||
public static final Predicate<String> anyMapFiles = str -> str.equals(Vars.oldMapExtension) || str.equals(Vars.mapExtension);
|
||||
public static final Predicate<String> mapFiles = str -> str.equals(Vars.mapExtension);
|
||||
public static final Predicate<String> saveFiles = str -> str.equals(Vars.saveExtension);
|
||||
|
||||
public FileChooser(String title, Predicate<FileHandle> filter, boolean open, Consumer<FileHandle> result){
|
||||
super(title);
|
||||
this.open = open;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class HostDialog extends FloatingDialog{
|
||||
Net.host(Vars.port);
|
||||
player.isAdmin = true;
|
||||
}catch(IOException e){
|
||||
ui.showError(Core.bundle.format("server.error", Strings.parseException(e, false)));
|
||||
ui.showError(Core.bundle.format("server.error", Strings.parseException(e, true)));
|
||||
}
|
||||
ui.loadfrag.hide();
|
||||
hide();
|
||||
|
||||
@@ -90,16 +90,16 @@ public class LoadDialog extends FloatingDialog{
|
||||
slot.exportFile(file);
|
||||
setup();
|
||||
}catch(IOException e){
|
||||
ui.showError(Core.bundle.format("save.export.fail", Strings.parseException(e, false)));
|
||||
ui.showError(Core.bundle.format("save.export.fail", Strings.parseException(e, true)));
|
||||
}
|
||||
}, false, saveExtension);
|
||||
}, false, FileChooser.saveFiles);
|
||||
}else{
|
||||
try{
|
||||
FileHandle file = Core.files.local("save-" + slot.getName() + "." + Vars.saveExtension);
|
||||
slot.exportFile(file);
|
||||
Platform.instance.shareFile(file);
|
||||
}catch(Exception e){
|
||||
ui.showError(Core.bundle.format("save.export.fail", Strings.parseException(e, false)));
|
||||
ui.showError(Core.bundle.format("save.export.fail", Strings.parseException(e, true)));
|
||||
}
|
||||
}
|
||||
}).size(14 * 3).right();
|
||||
@@ -155,12 +155,12 @@ public class LoadDialog extends FloatingDialog{
|
||||
setup();
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
ui.showError(Core.bundle.format("save.import.fail", Strings.parseException(e, false)));
|
||||
ui.showError(Core.bundle.format("save.import.fail", Strings.parseException(e, true)));
|
||||
}
|
||||
}else{
|
||||
ui.showError("$save.import.invalid");
|
||||
}
|
||||
}, true, saveExtension);
|
||||
}, true, FileChooser.saveFiles);
|
||||
}).fillX().margin(10f).minWidth(300f).height(70f).pad(4f).padRight(-4);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.scene.event.Touchable;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.Scaling;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.io.MapIO;
|
||||
@@ -23,8 +23,19 @@ public class MapsDialog extends FloatingDialog{
|
||||
addCloseButton();
|
||||
buttons.addImageTextButton("$editor.importmap", "icon-add", 14 * 2, () -> {
|
||||
Platform.instance.showFileChooser("$editor.importmap", "Map File", file -> {
|
||||
try{
|
||||
Map map = MapIO.createMap(file, true);
|
||||
world.maps.tryCatchMapError(() -> {
|
||||
if(MapIO.isImage(file)){
|
||||
ui.showError("$editor.errorimage");
|
||||
return;
|
||||
}
|
||||
|
||||
Map map;
|
||||
if(file.extension().equalsIgnoreCase(mapExtension)){
|
||||
map = MapIO.createMap(file, true);
|
||||
}else{
|
||||
map = world.maps.makeLegacyMap(file);
|
||||
}
|
||||
|
||||
String name = map.tags.get("name");
|
||||
if(name == null){
|
||||
ui.showError("$editor.errorname");
|
||||
@@ -34,27 +45,21 @@ public class MapsDialog extends FloatingDialog{
|
||||
Map conflict = world.maps.all().find(m -> m.name().equals(name));
|
||||
|
||||
if(conflict != null && !conflict.custom){
|
||||
ui.showError(Core.bundle.format("editor.import.exists", name));
|
||||
ui.showInfo(Core.bundle.format("editor.import.exists", name));
|
||||
}else if(conflict != null){
|
||||
ui.showConfirm("$confirm", "$editor.overwrite.confirm", () -> {
|
||||
try{
|
||||
world.maps.tryCatchMapError(() -> {
|
||||
world.maps.importMap(file);
|
||||
setup();
|
||||
}catch(Exception e){
|
||||
ui.showError(Core.bundle.format("editor.errorload", Strings.parseException(e, false)));
|
||||
Log.err(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}else{
|
||||
world.maps.importMap(file);
|
||||
world.maps.importMap(map.file);
|
||||
setup();
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
ui.showError(Core.bundle.format("editor.errorload", Strings.parseException(e, false)));
|
||||
Log.err(e);
|
||||
}
|
||||
}, true, mapExtension);
|
||||
});
|
||||
}, true, FileChooser.anyMapFiles);
|
||||
}).size(230f, 64f);
|
||||
|
||||
shown(this::setup);
|
||||
|
||||
Reference in New Issue
Block a user