Fixed autosave

This commit is contained in:
Anuken
2017-12-29 19:27:21 -05:00
parent b7c8ff4d5b
commit 019cc75fb9
7 changed files with 956 additions and 33 deletions

View File

@@ -282,6 +282,7 @@ public class Control extends Module{
public void playMap(Map map){
Vars.ui.showLoading();
saves.resetSave();
Timers.run(16, ()->{
reset();
@@ -554,6 +555,8 @@ public class Control extends Module{
}
Gdx.input.setCursorCatched(controlling);
saves.update();
if(debug && GameState.is(State.playing)){
//debug actions

View File

@@ -226,6 +226,7 @@ public class UI extends SceneModule{
prefs.game.checkPref("indicators", true);
prefs.game.checkPref("effects", true);
prefs.game.sliderPref("sensitivity", 100, 10, 300, i -> i + "%");
prefs.game.sliderPref("saveinterval", 120, 15, 5*120, i -> Bundles.format("setting.seconds", i));
prefs.graphics.checkPref("fps", false);
prefs.graphics.checkPref("vsync", true, b -> Gdx.graphics.setVSync(b));

View File

@@ -14,6 +14,7 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.world.GameMode;
import io.anuke.mindustry.world.Map;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import java.io.IOException;
@@ -22,6 +23,7 @@ public class Saves {
private Array<SaveSlot> saves = new Array<>();
private SaveSlot current;
private boolean saving;
private float time;
private AsyncExecutor exec = new AsyncExecutor(1);
@@ -33,44 +35,30 @@ public class Saves {
nextSlot = i + 1;
}
}
}
public void update(){
if(!GameState.is(State.menu) && !GameState.is(State.dead) && current != null && current.isAutosave()){
time += Timers.delta();
if(time > Settings.getInt("saveinterval")*60) {
saving = true;
Vars.ui.showError("sacving");
Timer.schedule(new Task() {
Field field;
int lastInterval;
exec.submit(() -> {
SaveIO.saveToSlot(current.index);
saving = false;
return true;
});
{
try{
field = ClassReflection.getDeclaredField(getClass(), "intervalMillis");
field.setAccessible(true);
}catch (ReflectionException e){
throw new RuntimeException(e);
}
time = 0;
}
}else{
time = 0;
}
}
@Override
public void run() {
if(Settings.getInt("saveinterval") != lastInterval){
try{
field.set(this, (long)(Settings.getInt("saveinterval")) / 60f * 1000);
}catch (ReflectionException e){
throw new RuntimeException(e);
}
lastInterval = Settings.getInt("saveinterval");
}
if(!GameState.is(State.menu) && !GameState.is(State.dead) && current != null && current.isAutosave()){
saving = true;
exec.submit(() -> {
SaveIO.saveToSlot(current.index);
saving = false;
return true;
});
}
}
}, 0f, 60f*2);
public void resetSave(){
current = null;
}
public boolean isSaving(){

View File

@@ -2,6 +2,7 @@ package io.anuke.mindustry.ui.fragments;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
@@ -148,6 +149,14 @@ public class HudFragment implements Fragment{
}}.end();
}
new table(){{
abottom();
visible(() -> !GameState.is(State.menu) && Vars.control.getSaves().isSaving());
new label("$text.saveload");
}}.end();
blockfrag.build();
}