mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-03-17 12:21:19 -07:00
Added autosave
This commit is contained in:
parent
036a246769
commit
152dc515db
4 changed files with 44 additions and 5 deletions
|
|
@ -25,7 +25,7 @@ io.anuke.ucore.scene.Skin$TintedDrawable: {
|
|||
dialogDim: {name: white, color: {r: 0, g: 0, b: 0, a: 0.9} },
|
||||
invis: {name: white, color: {r: 0, g: 0, b: 0, a: 0} }
|
||||
loadDim: {name: white, color: {r: 0, g: 0, b: 0, a: 0.8} },
|
||||
clear: {name: white, color: {r: 0.1, g: 0.1, b: 0.1, a: 0.7}},
|
||||
clear: {name: white, color: {r: 0.1, g: 0.1, b: 0.1, a: 0.75}},
|
||||
clear-over: {name: white, color: {r: 1, g: 1, b: 1, a: 0.2} },
|
||||
clear-down: {name: white, color: {r: 1, g: 1, b: 1, a: 0.4} }
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,7 +2,12 @@ package io.anuke.mindustry.io;
|
|||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Timer;
|
||||
import com.badlogic.gdx.utils.Timer.Task;
|
||||
import com.badlogic.gdx.utils.async.AsyncExecutor;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
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;
|
||||
|
|
@ -12,6 +17,10 @@ import java.io.IOException;
|
|||
public class Saves {
|
||||
private int nextSlot;
|
||||
private Array<SaveSlot> saves = new Array<>();
|
||||
private SaveSlot current;
|
||||
private boolean saving;
|
||||
|
||||
private AsyncExecutor exec = new AsyncExecutor(1);
|
||||
|
||||
public void load(){
|
||||
saves.clear();
|
||||
|
|
@ -21,6 +30,26 @@ public class Saves {
|
|||
nextSlot = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Timer.schedule(new Task() {
|
||||
@Override
|
||||
public void run() {
|
||||
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 boolean isSaving(){
|
||||
return saving;
|
||||
}
|
||||
|
||||
public boolean canAddSave(){
|
||||
|
|
@ -46,6 +75,16 @@ public class Saves {
|
|||
this.index = index;
|
||||
}
|
||||
|
||||
public void load(){
|
||||
current = this;
|
||||
SaveIO.loadFromSlot(index);
|
||||
}
|
||||
|
||||
public void save(){
|
||||
current = this;
|
||||
SaveIO.isSaveValid(index);
|
||||
}
|
||||
|
||||
public String getDate(){
|
||||
return SaveIO.getTimeString(index);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ public class LoadDialog extends FloatingDialog{
|
|||
Vars.ui.hideLoading();
|
||||
hide();
|
||||
try{
|
||||
SaveIO.loadFromSlot(slot.index);
|
||||
slot.load();
|
||||
GameState.set(State.playing);
|
||||
Vars.ui.hideMenu();
|
||||
}catch(Exception e){
|
||||
|
|
|
|||
|
|
@ -44,19 +44,19 @@ public class SaveDialog extends LoadDialog{
|
|||
if(button.childrenPressed()) return;
|
||||
|
||||
Vars.ui.showConfirm("$text.overwrite", "$text.save.overwrite", () -> {
|
||||
save(slot.index);
|
||||
save(slot);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void save(int slot){
|
||||
void save(SaveSlot slot){
|
||||
Vars.ui.showLoading("$text.saveload");
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
hide();
|
||||
Vars.ui.hideLoading();
|
||||
try{
|
||||
SaveIO.saveToSlot(slot);
|
||||
slot.save();
|
||||
}catch(Throwable e){
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue