This commit is contained in:
Anuken
2020-08-11 12:48:17 -04:00
parent d85f6c72eb
commit 188171ec03
10 changed files with 36 additions and 19 deletions

View File

@@ -45,10 +45,10 @@ public class LAssembler{
}
}
public static LAssembler assemble(String data){
public static LAssembler assemble(String data, int maxInstructions){
LAssembler asm = new LAssembler();
Seq<LStatement> st = read(data);
Seq<LStatement> st = read(data, maxInstructions);
asm.instructions = st.map(l -> l.build(asm)).filter(l -> l != null).toArray(LInstruction.class);
return asm;
@@ -65,15 +65,22 @@ public class LAssembler{
}
public static Seq<LStatement> read(String data){
return read(data, Integer.MAX_VALUE);
}
public static Seq<LStatement> read(String data, int max){
//empty data check
if(data == null || data.isEmpty()) return new Seq<>();
Seq<LStatement> statements = new Seq<>();
String[] lines = data.split("[;\n]+");
int index = 0;
for(String line : lines){
//comments
if(line.startsWith("#")) continue;
if(index++ > max) continue;
try{
//yes, I am aware that this can be split with regex, but that's slow and even more incomprehensible
Seq<String> tokens = new Seq<>();

View File

@@ -19,6 +19,7 @@ import mindustry.graphics.*;
import mindustry.logic.LStatements.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import mindustry.world.blocks.logic.*;
public class LCanvas extends Table{
private static final Color backgroundCol = Pal.darkMetal.cpy().mul(0.1f), gridCol = Pal.darkMetal.cpy().mul(0.5f);
@@ -56,7 +57,7 @@ public class LCanvas extends Table{
});
dialog.addCloseButton();
dialog.show();
}).height(50f).left().width(400f).marginLeft(10f);
}).height(50f).left().width(400f).marginLeft(10f).disabled(t -> statements.getChildren().size >= LogicBlock.maxInstructions);
}
private void drawGrid(){

View File

@@ -47,8 +47,8 @@ public class LExecutor{
}
}
public void load(String data){
load(LAssembler.assemble(data));
public void load(String data, int maxInstructions){
load(LAssembler.assemble(data, maxInstructions));
}
/** Loads with a specified assembler. Resets all variables. */

View File

@@ -95,7 +95,10 @@ public abstract class LStatement{
});
t.actions(Actions.alpha(0), Actions.fadeIn(0.3f, Interp.fade));
hideCons.get(t, hide);
t.top().pane(inner -> {
inner.top();
hideCons.get(inner, hide);
}).top();
t.pack();
}

View File

@@ -450,10 +450,10 @@ public class LStatements{
stack.clearChildren();
stack.addChild(tables[selected]);
t.pack();
}).size(80f, 50f).checked(selected == fi).group(group);
}).size(80f, 50f).growX().checked(selected == fi).group(group);
}
t.row();
t.add(stack).colspan(3).expand().left();
t.add(stack).colspan(3).width(240f).left();
}));
}, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color);
@@ -614,7 +614,7 @@ public class LStatements{
//elements need separate conversion logic
@Override
public void setupUI(){
if(elem != null && destIndex > 0 && destIndex < elem.parent.getChildren().size){
if(elem != null && destIndex >= 0 && destIndex < elem.parent.getChildren().size){
dest = (StatementElem)elem.parent.getChildren().get(destIndex);
}
}