package Hexel.rendering.overlays;
import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import Hexel.Engine;
import Hexel.Hexel;
import Hexel.Session;
import Hexel.Stage;
import Hexel.blocks.types.BlockDebug;
import Hexel.math.Vector3i;
import Hexel.rendering.GLChunk;
import Hexel.things.ThingsFile;
import Hexel.things.types.Player;
import Hexel.things.types.Thing;
public class LoadGameMenuItems {
public static MenuItem[] getLoadGameMenuItems(final Engine engine, final Runnable goBack){
final File[] saves = new File(Hexel.workingDir, Hexel.saveDir).listFiles();
int len = 0;
if (saves != null)
len = saves.length;
MenuItem[] items = new MenuItem[len+1];
for (int i = 0; i < len; i++){
final int _i = i;
items[i] = new MenuItem(saves[i].getName(), new Runnable() {
@Override
public void run() {
Hexel.session = new Session(saves[_i].getName());
Set<Thing> things = ThingsFile.load();
for (Thing thing : things){
thing.thingBridge = engine.getThingBridge();
//TODO thing bridge
if (thing instanceof Player){
Player player = (Player)thing;
engine.setControllable(player);
engine.setCamera(player);
}
engine.addThing(thing);
}
engine.setStage(Stage.INGAME);
}
});
}
items[items.length-1] = new MenuItem("back", new Runnable() {
@Override
public void run() {
goBack.run();
}
});
return items;
}
}