Schematic export buttons, workshop support progress
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.collection.IntIntMap.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.util.ArcAnnotate.*;
|
||||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
|
||||
public class Schematic{
|
||||
public final Array<Stile> tiles;
|
||||
public StringMap tags;
|
||||
public int width, height;
|
||||
public boolean workshop;
|
||||
public @Nullable FileHandle file;
|
||||
|
||||
public Schematic(Array<Stile> tiles, StringMap tags, int width, int height){
|
||||
@@ -19,10 +21,30 @@ public class Schematic{
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Array<ItemStack> requirements(){
|
||||
IntIntMap amounts = new IntIntMap();
|
||||
|
||||
tiles.each(t -> {
|
||||
for(ItemStack stack : t.block.requirements){
|
||||
amounts.getAndIncrement(stack.item.id, 0, stack.amount);
|
||||
}
|
||||
});
|
||||
Array<ItemStack> stacks = new Array<>();
|
||||
for(Entry ent : amounts.entries()){
|
||||
stacks.add(new ItemStack(Vars.content.item(ent.key), ent.value));
|
||||
}
|
||||
stacks.sort();
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public String name(){
|
||||
return tags.get("name", "unknown");
|
||||
}
|
||||
|
||||
public boolean isWorkshop(){
|
||||
return tags.containsKey("workshop");
|
||||
}
|
||||
|
||||
public static class Stile{
|
||||
public @NonNull Block block;
|
||||
public short x, y;
|
||||
|
||||
@@ -53,21 +53,28 @@ public class Schematics implements Loadable{
|
||||
/** Load all schematics in the folder immediately.*/
|
||||
public void load(){
|
||||
all.clear();
|
||||
for(FileHandle file : schematicDirectory.list()){
|
||||
if(!file.extension().equals(schematicExtension)) continue;
|
||||
|
||||
try{
|
||||
all.add(read(file));
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
for(FileHandle file : schematicDirectory.list()){
|
||||
loadFile(file);
|
||||
}
|
||||
|
||||
platform.getExternalSchematics().each(this::loadFile);
|
||||
|
||||
Core.app.post(() -> {
|
||||
shadowBuffer = new FrameBuffer(maxSchematicSize + padding, maxSchematicSize + padding);
|
||||
shadowBuffer = new FrameBuffer(maxSchematicSize + padding + 2, maxSchematicSize + padding + 2);
|
||||
});
|
||||
}
|
||||
|
||||
private void loadFile(FileHandle file){
|
||||
if(!file.extension().equals(schematicExtension)) return;
|
||||
|
||||
try{
|
||||
all.add(read(file));
|
||||
}catch(IOException e){
|
||||
Log.err(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Array<Schematic> all(){
|
||||
return all;
|
||||
}
|
||||
@@ -159,6 +166,13 @@ public class Schematics implements Loadable{
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Schematic s){
|
||||
all.remove(s);
|
||||
if(s.file != null){
|
||||
s.file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a schematic from a world selection. */
|
||||
public Schematic create(int x, int y, int x2, int y2){
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(x, y, x2, y2, 0, false, maxSchematicSize);
|
||||
|
||||
Reference in New Issue
Block a user