2020-08-07 16:11:02 -04:00
|
|
|
package mindustry.logic;
|
|
|
|
|
|
|
|
import arc.graphics.*;
|
|
|
|
import arc.scene.ui.*;
|
|
|
|
import arc.scene.ui.layout.*;
|
2020-08-07 23:01:40 -04:00
|
|
|
import mindustry.annotations.Annotations.*;
|
2020-08-07 16:11:02 -04:00
|
|
|
import mindustry.logic.LCanvas.*;
|
2020-08-08 14:14:33 -04:00
|
|
|
import mindustry.logic.LExecutor.*;
|
2020-08-07 16:11:02 -04:00
|
|
|
import mindustry.ui.*;
|
|
|
|
|
|
|
|
public class LStatements{
|
|
|
|
|
2020-08-08 14:14:33 -04:00
|
|
|
@RegisterStatement("write")
|
|
|
|
public static class WriteStatement extends LStatement{
|
|
|
|
public String to = "0";
|
|
|
|
public String from = "result";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, to, str -> to = str);
|
2020-08-08 14:14:33 -04:00
|
|
|
|
|
|
|
table.add(" = ");
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, from, str -> from = str);
|
2020-08-08 14:14:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.io;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LInstruction build(LAssembler builder){
|
|
|
|
return new WriteI(builder.var(from), builder.var(to));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RegisterStatement("read")
|
|
|
|
public static class ReadStatement extends LStatement{
|
|
|
|
public String to = "result";
|
|
|
|
public String from = "0";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, to, str -> to = str);
|
2020-08-08 14:14:33 -04:00
|
|
|
|
|
|
|
table.add(" = mem:: ");
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, from, str -> from = str);
|
2020-08-08 14:14:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.io;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LInstruction build(LAssembler builder){
|
|
|
|
return new ReadI(builder.var(from), builder.var(to));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RegisterStatement("sensor")
|
|
|
|
public static class SensorStatement extends LStatement{
|
|
|
|
public String to = "result";
|
|
|
|
public String from = "@0", type = "@copper";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, to, str -> to = str);
|
2020-08-08 14:14:33 -04:00
|
|
|
|
|
|
|
table.add(" = ");
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
table.row();
|
|
|
|
|
|
|
|
field(table, type, str -> type = str);
|
2020-08-08 14:14:33 -04:00
|
|
|
|
|
|
|
table.add(" in ");
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, from, str -> from = str);
|
2020-08-08 14:14:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.operations;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LInstruction build(LAssembler builder){
|
|
|
|
return new SenseI(builder.var(from), builder.var(to), builder.var(type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 23:01:40 -04:00
|
|
|
@RegisterStatement("set")
|
|
|
|
public static class SetStatement extends LStatement{
|
2020-08-07 16:11:02 -04:00
|
|
|
public String to = "result";
|
|
|
|
public String from = "0";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, to, str -> to = str);
|
2020-08-07 16:11:02 -04:00
|
|
|
|
|
|
|
table.add(" = ");
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, from, str -> from = str);
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.operations;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-07 17:50:54 -04:00
|
|
|
public LInstruction build(LAssembler builder){
|
2020-08-07 23:01:40 -04:00
|
|
|
return new SetI(builder.var(from), builder.var(to));
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 23:01:40 -04:00
|
|
|
@RegisterStatement("enable")
|
|
|
|
public static class EnableStatement extends LStatement{
|
2020-08-07 16:11:02 -04:00
|
|
|
public String target = "result";
|
|
|
|
public String value = "0";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, target, str -> target = str);
|
2020-08-07 16:11:02 -04:00
|
|
|
|
|
|
|
table.add(" -> ");
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, value, str -> value = str);
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.operations;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-07 23:01:40 -04:00
|
|
|
public LInstruction build(LAssembler builder){
|
|
|
|
return new EnableI(builder.var(target), builder.var(value));
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 23:01:40 -04:00
|
|
|
@RegisterStatement("op")
|
2020-08-07 16:11:02 -04:00
|
|
|
public static class OpStatement extends LStatement{
|
2020-08-07 17:50:54 -04:00
|
|
|
public BinaryOp op = BinaryOp.add;
|
2020-08-07 16:11:02 -04:00
|
|
|
public String a = "a", b = "b", dest = "result";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, dest, str -> dest = str);
|
2020-08-07 16:11:02 -04:00
|
|
|
|
|
|
|
table.add(" = ");
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
table.row();
|
2020-08-07 16:11:02 -04:00
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, a, str -> a = str);
|
2020-08-07 16:11:02 -04:00
|
|
|
|
|
|
|
TextButton[] button = {null};
|
|
|
|
button[0] = table.button(op.symbol, Styles.cleart, () -> {
|
2020-08-07 17:50:54 -04:00
|
|
|
op = BinaryOp.all[(op.ordinal() + 1) % BinaryOp.all.length];
|
2020-08-07 16:11:02 -04:00
|
|
|
button[0].setText(op.symbol);
|
|
|
|
}).size(50f, 30f).pad(4f).get();
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, b, str -> b = str);
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-07 17:50:54 -04:00
|
|
|
public LInstruction build(LAssembler builder){
|
2020-08-07 16:11:02 -04:00
|
|
|
return new BinaryOpI(op,builder.var(a), builder.var(b), builder.var(dest));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.operations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 23:01:40 -04:00
|
|
|
@RegisterStatement("end")
|
2020-08-07 16:11:02 -04:00
|
|
|
public static class EndStatement extends LStatement{
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-07 17:50:54 -04:00
|
|
|
public LInstruction build(LAssembler builder){
|
2020-08-07 16:11:02 -04:00
|
|
|
return new EndI();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.control;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 23:01:40 -04:00
|
|
|
@RegisterStatement("print")
|
2020-08-07 18:30:03 -04:00
|
|
|
public static class PrintStatement extends LStatement{
|
|
|
|
public String value = "\"frog\"";
|
2020-08-08 14:14:33 -04:00
|
|
|
public String target = "result";
|
2020-08-07 18:30:03 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, value, str -> value = str);
|
2020-08-08 14:14:33 -04:00
|
|
|
|
|
|
|
table.add(" to ");
|
|
|
|
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, target, str -> target = str);
|
2020-08-07 18:30:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LInstruction build(LAssembler builder){
|
2020-08-08 14:14:33 -04:00
|
|
|
return new PrintI(builder.var(value), builder.var(target));
|
2020-08-07 18:30:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.control;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 23:01:40 -04:00
|
|
|
@RegisterStatement("jump")
|
2020-08-07 16:11:02 -04:00
|
|
|
public static class JumpStatement extends LStatement{
|
2020-08-07 17:50:54 -04:00
|
|
|
public transient StatementElem dest;
|
2020-08-07 18:30:03 -04:00
|
|
|
|
2020-08-07 17:50:54 -04:00
|
|
|
public int destIndex;
|
|
|
|
public String condition = "true";
|
2020-08-07 16:11:02 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
|
|
|
table.add("if ").padLeft(6);
|
2020-08-08 18:01:54 -04:00
|
|
|
field(table, condition, str -> condition = str);
|
|
|
|
|
2020-08-07 16:11:02 -04:00
|
|
|
table.add().growX();
|
2020-08-07 17:50:54 -04:00
|
|
|
table.add(new JumpButton(Color.white, () -> dest, s -> dest = s)).size(30).right().padRight(-17);
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|
|
|
|
|
2020-08-07 17:50:54 -04:00
|
|
|
//elements need separate conversion logic
|
2020-08-07 16:11:02 -04:00
|
|
|
@Override
|
2020-08-07 18:30:03 -04:00
|
|
|
public void setupUI(){
|
|
|
|
if(elem != null){
|
|
|
|
dest = (StatementElem)elem.parent.getChildren().get(destIndex);
|
2020-08-07 17:50:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-07 18:30:03 -04:00
|
|
|
public void saveUI(){
|
|
|
|
if(elem != null){
|
|
|
|
destIndex = dest == null ? -1 : dest.parent.getChildren().indexOf(dest);
|
|
|
|
}
|
2020-08-07 17:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LInstruction build(LAssembler builder){
|
|
|
|
return new JumpI(builder.var(condition),destIndex);
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.control;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-08 14:14:33 -04:00
|
|
|
//disabled until further notice - bypasses the network
|
|
|
|
/*
|
2020-08-07 23:01:40 -04:00
|
|
|
@RegisterStatement("getbuild")
|
|
|
|
public static class getBuildStatement extends LStatement{
|
2020-08-07 16:11:02 -04:00
|
|
|
public String x = "0", y = "0", dest = "result";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build(Table table){
|
|
|
|
table.field(dest, Styles.nodeField, str -> dest = str)
|
|
|
|
.size(100f, 40f).pad(2f).color(table.color);
|
|
|
|
|
|
|
|
table.add(" = ");
|
|
|
|
|
|
|
|
table.field(x, Styles.nodeField, str -> x = str)
|
|
|
|
.size(90f, 40f).pad(2f).color(table.color);
|
|
|
|
|
|
|
|
table.add(", ");
|
|
|
|
|
|
|
|
table.field(y, Styles.nodeField, str -> y = str)
|
|
|
|
.size(90f, 40f).pad(2f).color(table.color);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-07 17:50:54 -04:00
|
|
|
public LInstruction build(LAssembler builder){
|
2020-08-07 23:01:40 -04:00
|
|
|
return new GetBuildI(builder.var(dest), builder.var(x), builder.var(y));
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LCategory category(){
|
|
|
|
return LCategory.blocks;
|
|
|
|
}
|
2020-08-08 14:14:33 -04:00
|
|
|
}*/
|
2020-08-07 16:11:02 -04:00
|
|
|
}
|