Loadout selection + custom loadout schematics
This commit is contained in:
@@ -55,6 +55,7 @@ public class Schematics implements Loadable{
|
||||
private Seq<Schematic> all = new Seq<>();
|
||||
private OrderedMap<Schematic, FrameBuffer> previews = new OrderedMap<>();
|
||||
private ObjectSet<Schematic> errored = new ObjectSet<>();
|
||||
private ObjectMap<CoreBlock, Seq<Schematic>> loadouts = new ObjectMap<>();
|
||||
private FrameBuffer shadowBuffer;
|
||||
private Texture errorTexture;
|
||||
private long lastClearTime;
|
||||
@@ -85,6 +86,8 @@ public class Schematics implements Loadable{
|
||||
public void load(){
|
||||
all.clear();
|
||||
|
||||
loadLoadouts();
|
||||
|
||||
for(Fi file : schematicDirectory.list()){
|
||||
loadFile(file);
|
||||
}
|
||||
@@ -109,6 +112,10 @@ public class Schematics implements Loadable{
|
||||
bases.load();
|
||||
}
|
||||
|
||||
private void loadLoadouts(){
|
||||
Seq.with(Loadouts.basicShard, Loadouts.basicFoundation, Loadouts.basicNucleus).each(s -> checkLoadout(s,false));
|
||||
}
|
||||
|
||||
public void overwrite(Schematic target, Schematic newSchematic){
|
||||
if(previews.containsKey(target)){
|
||||
previews.get(target).dispose();
|
||||
@@ -136,6 +143,7 @@ public class Schematics implements Loadable{
|
||||
try{
|
||||
Schematic s = read(file);
|
||||
all.add(s);
|
||||
checkLoadout(s, true);
|
||||
|
||||
//external file from workshop
|
||||
if(!s.file.parent().equals(schematicDirectory)){
|
||||
@@ -275,6 +283,22 @@ public class Schematics implements Loadable{
|
||||
.removeAll(s -> !s.block.isVisible() || !s.block.unlockedNow());
|
||||
}
|
||||
|
||||
/** @return all the valid loadouts for a specific core type. */
|
||||
public Seq<Schematic> getLoadouts(CoreBlock block){
|
||||
return loadouts.get(block, Seq::new);
|
||||
}
|
||||
|
||||
/** Checks a schematic for deployment validity and adds it to the cache. */
|
||||
private void checkLoadout(Schematic s, boolean validate){
|
||||
Stile core = s.tiles.find(t -> t.block instanceof CoreBlock);
|
||||
|
||||
//make sure a core exists, and that the schematic is small enough.
|
||||
if(core == null || (validate && (s.width > core.block.size + maxLoadoutSchematicPad *2 || s.height > core.block.size + maxLoadoutSchematicPad *2))) return;
|
||||
|
||||
//place in the cache
|
||||
loadouts.get((CoreBlock)core.block, Seq::new).add(s);
|
||||
}
|
||||
|
||||
/** Adds a schematic to the list, also copying it into the files.*/
|
||||
public void add(Schematic schematic){
|
||||
all.add(schematic);
|
||||
@@ -286,11 +310,14 @@ public class Schematics implements Loadable{
|
||||
ui.showException(e);
|
||||
Log.err(e);
|
||||
}
|
||||
|
||||
checkLoadout(schematic, true);
|
||||
all.sort();
|
||||
}
|
||||
|
||||
public void remove(Schematic s){
|
||||
all.remove(s);
|
||||
loadouts.each((block, seq) -> seq.remove(s));
|
||||
if(s.file != null){
|
||||
s.file.delete();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import mindustry.game.EventType.*;
|
||||
import mindustry.game.SectorInfo.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -19,6 +20,7 @@ public class Universe{
|
||||
private float secondCounter;
|
||||
private int turn;
|
||||
private float turnCounter;
|
||||
private Schematic lastLoadout = Loadouts.basicShard;
|
||||
|
||||
public Universe(){
|
||||
load();
|
||||
@@ -73,6 +75,31 @@ public class Universe{
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates selected loadout for future deployment. */
|
||||
public void updateLoadout(CoreBlock block, Schematic schem){
|
||||
Core.settings.put("lastloadout-" + block.name, schem.file == null ? "" : schem.file.nameWithoutExtension());
|
||||
lastLoadout = schem;
|
||||
}
|
||||
|
||||
public Schematic getLastLoadout(){
|
||||
return lastLoadout;
|
||||
}
|
||||
|
||||
/** @return the last selected loadout for this specific core type. */
|
||||
public Schematic getLoadout(CoreBlock core){
|
||||
//for tools - schem
|
||||
if(schematics == null) return Loadouts.basicShard;
|
||||
|
||||
//find last used loadout file name
|
||||
String file = Core.settings.getString("lastloadout-" + core.name, "");
|
||||
|
||||
//use default (first) schematic if not found
|
||||
Seq<Schematic> all = schematics.getLoadouts(core);
|
||||
Schematic schem = all.find(s -> s.file != null && s.file.nameWithoutExtension().equals(file));
|
||||
|
||||
return schem == null ? all.first() : schem;
|
||||
}
|
||||
|
||||
public int[] getTotalExports(){
|
||||
int[] exports = new int[Vars.content.items().size];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user