Basic setProp implementation

This commit is contained in:
Anuken
2023-03-09 05:25:35 -05:00
parent a857eaed74
commit bae3884d96
9 changed files with 264 additions and 8 deletions
+2 -1
View File
@@ -59,7 +59,8 @@ public enum LAccess{
public static final LAccess[]
all = values(),
senseable = Seq.select(all, t -> t.params.length <= 1).toArray(LAccess.class),
controls = Seq.select(all, t -> t.params.length > 0).toArray(LAccess.class);
controls = Seq.select(all, t -> t.params.length > 0).toArray(LAccess.class),
settable = {x, y, rotation, team, flag, health, totalPower, payloadType}; //TODO
LAccess(String... params){
this.params = params;
+32
View File
@@ -1695,5 +1695,37 @@ public class LExecutor{
}
}
public static class SetPropI implements LInstruction{
public int type, of, value;
public SetPropI(int type, int of, int value){
this.type = type;
this.of = of;
this.value = value;
}
public SetPropI(){
}
@Override
public void run(LExecutor exec){
Object target = exec.obj(of);
Object key = exec.obj(type);
if(target instanceof Settable sp){
if(key instanceof LAccess property){
Var var = exec.var(value);
if(var.isobj){
sp.setProp(property, var.objval);
}else{
sp.setProp(property, var.numval);
}
}else if(key instanceof UnlockableContent content){
sp.setProp(content, exec.num(value));
}
}
}
}
//endregion
}
+109
View File
@@ -1683,4 +1683,113 @@ public class LStatements{
return LCategory.world;
}
}
@RegisterStatement("setprop")
public static class SetPropStatement extends LStatement{
public String type = "@copper", of = "block1", value = "0";
private transient int selected = 0;
private transient TextField tfield;
@Override
public void build(Table table){
table.add(" set ");
tfield = field(table, type, str -> type = str).padRight(0f).get();
table.button(b -> {
b.image(Icon.pencilSmall);
//240
b.clicked(() -> showSelectTable(b, (t, hide) -> {
Table[] tables = {
//items
new Table(i -> {
i.left();
int c = 0;
for(Item item : Vars.content.items()){
if(item.hidden) continue;
i.button(new TextureRegionDrawable(item.uiIcon), Styles.flati, iconSmall, () -> {
stype("@" + item.name);
hide.run();
}).size(40f);
if(++c % 6 == 0) i.row();
}
}),
//liquids
new Table(i -> {
i.left();
int c = 0;
for(Liquid item : Vars.content.liquids()){
if(!item.unlockedNow() || item.hidden) continue;
i.button(new TextureRegionDrawable(item.uiIcon), Styles.flati, iconSmall, () -> {
stype("@" + item.name);
hide.run();
}).size(40f);
if(++c % 6 == 0) i.row();
}
}),
//sensors
new Table(i -> {
for(LAccess property : LAccess.settable){
i.button(property.name(), Styles.flatt, () -> {
stype("@" + property.name());
hide.run();
}).size(240f, 40f).self(c -> tooltip(c, property)).row();
}
})
};
Drawable[] icons = {Icon.box, Icon.liquid, Icon.tree};
Stack stack = new Stack(tables[selected]);
ButtonGroup<Button> group = new ButtonGroup<>();
for(int i = 0; i < tables.length; i++){
int fi = i;
t.button(icons[i], Styles.squareTogglei, () -> {
selected = fi;
stack.clearChildren();
stack.addChild(tables[selected]);
t.parent.parent.pack();
t.parent.parent.invalidateHierarchy();
}).height(50f).growX().checked(selected == fi).group(group);
}
t.row();
t.add(stack).colspan(3).width(240f).left();
}));
}, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color);
table.add(" of ").self(this::param);
field(table, of, str -> of = str);
table.add(" to ");
field(table, value, str -> value = str);
}
private void stype(String text){
tfield.setText(text);
this.type = text;
}
@Override
public boolean privileged(){
return true;
}
@Override
public LInstruction build(LAssembler builder){
return new SetPropI(builder.var(type), builder.var(of), builder.var(value));
}
@Override
public LCategory category(){
return LCategory.world;
}
}
}
+3 -4
View File
@@ -2,9 +2,8 @@ package mindustry.logic;
import mindustry.ctype.*;
//TODO
public interface Settable{
void setProperty(LAccess prop, double value);
void setProperty(LAccess prop, Object value);
void setProperty(UnlockableContent content, double value);
void setProp(LAccess prop, double value);
void setProp(LAccess prop, Object value);
void setProp(UnlockableContent content, double value);
}