mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-03-27 09:11:06 -07:00
Fixed autosave not triggering
This commit is contained in:
parent
380d9908b4
commit
2c8cd2f8dc
3 changed files with 19 additions and 13 deletions
|
|
@ -233,6 +233,10 @@ public class UI extends SceneModule{
|
|||
}
|
||||
|
||||
public void loadLogic(Callable call){
|
||||
loadLogic("$text.loading", call);
|
||||
}
|
||||
|
||||
public void loadLogic(String text, Callable call){
|
||||
loadfrag.show();
|
||||
Timers.runTask(7f, () -> {
|
||||
threads.run(() -> {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import com.badlogic.gdx.files.FileHandle;
|
|||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.game.Difficulty;
|
||||
import io.anuke.mindustry.game.EventType.StateChangeEvent;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.ThreadArray;
|
||||
|
|
@ -20,6 +22,14 @@ public class Saves{
|
|||
private boolean saving;
|
||||
private float time;
|
||||
|
||||
public Saves(){
|
||||
Events.on(StateChangeEvent.class, (prev, state) -> {
|
||||
if(state == State.menu){
|
||||
threads.run(() -> current = null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void load(){
|
||||
saves.clear();
|
||||
for(int i = 0; i < saveSlots; i++){
|
||||
|
|
@ -37,9 +47,6 @@ public class Saves{
|
|||
}
|
||||
|
||||
public void update(){
|
||||
if(state.is(State.menu)){
|
||||
current = null;
|
||||
}
|
||||
|
||||
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave()){
|
||||
time += Timers.delta();
|
||||
|
|
@ -109,15 +116,15 @@ public class Saves{
|
|||
}
|
||||
|
||||
public void load(){
|
||||
current = this;
|
||||
SaveIO.loadFromSlot(index);
|
||||
meta = SaveIO.getData(index);
|
||||
current = this;
|
||||
}
|
||||
|
||||
public void save(){
|
||||
current = this;
|
||||
SaveIO.saveToSlot(index);
|
||||
meta = SaveIO.getData(index);
|
||||
current = this;
|
||||
}
|
||||
|
||||
public String getDate(){
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
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.imagebutton;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
|
@ -130,15 +128,12 @@ public class PausedDialog extends FloatingDialog{
|
|||
return;
|
||||
}
|
||||
|
||||
ui.loadfrag.show("$text.saveload");
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
ui.loadfrag.hide();
|
||||
ui.loadLogic("$text.saveload", () -> {
|
||||
try{
|
||||
control.getSaves().getCurrent().save();
|
||||
}catch(Throwable e){
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
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());
|
||||
e.printStackTrace();
|
||||
threads.runGraphics(() -> ui.showError("[orange]" + Bundles.get("text.savefail")));
|
||||
}
|
||||
state.set(State.menu);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue