Map fixes
This commit is contained in:
@@ -231,7 +231,7 @@ public class Control implements ApplicationListener, Loadable{
|
|||||||
world.loadMap(map, rules);
|
world.loadMap(map, rules);
|
||||||
state.rules = rules;
|
state.rules = rules;
|
||||||
logic.play();
|
logic.play();
|
||||||
if(settings.getBool("savecreate")){
|
if(settings.getBool("savecreate") && !world.isInvalidMap()){
|
||||||
control.saves.addSave(map.name() + " " + new SimpleDateFormat("MMM dd h:mm", Locale.getDefault()).format(new Date()));
|
control.saves.addSave(map.name() + " " + new SimpleDateFormat("MMM dd h:mm", Locale.getDefault()).format(new Date()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class MapPreviewLoader extends TextureLoader{
|
|||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MapPreviewParameter param = (MapPreviewParameter)parameter;
|
MapPreviewParameter param = (MapPreviewParameter)parameter;
|
||||||
Vars.maps.createNewPreview(param.map);
|
Vars.maps.queueNewPreview(param.map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public class Maps{
|
|||||||
private Json json = new Json();
|
private Json json = new Json();
|
||||||
|
|
||||||
private AsyncExecutor executor = new AsyncExecutor(2);
|
private AsyncExecutor executor = new AsyncExecutor(2);
|
||||||
|
private ObjectSet<Map> previewList = new ObjectSet<>();
|
||||||
|
|
||||||
/** Returns a list of all maps, including custom ones. */
|
/** Returns a list of all maps, including custom ones. */
|
||||||
public Array<Map> all(){
|
public Array<Map> all(){
|
||||||
@@ -58,6 +59,8 @@ public class Maps{
|
|||||||
Events.on(ClientLoadEvent.class, event -> {
|
Events.on(ClientLoadEvent.class, event -> {
|
||||||
maps.sort();
|
maps.sort();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
((CustomLoader)Core.assets.getLoader(Content.class)).loaded = this::createAllPreviews;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,8 +152,13 @@ public class Maps{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Core.assets.isLoaded(map.previewFile().path() + "." + mapExtension)){
|
||||||
|
Core.assets.unload(map.previewFile().path() + "." + mapExtension);
|
||||||
|
}
|
||||||
|
|
||||||
Pixmap pix = MapIO.generatePreview(world.getTiles());
|
Pixmap pix = MapIO.generatePreview(world.getTiles());
|
||||||
executor.submit(() -> map.previewFile().writePNG(pix));
|
executor.submit(() -> map.previewFile().writePNG(pix));
|
||||||
|
writeCache(map);
|
||||||
|
|
||||||
map.texture = new Texture(pix);
|
map.texture = new Texture(pix);
|
||||||
}
|
}
|
||||||
@@ -309,27 +317,39 @@ public class Maps{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadPreviews(){
|
public void loadPreviews(){
|
||||||
Array<Map> createNew = new Array<>();
|
|
||||||
|
|
||||||
for(Map map : maps){
|
for(Map map : maps){
|
||||||
//try to load preview
|
//try to load preview
|
||||||
if(map.previewFile().exists()){
|
if(map.previewFile().exists()){
|
||||||
//this may fail, but calls createNewPreview
|
//this may fail, but calls createNewPreview
|
||||||
Core.assets.load(new AssetDescriptor<>(map.previewFile().path() + "." + mapExtension, Texture.class, new MapPreviewParameter(map))).loaded = t -> map.texture = (Texture)t;
|
Core.assets.load(new AssetDescriptor<>(map.previewFile().path() + "." + mapExtension, Texture.class, new MapPreviewParameter(map))).loaded = t -> map.texture = (Texture)t;
|
||||||
}else{
|
|
||||||
createNew.add(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
readCache(map);
|
readCache(map);
|
||||||
}catch(Exception ignored){
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
queueNewPreview(map);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
queueNewPreview(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
((CustomLoader)Core.assets.getLoader(Content.class)).loaded = () -> Core.app.post(() -> createNew.each(this::createNewPreview));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createNewPreview(Map map){
|
private void createAllPreviews(){
|
||||||
|
Core.app.post(() -> {
|
||||||
|
for(Map map : previewList){
|
||||||
|
createNewPreview(map);
|
||||||
|
}
|
||||||
|
previewList.clear();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void queueNewPreview(Map map){
|
||||||
|
Core.app.post(() -> previewList.add(map));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createNewPreview(Map map){
|
||||||
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!
|
||||||
|
|||||||
Reference in New Issue
Block a user