Graphics
@ -70,15 +70,22 @@ public class LogicStatementProcessor extends BaseProcessor{
|
||||
if(field.is(Modifier.TRANSIENT)) continue;
|
||||
|
||||
writer.addStatement("out.append(\" \")");
|
||||
writer.addStatement("out.append((($T)obj).$L)", c.mirror(), field.name());
|
||||
writer.addStatement("out.append((($T)obj).$L$L)", c.mirror(), field.name(),
|
||||
field.mirror().toString().equals("java.lang.String") ?
|
||||
".replace(\"\\n\", \"\\\\n\")" :
|
||||
Seq.with(typeu.directSupertypes(field.mirror())).contains(t -> t.toString().contains("java.lang.Enum")) ? ".name()" :
|
||||
"");
|
||||
|
||||
//reading primitives, strings and enums is supported; nothing else is
|
||||
reader.addStatement("result.$L = $L(tokens[$L])",
|
||||
reader.addStatement("result.$L = $L(tokens[$L])$L",
|
||||
field.name(),
|
||||
field.mirror().toString().equals("java.lang.String") ?
|
||||
"" : (field.tname().isPrimitive() ? field.tname().box().toString() :
|
||||
field.mirror().toString()) + ".valueOf", //if it's not a string, it must have a valueOf method
|
||||
index + 1
|
||||
index + 1,
|
||||
field.mirror().toString().equals("java.lang.String") ?
|
||||
".replace(\"\\\\n\", \"\\n\")" :
|
||||
""
|
||||
);
|
||||
|
||||
index ++;
|
||||
|
1
annotations/src/main/resources/revisions/Bullet/5.json
Normal file
@ -0,0 +1 @@
|
||||
{version:5,fields:[{name:collided,type:arc.struct.IntSeq,size:-1},{name:damage,type:float,size:4},{name:data,type:java.lang.Object,size:-1},{name:lifetime,type:float,size:4},{name:owner,type:Entityc,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:type,type:mindustry.entities.bullet.BulletType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
|
@ -0,0 +1 @@
|
||||
{version:5,fields:[{name:color,type:arc.graphics.Color,size:-1},{name:data,type:java.lang.Object,size:-1},{name:effect,type:mindustry.entities.Effect,size:-1},{name:lifetime,type:float,size:4},{name:offsetX,type:float,size:4},{name:offsetY,type:float,size:4},{name:parent,type:Posc,size:-1},{name:rotation,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
BIN
core/assets-raw/sprites/blocks/logic/logic-display.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 836 B After Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 411 B After Width: | Height: | Size: 411 B |
@ -282,3 +282,4 @@
|
||||
63462=overdrive-dome|block-overdrive-dome-medium
|
||||
63461=logic-processor|block-logic-processor-medium
|
||||
63460=micro-processor|block-micro-processor-medium
|
||||
63459=logic-display|block-logic-display-medium
|
||||
|
Before Width: | Height: | Size: 783 B After Width: | Height: | Size: 776 B |
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 186 KiB |
Before Width: | Height: | Size: 384 KiB After Width: | Height: | Size: 386 KiB |
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 1.8 MiB |
Before Width: | Height: | Size: 183 KiB After Width: | Height: | Size: 187 KiB |
Before Width: | Height: | Size: 398 KiB After Width: | Height: | Size: 391 KiB |
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
@ -82,7 +82,7 @@ public class Blocks implements ContentList{
|
||||
repairPoint, resupplyPoint,
|
||||
|
||||
//logic
|
||||
microProcessor, logicProcessor,
|
||||
microProcessor, logicProcessor, logicDisplay,
|
||||
|
||||
//campaign
|
||||
launchPad, launchPadLarge,
|
||||
@ -1909,6 +1909,14 @@ public class Blocks implements ContentList{
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
logicDisplay = new LogicDisplay("logic-display"){{
|
||||
requirements(Category.effect, with(Items.copper, 200, Items.lead, 120, Items.silicon, 100, Items.metaglass, 50));
|
||||
|
||||
displaySize = 64;
|
||||
|
||||
size = 3;
|
||||
}};
|
||||
|
||||
//endregion
|
||||
//region experimental
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class LAssembler{
|
||||
|
||||
Seq<LStatement> st = read(data);
|
||||
|
||||
asm.instructions = st.map(l -> l.build(asm)).toArray(LInstruction.class);
|
||||
asm.instructions = st.map(l -> l.build(asm)).filter(l -> l != null).toArray(LInstruction.class);
|
||||
return asm;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ public class LAssembler{
|
||||
String[] lines = data.split("[;\n]+");
|
||||
for(String line : lines){
|
||||
//comments
|
||||
if(line.startsWith("#")) continue;
|
||||
//if(line.startsWith("#")) continue;
|
||||
|
||||
String[] tokens = line.split(" ");
|
||||
LStatement st = LogicIO.read(tokens);
|
||||
|
@ -421,6 +421,7 @@ public class LCanvas extends Table{
|
||||
|
||||
void drawCurve(float x, float y, float x2, float y2, Color color){
|
||||
Lines.stroke(4f, color);
|
||||
Draw.alpha(parentAlpha);
|
||||
|
||||
float dist = 100f;
|
||||
|
||||
|
@ -1,10 +1,14 @@
|
||||
package mindustry.logic;
|
||||
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.blocks.logic.LogicDisplay.*;
|
||||
|
||||
import static mindustry.world.blocks.logic.LogicDisplay.*;
|
||||
|
||||
public class LExecutor{
|
||||
//special variables
|
||||
@ -15,6 +19,7 @@ public class LExecutor{
|
||||
public double[] memory = {};
|
||||
public LInstruction[] instructions = {};
|
||||
public Var[] vars = {};
|
||||
public LongSeq graphicsBuffer = new LongSeq();
|
||||
|
||||
public boolean initialized(){
|
||||
return instructions != null && vars != null && instructions.length > 0;
|
||||
@ -283,6 +288,48 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class DisplayI implements LInstruction{
|
||||
public byte type;
|
||||
public int target;
|
||||
public int x, y, p1, p2, p3;
|
||||
|
||||
public DisplayI(byte type, int target, int x, int y, int p1, int p2, int p3){
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.p1 = p1;
|
||||
this.p2 = p2;
|
||||
this.p3 = p3;
|
||||
}
|
||||
|
||||
public DisplayI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
//graphics on headless servers are useless.
|
||||
if(Vars.headless) return;
|
||||
|
||||
Building build = exec.building(target);
|
||||
if(build instanceof LogicDisplayEntity){
|
||||
//flush is a special command
|
||||
if(type == commandFlush){
|
||||
LogicDisplayEntity d = (LogicDisplayEntity)build;
|
||||
for(int i = 0; i < exec.graphicsBuffer.size; i++){
|
||||
d.commands.addLast(exec.graphicsBuffer.items[i]);
|
||||
}
|
||||
exec.graphicsBuffer.clear();
|
||||
}else{
|
||||
//cap graphics buffer size
|
||||
if(exec.graphicsBuffer.size < 1024){
|
||||
exec.graphicsBuffer.add(DisplayCmd.get(type, exec.numi(x), exec.numi(y), exec.numi(p1), exec.numi(p2), exec.numi(p3)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PrintI implements LInstruction{
|
||||
private static final StringBuilder out = new StringBuilder();
|
||||
|
||||
|
@ -24,28 +24,38 @@ public abstract class LStatement{
|
||||
public abstract LCategory category();
|
||||
public abstract LInstruction build(LAssembler builder);
|
||||
|
||||
//protected methods are only for internal UI layout utilities
|
||||
|
||||
protected Cell<TextField> field(Table table, String value, Cons<String> setter){
|
||||
return table.field(value, Styles.nodeField, setter)
|
||||
.size(144f, 40f).pad(2f).color(table.color).addInputDialog();
|
||||
}
|
||||
|
||||
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter){
|
||||
protected Cell<TextField> fields(Table table, String value, Cons<String> setter){
|
||||
return field(table, value, setter).width(70f);
|
||||
}
|
||||
|
||||
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter, int cols, Cons<Cell> sizer){
|
||||
showSelectTable(b, (t, hide) -> {
|
||||
ButtonGroup<Button> group = new ButtonGroup<>();
|
||||
int i = 0;
|
||||
t.defaults().size(56f, 40f);
|
||||
|
||||
for(T p : values){
|
||||
t.button(p.toString(), Styles.clearTogglet, () -> {
|
||||
sizer.get(t.button(p.toString(), Styles.clearTogglet, () -> {
|
||||
getter.get(p);
|
||||
hide.run();
|
||||
}).checked(current == p).group(group);
|
||||
}).checked(current == p).group(group));
|
||||
|
||||
if(++i % 4 == 0) t.row();
|
||||
if(++i % cols == 0) t.row();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter){
|
||||
showSelect(b, values, current, getter, 4, c -> {});
|
||||
}
|
||||
|
||||
protected void showSelectTable(Button b, Cons2<Table, Runnable> hideCons){
|
||||
Table t = new Table(Tex.button);
|
||||
|
||||
@ -64,6 +74,8 @@ public abstract class LStatement{
|
||||
Core.scene.add(t);
|
||||
|
||||
t.update(() -> {
|
||||
if(b.parent == null) return;
|
||||
|
||||
b.localToStageCoordinates(Tmp.v1.set(b.getWidth()/2f, b.getHeight()/2f));
|
||||
t.setPosition(Tmp.v1.x, Tmp.v1.y, Align.center);
|
||||
t.keepInStage();
|
||||
|
@ -12,8 +12,31 @@ import mindustry.logic.LExecutor.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
import static mindustry.world.blocks.logic.LogicDisplay.*;
|
||||
|
||||
public class LStatements{
|
||||
|
||||
//TODO broken
|
||||
//@RegisterStatement("#")
|
||||
public static class CommentStatement extends LStatement{
|
||||
public String comment = "";
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.area(comment, Styles.nodeArea, v -> comment = v).growX().height(90f).padLeft(2).padRight(6).color(table.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LCategory category(){
|
||||
return LCategory.control;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("write")
|
||||
public static class WriteStatement extends LStatement{
|
||||
public String to = "0";
|
||||
@ -64,6 +87,93 @@ public class LStatements{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RegisterStatement("display")
|
||||
public static class DisplayStatement extends LStatement{
|
||||
public CommandType type = CommandType.line;
|
||||
public String target = "monitor";
|
||||
public String x = "0", y = "0", p1 = "0", p2 = "0", p3 = "0";
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
rebuild(table);
|
||||
}
|
||||
|
||||
void rebuild(Table table){
|
||||
table.clearChildren();
|
||||
|
||||
table.add("draw").padLeft(4);
|
||||
|
||||
table.button(b -> {
|
||||
b.label(() -> type.name());
|
||||
b.clicked(() -> showSelect(b, CommandType.all, type, t -> {
|
||||
type = t;
|
||||
rebuild(table);
|
||||
}, 2, cell -> cell.size(100, 50)));
|
||||
}, Styles.cleari, () -> {}).size(90, 50);
|
||||
|
||||
table.add(" to ");
|
||||
|
||||
field(table, target, str -> target = str);
|
||||
|
||||
table.row();
|
||||
|
||||
table.table(c -> {
|
||||
c.marginLeft(3);
|
||||
c.left();
|
||||
c.setColor(table.color);
|
||||
switch(type){
|
||||
case clear:
|
||||
case color:
|
||||
c.add("rgb ");
|
||||
fields(c, x, v -> x = v);
|
||||
fields(c, y, v -> y = v);
|
||||
fields(c, p1, v -> p1 = v);
|
||||
break;
|
||||
case stroke:
|
||||
c.add("width ");
|
||||
fields(c, x, v -> x = v);
|
||||
break;
|
||||
case line:
|
||||
c.add("xyx2y2 ");
|
||||
fields(c, x, v -> x = v);
|
||||
fields(c, y, v -> y = v);
|
||||
fields(c, p1, v -> p1 = v);
|
||||
fields(c, p2, v -> p2 = v);
|
||||
break;
|
||||
case rect:
|
||||
case lineRect:
|
||||
c.add("xywh ");
|
||||
fields(c, x, v -> x = v);
|
||||
fields(c, y, v -> y = v);
|
||||
fields(c, p1, v -> p1 = v);
|
||||
fields(c, p2, v -> p2 = v);
|
||||
break;
|
||||
case poly:
|
||||
case linePoly:
|
||||
c.add("xysra ");
|
||||
fields(c, x, v -> x = v);
|
||||
fields(c, y, v -> y = v);
|
||||
c.row();
|
||||
fields(c, p1, v -> p1 = v);
|
||||
fields(c, p2, v -> p2 = v);
|
||||
fields(c, p3, v -> p3 = v);
|
||||
break;
|
||||
}
|
||||
}).colspan(4).left();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LCategory category(){
|
||||
return LCategory.io;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new DisplayI((byte)type.ordinal(), builder.var(target), builder.var(x), builder.var(y), builder.var(p1), builder.var(p2), builder.var(p3));
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("sensor")
|
||||
public static class SensorStatement extends LStatement{
|
||||
public String to = "result";
|
||||
@ -89,8 +199,10 @@ public class LStatements{
|
||||
Table[] tables = {
|
||||
//items
|
||||
new Table(i -> {
|
||||
i.left();
|
||||
int c = 0;
|
||||
for(Item item : Vars.content.items()){
|
||||
if(!item.unlockedNow()) continue;
|
||||
i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> {
|
||||
stype("@" + item.name);
|
||||
hide.run();
|
||||
@ -101,8 +213,10 @@ public class LStatements{
|
||||
}),
|
||||
//liquids
|
||||
new Table(i -> {
|
||||
i.left();
|
||||
int c = 0;
|
||||
for(Liquid item : Vars.content.liquids()){
|
||||
if(!item.unlockedNow()) continue;
|
||||
i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> {
|
||||
stype("@" + item.name);
|
||||
hide.run();
|
||||
@ -138,7 +252,7 @@ public class LStatements{
|
||||
}).size(80f, 50f).checked(selected == fi).group(group);
|
||||
}
|
||||
t.row();
|
||||
t.add(stack).colspan(3);
|
||||
t.add(stack).colspan(3).expand().left();
|
||||
}));
|
||||
}, Styles.cleart, () -> {}).size(40f).padLeft(-1);
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class Styles{
|
||||
public static KeybindDialogStyle defaultKeybindDialog;
|
||||
public static SliderStyle defaultSlider, vSlider;
|
||||
public static LabelStyle defaultLabel, outlineLabel, techLabel;
|
||||
public static TextFieldStyle defaultField, nodeField, areaField;
|
||||
public static TextFieldStyle defaultField, nodeField, areaField, nodeArea;
|
||||
public static CheckBoxStyle defaultCheck;
|
||||
public static DialogStyle defaultDialog, fullDialog;
|
||||
|
||||
@ -331,6 +331,17 @@ public class Styles{
|
||||
messageFontColor = Color.gray;
|
||||
}};
|
||||
|
||||
nodeArea = new TextFieldStyle(){{
|
||||
font = Fonts.chat;
|
||||
fontColor = Color.white;
|
||||
disabledFontColor = Color.gray;
|
||||
selection = Tex.selection;
|
||||
background = underlineWhite;
|
||||
cursor = Tex.cursor;
|
||||
messageFont = Fonts.def;
|
||||
messageFontColor = Color.gray;
|
||||
}};
|
||||
|
||||
defaultCheck = new CheckBoxStyle(){{
|
||||
checkboxOn = checkOn;
|
||||
checkboxOff = checkOff;
|
||||
|
112
core/src/mindustry/world/blocks/logic/LogicDisplay.java
Normal file
@ -0,0 +1,112 @@
|
||||
package mindustry.world.blocks.logic;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class LogicDisplay extends Block{
|
||||
public static final byte
|
||||
commandClear = 0,
|
||||
commandColor = 1,
|
||||
commandStroke = 2,
|
||||
commandLine = 3,
|
||||
commandRect = 4,
|
||||
commandLineRect = 5,
|
||||
commandPoly = 6,
|
||||
commandLinePoly = 7,
|
||||
commandFlush = 8;
|
||||
|
||||
public int displaySize = 64;
|
||||
|
||||
public LogicDisplay(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
}
|
||||
|
||||
public class LogicDisplayEntity extends Building{
|
||||
public FrameBuffer buffer;
|
||||
public float color = Color.whiteFloatBits;
|
||||
public float stroke = 1f;
|
||||
public LongQueue commands = new LongQueue();
|
||||
|
||||
public LogicDisplayEntity(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
if(buffer == null){
|
||||
buffer = new FrameBuffer(displaySize, displaySize);
|
||||
}
|
||||
|
||||
if(!commands.isEmpty()){
|
||||
Draw.draw(Draw.z(), () -> {
|
||||
Tmp.m1.set(Draw.proj());
|
||||
Draw.proj(0, 0, displaySize, displaySize);
|
||||
buffer.begin();
|
||||
Draw.color(color);
|
||||
Lines.stroke(stroke);
|
||||
Lines.precise(true);
|
||||
|
||||
while(!commands.isEmpty()){
|
||||
long c = commands.removeFirst();
|
||||
byte type = DisplayCmd.type(c);
|
||||
int x = DisplayCmd.x(c), y = DisplayCmd.y(c),
|
||||
p1 = DisplayCmd.p1(c), p2 = DisplayCmd.p2(c), p3 = DisplayCmd.p3(c);
|
||||
|
||||
switch(type){
|
||||
case commandClear: Core.graphics.clear(x/255f, y/255f, p1/255f, 1f); break;
|
||||
case commandLine: Lines.line(x, y, p1, p2); break;
|
||||
case commandRect: Fill.crect(x, y, p1, p2); break;
|
||||
case commandLineRect: Lines.rect(x, y, p1, p2); break;
|
||||
case commandPoly: Fill.poly(x, y, p1, p2, p3); break;
|
||||
case commandLinePoly: Lines.poly(x, y, p1, p2, p3); break;
|
||||
case commandColor: this.color = Color.toFloatBits(x, y, p1, 255); Draw.color(this.color); break;
|
||||
case commandStroke: this.stroke = x; Lines.stroke(x); break;
|
||||
}
|
||||
}
|
||||
|
||||
Lines.precise(false);
|
||||
|
||||
buffer.end();
|
||||
Draw.proj(Tmp.m1);
|
||||
Draw.reset();
|
||||
});
|
||||
}
|
||||
|
||||
Draw.rect(Draw.wrap(buffer.getTexture()), x, y, buffer.getWidth() * Draw.scl, -buffer.getHeight() * Draw.scl);
|
||||
}
|
||||
}
|
||||
|
||||
public enum CommandType{
|
||||
clear,
|
||||
color,
|
||||
stroke,
|
||||
line,
|
||||
rect,
|
||||
lineRect,
|
||||
poly,
|
||||
linePoly,
|
||||
flush;
|
||||
|
||||
public static final CommandType[] all = values();
|
||||
}
|
||||
|
||||
@Struct
|
||||
static class DisplayCmdStruct{
|
||||
public byte type;
|
||||
|
||||
//each coordinate is only 8 bits, limiting size to 256x256
|
||||
//anything larger than that would be excessive anyway
|
||||
@StructField(9)
|
||||
public int x, y, p1, p2, p3;
|
||||
}
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=cbfa2828a465909e9bb74e3dde211a3f59ffbbb1
|
||||
archash=db8aa62298fc1500ede3a09776f1414be9b6ba30
|
||||
|