Fixed autosave not triggering
This commit is contained in:
@@ -233,6 +233,10 @@ public class UI extends SceneModule{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadLogic(Callable call){
|
public void loadLogic(Callable call){
|
||||||
|
loadLogic("$text.loading", call);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadLogic(String text, Callable call){
|
||||||
loadfrag.show();
|
loadfrag.show();
|
||||||
Timers.runTask(7f, () -> {
|
Timers.runTask(7f, () -> {
|
||||||
threads.run(() -> {
|
threads.run(() -> {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import com.badlogic.gdx.files.FileHandle;
|
|||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.game.Difficulty;
|
import io.anuke.mindustry.game.Difficulty;
|
||||||
|
import io.anuke.mindustry.game.EventType.StateChangeEvent;
|
||||||
import io.anuke.mindustry.game.GameMode;
|
import io.anuke.mindustry.game.GameMode;
|
||||||
|
import io.anuke.ucore.core.Events;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.ThreadArray;
|
import io.anuke.ucore.util.ThreadArray;
|
||||||
@@ -20,6 +22,14 @@ public class Saves{
|
|||||||
private boolean saving;
|
private boolean saving;
|
||||||
private float time;
|
private float time;
|
||||||
|
|
||||||
|
public Saves(){
|
||||||
|
Events.on(StateChangeEvent.class, (prev, state) -> {
|
||||||
|
if(state == State.menu){
|
||||||
|
threads.run(() -> current = null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void load(){
|
public void load(){
|
||||||
saves.clear();
|
saves.clear();
|
||||||
for(int i = 0; i < saveSlots; i++){
|
for(int i = 0; i < saveSlots; i++){
|
||||||
@@ -37,9 +47,6 @@ public class Saves{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
if(state.is(State.menu)){
|
|
||||||
current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave()){
|
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave()){
|
||||||
time += Timers.delta();
|
time += Timers.delta();
|
||||||
@@ -109,15 +116,15 @@ public class Saves{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void load(){
|
public void load(){
|
||||||
current = this;
|
|
||||||
SaveIO.loadFromSlot(index);
|
SaveIO.loadFromSlot(index);
|
||||||
meta = SaveIO.getData(index);
|
meta = SaveIO.getData(index);
|
||||||
|
current = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(){
|
public void save(){
|
||||||
current = this;
|
|
||||||
SaveIO.saveToSlot(index);
|
SaveIO.saveToSlot(index);
|
||||||
meta = SaveIO.getData(index);
|
meta = SaveIO.getData(index);
|
||||||
|
current = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDate(){
|
public String getDate(){
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package io.anuke.mindustry.ui.dialogs;
|
package io.anuke.mindustry.ui.dialogs;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.core.Timers;
|
|
||||||
import io.anuke.ucore.scene.builders.build;
|
import io.anuke.ucore.scene.builders.build;
|
||||||
import io.anuke.ucore.scene.builders.imagebutton;
|
import io.anuke.ucore.scene.builders.imagebutton;
|
||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
@@ -130,15 +128,12 @@ public class PausedDialog extends FloatingDialog{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.loadfrag.show("$text.saveload");
|
ui.loadLogic("$text.saveload", () -> {
|
||||||
|
|
||||||
Timers.runTask(5f, () -> {
|
|
||||||
ui.loadfrag.hide();
|
|
||||||
try{
|
try{
|
||||||
control.getSaves().getCurrent().save();
|
control.getSaves().getCurrent().save();
|
||||||
}catch(Throwable e){
|
}catch(Throwable e){
|
||||||
e = (e.getCause() == null ? e : e.getCause());
|
e.printStackTrace();
|
||||||
ui.showError("[orange]" + Bundles.get("text.savefail") + "\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
|
threads.runGraphics(() -> ui.showError("[orange]" + Bundles.get("text.savefail")));
|
||||||
}
|
}
|
||||||
state.set(State.menu);
|
state.set(State.menu);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user