Sensor types
This commit is contained in:
@@ -12,14 +12,14 @@ import mindustry.type.*;
|
||||
public class LAssembler{
|
||||
public static ObjectMap<String, Func<String[], LStatement>> customParsers = new ObjectMap<>();
|
||||
|
||||
private transient int lastVar;
|
||||
private int lastVar;
|
||||
/** Maps names to variable IDs. */
|
||||
ObjectMap<String, BVar> vars = new ObjectMap<>();
|
||||
/** All instructions to be executed. */
|
||||
LInstruction[] instructions;
|
||||
|
||||
public LAssembler(){
|
||||
putVar("@counter");
|
||||
putVar("@counter").value = 0;
|
||||
putConst("@time", 0);
|
||||
|
||||
//add default constants
|
||||
@@ -36,6 +36,12 @@ public class LAssembler{
|
||||
for(Liquid liquid : Vars.content.liquids()){
|
||||
putConst("@" + liquid.name, liquid);
|
||||
}
|
||||
|
||||
//store sensor constants
|
||||
|
||||
for(LSensor sensor : LSensor.all){
|
||||
putConst("@" + sensor.name(), sensor);
|
||||
}
|
||||
}
|
||||
|
||||
public static LAssembler assemble(String data){
|
||||
|
||||
@@ -3,8 +3,8 @@ package mindustry.logic;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
public class LExecutor{
|
||||
//special variables
|
||||
@@ -192,16 +192,16 @@ public class LExecutor{
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
Building build = exec.building(from);
|
||||
Object target = exec.obj(from);
|
||||
Object sense = exec.obj(type);
|
||||
|
||||
double output = 0;
|
||||
|
||||
if(build != null){
|
||||
if(sense instanceof Item && build.items != null){
|
||||
output = build.items.get((Item)sense);
|
||||
}else if(sense instanceof Liquid && build.liquids != null){
|
||||
output = build.liquids.get((Liquid)sense);
|
||||
if(target instanceof Senseable){
|
||||
if(sense instanceof Content){
|
||||
output = ((Senseable)target).sense(((Content)sense));
|
||||
}else if(sense instanceof LSensor){
|
||||
output = ((Senseable)target).sense(((LSensor)sense));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ public class LExecutor{
|
||||
|
||||
//this should avoid any garbage allocation
|
||||
Var v = exec.vars[value];
|
||||
if(v.isobj){
|
||||
if(v.isobj && value != 0){
|
||||
if(v.objval instanceof String){
|
||||
b.handleString(v.objval);
|
||||
}else if(v.objval == null){
|
||||
|
||||
15
core/src/mindustry/logic/LSensor.java
Normal file
15
core/src/mindustry/logic/LSensor.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package mindustry.logic;
|
||||
|
||||
public enum LSensor{
|
||||
totalItems,
|
||||
totalLiquids,
|
||||
totalPower,
|
||||
powerNetStored,
|
||||
powerNetIn,
|
||||
powerNetOut,
|
||||
health,
|
||||
heat,
|
||||
efficiency;
|
||||
|
||||
public static final LSensor[] all = values();
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package mindustry.logic;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.logic.LCanvas.*;
|
||||
import mindustry.logic.LExecutor.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
/**
|
||||
* A statement is an intermediate representation of an instruction, to be used mostly in UI.
|
||||
@@ -16,6 +18,11 @@ public abstract class LStatement{
|
||||
public abstract LCategory category();
|
||||
public abstract LInstruction build(LAssembler builder);
|
||||
|
||||
protected void field(Table table, String value, Cons<String> setter){
|
||||
table.field(value, Styles.nodeField, setter)
|
||||
.size(130f, 40f).pad(2f).color(table.color);
|
||||
}
|
||||
|
||||
public void write(StringBuilder builder){
|
||||
LogicIO.write(this,builder);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package mindustry.logic;
|
||||
import arc.graphics.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.logic.LCanvas.*;
|
||||
import mindustry.logic.LExecutor.*;
|
||||
@@ -18,15 +17,11 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
Log.info("mem:: ");
|
||||
|
||||
table.field(to, Styles.nodeField, str -> to = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, to, str -> to = str);
|
||||
|
||||
table.add(" = ");
|
||||
|
||||
table.field(from, Styles.nodeField, str -> from = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, from, str -> from = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,13 +42,11 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.field(to, Styles.nodeField, str -> to = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, to, str -> to = str);
|
||||
|
||||
table.add(" = mem:: ");
|
||||
|
||||
table.field(from, Styles.nodeField, str -> from = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, from, str -> from = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,18 +67,17 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.field(to, Styles.nodeField, str -> to = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, to, str -> to = str);
|
||||
|
||||
table.add(" = ");
|
||||
|
||||
table.field(type, Styles.nodeField, str -> type = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
table.row();
|
||||
|
||||
field(table, type, str -> type = str);
|
||||
|
||||
table.add(" in ");
|
||||
|
||||
table.field(from, Styles.nodeField, str -> from = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, from, str -> from = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,13 +98,11 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.field(to, Styles.nodeField, str -> to = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, to, str -> to = str);
|
||||
|
||||
table.add(" = ");
|
||||
|
||||
table.field(from, Styles.nodeField, str -> from = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, from, str -> from = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,13 +123,11 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.field(target, Styles.nodeField, str -> target = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, target, str -> target = str);
|
||||
|
||||
table.add(" -> ");
|
||||
|
||||
table.field(value, Styles.nodeField, str -> value = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, value, str -> value = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,14 +148,13 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.field(dest, Styles.nodeField, str -> dest = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, dest, str -> dest = str);
|
||||
|
||||
table.add(" = ");
|
||||
|
||||
table.field(a, Styles.nodeField, str -> a = str)
|
||||
.size(90f, 40f).pad(2f).color(table.color);
|
||||
table.row();
|
||||
|
||||
field(table, a, str -> a = str);
|
||||
|
||||
TextButton[] button = {null};
|
||||
button[0] = table.button(op.symbol, Styles.cleart, () -> {
|
||||
@@ -175,8 +162,7 @@ public class LStatements{
|
||||
button[0].setText(op.symbol);
|
||||
}).size(50f, 30f).pad(4f).get();
|
||||
|
||||
table.field(b, Styles.nodeField, str -> b = str)
|
||||
.size(90f, 40f).pad(2f).color(table.color);
|
||||
field(table, b, str -> b = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -215,13 +201,11 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.field(value, Styles.nodeField, str -> value = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, value, str -> value = str);
|
||||
|
||||
table.add(" to ");
|
||||
|
||||
table.field(target, Styles.nodeField, str -> target = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, target, str -> target = str);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,8 +229,8 @@ public class LStatements{
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.add("if ").padLeft(6);
|
||||
table.field(condition, Styles.nodeField, str -> condition = str)
|
||||
.size(100f, 40f).pad(2f).color(table.color);
|
||||
field(table, condition, str -> condition = str);
|
||||
|
||||
table.add().growX();
|
||||
table.add(new JumpButton(Color.white, () -> dest, s -> dest = s)).size(30).right().padRight(-17);
|
||||
}
|
||||
|
||||
8
core/src/mindustry/logic/Senseable.java
Normal file
8
core/src/mindustry/logic/Senseable.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package mindustry.logic;
|
||||
|
||||
import mindustry.ctype.*;
|
||||
|
||||
public interface Senseable{
|
||||
double sense(LSensor sensor);
|
||||
double sense(Content content);
|
||||
}
|
||||
Reference in New Issue
Block a user