Marker instruction rework
This commit is contained in:
@@ -27,7 +27,7 @@ public class GlobalVars{
|
||||
public static final Rand rand = new Rand();
|
||||
|
||||
//non-constants that depend on state
|
||||
private static int varTime, varTick, varSecond, varMinute, varWave, varWaveTime, varServer;
|
||||
private static int varTime, varTick, varSecond, varMinute, varWave, varWaveTime, varServer, varClient;
|
||||
|
||||
private ObjectIntMap<String> namesToIds = new ObjectIntMap<>();
|
||||
private Seq<Var> vars = new Seq<>(Var.class);
|
||||
@@ -57,6 +57,7 @@ public class GlobalVars{
|
||||
varWaveTime = put("@waveTime", 0);
|
||||
|
||||
varServer = put("@server", 0);
|
||||
varClient = put("@server", 0);
|
||||
|
||||
//special enums
|
||||
put("@ctrlProcessor", ctrlProcessor);
|
||||
@@ -152,6 +153,7 @@ public class GlobalVars{
|
||||
|
||||
//network
|
||||
vars.items[varServer].numval = (net.server() || !net.active()) ? 1 : 0;
|
||||
vars.items[varServer].numval = net.client() ? 1 : 0;
|
||||
}
|
||||
|
||||
/** @return a piece of content based on its logic ID. This is not equivalent to content ID. */
|
||||
|
||||
@@ -1842,11 +1842,11 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class MarkerI implements LInstruction{
|
||||
public LMarkerControl type = LMarkerControl.create;
|
||||
public static class SetMarkerI implements LInstruction{
|
||||
public LMarkerControl type = LMarkerControl.x;
|
||||
public int id, p1, p2, p3;
|
||||
|
||||
public MarkerI(LMarkerControl type, int id, int p1, int p2, int p3){
|
||||
public SetMarkerI(LMarkerControl type, int id, int p1, int p2, int p3){
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.p1 = p1;
|
||||
@@ -1854,50 +1854,82 @@ public class LExecutor{
|
||||
this.p3 = p3;
|
||||
}
|
||||
|
||||
public MarkerI(){
|
||||
public SetMarkerI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
ObjectiveMarker marker = null;
|
||||
|
||||
if(type == LMarkerControl.create){
|
||||
int type = exec.numi(p1);
|
||||
if(0 <= type && type < MapObjectives.allMarkerTypes.size){
|
||||
marker = MapObjectives.allMarkerTypes.get(type).get();
|
||||
if(marker != null){
|
||||
state.rules.markers.put(exec.numi(id), marker);
|
||||
marker.control(LMarkerControl.pos, exec.num(p2), exec.num(p3), 0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}else if(type == LMarkerControl.remove){
|
||||
state.rules.markers.remove(exec.numi(id));
|
||||
if(type == LMarkerControl.remove){
|
||||
state.markers.remove(exec.numi(id));
|
||||
}else{
|
||||
marker = state.rules.markers.get(exec.numi(id));
|
||||
}
|
||||
if(!state.markers.containsKey(exec.numi(id))) return;
|
||||
|
||||
if(marker == null) return;
|
||||
|
||||
Var var = exec.var(p1);
|
||||
if(!var.isobj){
|
||||
marker.control(type, exec.num(p1), exec.num(p2), exec.num(p3));
|
||||
}else{
|
||||
if(type == LMarkerControl.text){
|
||||
marker.setText((exec.obj(p1) != null ? exec.obj(p1).toString() : "null"), true);
|
||||
Call.updateMarkerText(exec.numi(id), type, (exec.obj(p1) != null ? exec.obj(p1).toString() : "null"));
|
||||
}else if(type == LMarkerControl.flushText){
|
||||
marker.setText(exec.textBuffer.toString(), false);
|
||||
Call.updateMarkerText(exec.numi(id), type, exec.textBuffer.toString());
|
||||
exec.textBuffer.setLength(0);
|
||||
}else{
|
||||
Call.updateMarker(exec.numi(id), type, exec.num(p1), exec.num(p2), exec.num(p3));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Call.setMarker(exec.numi(id), marker);
|
||||
public static class MakeMarkerI implements LInstruction{
|
||||
//TODO arbitrary number
|
||||
public static final int maxMarkers = 20000;
|
||||
|
||||
public String type = "shape";
|
||||
public int id, x, y;
|
||||
|
||||
public MakeMarkerI(String type, int id, int x, int y){
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public MakeMarkerI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
var cons = MapObjectives.markerNameToType.get(type);
|
||||
|
||||
if(cons != null && !net.client() && state.markers.size < maxMarkers){
|
||||
//TODO max markers...
|
||||
var marker = cons.get();
|
||||
marker.control(LMarkerControl.pos, exec.num(x), exec.num(y), 0);
|
||||
|
||||
Call.createMarker(exec.numi(id), marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, variants = Variant.both, unreliable = true)
|
||||
public static void setMarker(int id, ObjectiveMarker marker){
|
||||
state.rules.markers.put(id, marker);
|
||||
public static void createMarker(int id, ObjectiveMarker marker){
|
||||
state.markers.put(id, marker);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, variants = Variant.both, unreliable = true)
|
||||
public static void updateMarker(int id, LMarkerControl control, double p1, double p2, double p3){
|
||||
var marker = state.markers.get(id);
|
||||
if(marker != null){
|
||||
marker.control(control, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, variants = Variant.both, unreliable = true)
|
||||
public static void updateMarkerText(int id, LMarkerControl type, String text){
|
||||
var marker = state.markers.get(id);
|
||||
if(marker != null){
|
||||
if(type == LMarkerControl.text){
|
||||
marker.setText(text, true);
|
||||
}else if(type == LMarkerControl.flushText){
|
||||
marker.setText(text, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mindustry.logic;
|
||||
|
||||
public enum LMarkerControl{
|
||||
create("type", "x", "y"),
|
||||
remove,
|
||||
setVisibility("true/false"),
|
||||
toggleVisibility,
|
||||
|
||||
@@ -108,6 +108,18 @@ public abstract class LStatement{
|
||||
return field(table, value, setter).width(85f).padRight(10).left();
|
||||
}
|
||||
|
||||
/** Puts the text and field in one table, taking up one cell. */
|
||||
protected Cell<TextField> fieldst(Table table, String desc, String value, Cons<String> setter){
|
||||
Cell[] result = {null};
|
||||
table.table(t -> {
|
||||
t.setColor(table.color);
|
||||
t.add(desc).padLeft(10).left().self(this::param);
|
||||
result[0] = field(t, value, setter).width(85f).padRight(10).left();
|
||||
});
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
protected Cell<TextField> fields(Table table, String value, Cons<String> setter){
|
||||
return field(table, value, setter).width(85f);
|
||||
}
|
||||
|
||||
@@ -1921,9 +1921,9 @@ public class LStatements{
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("marker")
|
||||
public static class MarkerStatement extends LStatement{
|
||||
public LMarkerControl type = LMarkerControl.create;
|
||||
@RegisterStatement("setmarker")
|
||||
public static class SetMarkerStatement extends LStatement{
|
||||
public LMarkerControl type = LMarkerControl.x;
|
||||
public String id = "0", p1 = "0", p2 = "0", p3 = "0";
|
||||
|
||||
@Override
|
||||
@@ -1934,6 +1934,8 @@ public class LStatements{
|
||||
void rebuild(Table table){
|
||||
table.clearChildren();
|
||||
|
||||
table.add("set");
|
||||
|
||||
table.button(b -> {
|
||||
b.label(() -> type.name());
|
||||
b.clicked(() -> showSelect(b, LMarkerControl.all, type, t -> {
|
||||
@@ -1942,48 +1944,23 @@ public class LStatements{
|
||||
}, 2, cell -> cell.size(140, 50)));
|
||||
}, Styles.logict, () -> {}).size(190, 40).color(table.color).left().padLeft(2);
|
||||
|
||||
table.add(" marker# ");
|
||||
row(table);
|
||||
|
||||
fields(table, id, str -> id = str);
|
||||
fieldst(table, "of id#", id, str -> id = str);
|
||||
|
||||
if(type == LMarkerControl.create){
|
||||
fields(table, type.params[0], p1, v -> p1 = v).padRight(0f).left();
|
||||
table.button(b -> {
|
||||
b.image(Icon.pencilSmall);
|
||||
b.clicked(() -> showSelectTable(b, (t, hide) -> {
|
||||
t.row();
|
||||
t.table(i -> {
|
||||
i.left();
|
||||
int c = 0;
|
||||
for(var gen : MapObjectives.allMarkerTypes){
|
||||
var marker = gen.get();
|
||||
i.button(marker.typeName(), Styles.flatt, () -> {
|
||||
p1 = Integer.toString(MapObjectives.allMarkerTypes.indexOf(gen));
|
||||
rebuild(table);
|
||||
hide.run();
|
||||
}).size(140, 40);
|
||||
//Q: why don't you just use arrays for this?
|
||||
//A: arrays aren't as easy to serialize so the code generator doesn't handle them
|
||||
for(int f = 0; f < type.params.length; f++){
|
||||
int i = f;
|
||||
|
||||
if(++c % 2 == 0) i.row();
|
||||
}
|
||||
}).colspan(3).width(280f).left();
|
||||
}));
|
||||
}, Styles.logict, () -> {}).size(40f).padLeft(-2).color(table.color);
|
||||
fields(table, type.params[1], p2, v -> p2 = v);
|
||||
fields(table, type.params[2], p3, v -> p3 = v);
|
||||
}else{
|
||||
//Q: why don't you just use arrays for this?
|
||||
//A: arrays aren't as easy to serialize so the code generator doesn't handle them
|
||||
int c = 0;
|
||||
for(int i = 0; i < type.params.length; i++){
|
||||
table.table(t -> {
|
||||
t.setColor(table.color);
|
||||
|
||||
fields(table, type.params[i], i == 0 ? p1 : i == 1 ? p2 : p3, i == 0 ? v -> p1 = v : i == 1 ? v -> p2 = v : v -> p3 = v).width(100f);
|
||||
fields(t, type.params[i], i == 0 ? p1 : i == 1 ? p2 : p3, i == 0 ? v -> p1 = v : i == 1 ? v -> p2 = v : v -> p3 = v).width(100f);
|
||||
});
|
||||
|
||||
if(++c % 2 == 0) row(table);
|
||||
|
||||
if(i == 3){
|
||||
table.row();
|
||||
}
|
||||
}
|
||||
if(i == 0) row(table);
|
||||
if(i == 2) table.row();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1994,7 +1971,49 @@ public class LStatements{
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new MarkerI(type, builder.var(id), builder.var(p1), builder.var(p2), builder.var(p3));
|
||||
return new SetMarkerI(type, builder.var(id), builder.var(p1), builder.var(p2), builder.var(p3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LCategory category(){
|
||||
return LCategory.world;
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("makemarker")
|
||||
public static class MakeMarkerStatement extends LStatement{
|
||||
public String id = "0", type = "Shape", x = "0", y = "0";
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.clearChildren();
|
||||
|
||||
table.button(b -> {
|
||||
b.label(() -> type);
|
||||
|
||||
b.clicked(() -> showSelect(b, MapObjectives.allMarkerTypeNanes.toArray(String.class), type, t -> {
|
||||
type = t;
|
||||
build(table);
|
||||
}, 2, cell -> cell.size(160, 50)));
|
||||
}, Styles.logict, () -> {}).size(190, 40).color(table.color).left().padLeft(2);
|
||||
|
||||
fieldst(table, "id", id, str -> id = str);
|
||||
|
||||
row(table);
|
||||
|
||||
fieldst(table, "x", x, v -> x = v);
|
||||
|
||||
fieldst(table, "y", y, v -> y = v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean privileged(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new MakeMarkerI(type, builder.var(id), builder.var(x), builder.var(y));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user