Fixed map loading bugs
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 719 B After Width: | Height: | Size: 718 B |
Before Width: | Height: | Size: 682 KiB After Width: | Height: | Size: 672 KiB |
Before Width: | Height: | Size: 274 KiB After Width: | Height: | Size: 258 KiB |
Before Width: | Height: | Size: 579 KiB After Width: | Height: | Size: 574 KiB |
@ -184,7 +184,7 @@ public class Maps{
|
|||||||
FileHandle dest = findFile();
|
FileHandle dest = findFile();
|
||||||
file.copyTo(dest);
|
file.copyTo(dest);
|
||||||
|
|
||||||
loadMap(dest, true);
|
createNewPreview(loadMap(dest, true), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Attempts to run the following code;
|
/** Attempts to run the following code;
|
||||||
@ -341,7 +341,7 @@ public class Maps{
|
|||||||
private void createAllPreviews(){
|
private void createAllPreviews(){
|
||||||
Core.app.post(() -> {
|
Core.app.post(() -> {
|
||||||
for(Map map : previewList){
|
for(Map map : previewList){
|
||||||
createNewPreview(map);
|
createNewPreview(map, false);
|
||||||
}
|
}
|
||||||
previewList.clear();
|
previewList.clear();
|
||||||
});
|
});
|
||||||
@ -351,12 +351,16 @@ public class Maps{
|
|||||||
Core.app.post(() -> previewList.add(map));
|
Core.app.post(() -> previewList.add(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewPreview(Map map){
|
private void createNewPreview(Map map, boolean immediate){
|
||||||
try{
|
try{
|
||||||
//if it's here, then the preview failed to load or doesn't exist, make it
|
//if it's here, then the preview failed to load or doesn't exist, make it
|
||||||
//this has to be done synchronously!
|
//this has to be done synchronously!
|
||||||
Pixmap pix = MapIO.generatePreview(map);
|
Pixmap pix = MapIO.generatePreview(map);
|
||||||
Core.app.post(() -> map.texture = new Texture(pix));
|
if(immediate){
|
||||||
|
map.texture = new Texture(pix);
|
||||||
|
}else{
|
||||||
|
Core.app.post(() -> map.texture = new Texture(pix));
|
||||||
|
}
|
||||||
executor.submit(() -> {
|
executor.submit(() -> {
|
||||||
try{
|
try{
|
||||||
map.previewFile().writePNG(pix);
|
map.previewFile().writePNG(pix);
|
||||||
@ -404,7 +408,7 @@ public class Maps{
|
|||||||
return customMapDirectory.child("map_" + i + "." + mapExtension);
|
return customMapDirectory.child("map_" + i + "." + mapExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMap(FileHandle file, boolean custom) throws IOException{
|
private Map loadMap(FileHandle file, boolean custom) throws IOException{
|
||||||
Map map = MapIO.createMap(file, custom);
|
Map map = MapIO.createMap(file, custom);
|
||||||
|
|
||||||
if(map.name() == null){
|
if(map.name() == null){
|
||||||
@ -413,6 +417,7 @@ public class Maps{
|
|||||||
|
|
||||||
maps.add(map);
|
maps.add(map);
|
||||||
maps.sort();
|
maps.sort();
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadCustomMaps(){
|
private void loadCustomMaps(){
|
||||||
|
@ -42,7 +42,7 @@ public class Zone extends UnlockableContent{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
preview = Core.atlas.find(name);
|
preview = Core.atlas.find("zone-" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rules getRules(){
|
public Rules getRules(){
|
||||||
|
@ -62,49 +62,52 @@ public class MapsDialog extends FloatingDialog{
|
|||||||
if(!ios){
|
if(!ios){
|
||||||
buttons.addImageTextButton("$editor.importmap", "icon-load", iconsize, () -> {
|
buttons.addImageTextButton("$editor.importmap", "icon-load", iconsize, () -> {
|
||||||
platform.showFileChooser("$editor.importmap", "Map File", file -> {
|
platform.showFileChooser("$editor.importmap", "Map File", file -> {
|
||||||
maps.tryCatchMapError(() -> {
|
ui.loadAnd(() -> {
|
||||||
if(MapIO.isImage(file)){
|
maps.tryCatchMapError(() -> {
|
||||||
ui.showError("$editor.errorimage");
|
if(MapIO.isImage(file)){
|
||||||
return;
|
ui.showError("$editor.errorimage");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Map map;
|
Map map;
|
||||||
if(file.extension().equalsIgnoreCase(mapExtension)){
|
if(file.extension().equalsIgnoreCase(mapExtension)){
|
||||||
map = MapIO.createMap(file, true);
|
map = MapIO.createMap(file, true);
|
||||||
}else{
|
}else{
|
||||||
map = maps.makeLegacyMap(file);
|
map = maps.makeLegacyMap(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
//when you attempt to import a save, it will have no name, so generate one
|
//when you attempt to import a save, it will have no name, so generate one
|
||||||
String name = map.tags.getOr("name", () -> {
|
String name = map.tags.getOr("name", () -> {
|
||||||
String result = "unknown";
|
String result = "unknown";
|
||||||
int number = 0;
|
int number = 0;
|
||||||
while(maps.byName(result + number++) != null) ;
|
while(maps.byName(result + number++) != null) ;
|
||||||
return result + number;
|
return result + number;
|
||||||
});
|
|
||||||
|
|
||||||
//this will never actually get called, but it remains just in case
|
|
||||||
if(name == null){
|
|
||||||
ui.showError("$editor.errorname");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map conflict = maps.all().find(m -> m.name().equals(name));
|
|
||||||
|
|
||||||
if(conflict != null && !conflict.custom){
|
|
||||||
ui.showInfo(Core.bundle.format("editor.import.exists", name));
|
|
||||||
}else if(conflict != null){
|
|
||||||
ui.showConfirm("$confirm", "$editor.overwrite.confirm", () -> {
|
|
||||||
maps.tryCatchMapError(() -> {
|
|
||||||
maps.importMap(file);
|
|
||||||
setup();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}else{
|
|
||||||
maps.importMap(map.file);
|
|
||||||
setup();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//this will never actually get called, but it remains just in case
|
||||||
|
if(name == null){
|
||||||
|
ui.showError("$editor.errorname");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map conflict = maps.all().find(m -> m.name().equals(name));
|
||||||
|
|
||||||
|
if(conflict != null && !conflict.custom){
|
||||||
|
ui.showInfo(Core.bundle.format("editor.import.exists", name));
|
||||||
|
}else if(conflict != null){
|
||||||
|
ui.showConfirm("$confirm", "$editor.overwrite.confirm", () -> {
|
||||||
|
maps.tryCatchMapError(() -> {
|
||||||
|
maps.removeMap(conflict);
|
||||||
|
maps.importMap(map.file);
|
||||||
|
setup();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
maps.importMap(map.file);
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, true, FileChooser.anyMapFiles);
|
}, true, FileChooser.anyMapFiles);
|
||||||
}).size(210f, 64f);
|
}).size(210f, 64f);
|
||||||
|