Make setmarker ignor null values, remove redundant marker control operations
This commit is contained in:
@@ -2303,7 +2303,7 @@ lst.setprop = Sets a property of a unit or building.
|
||||
lst.effect = Create a particle effect.
|
||||
lst.sync = Sync a variable across the network.\nLimited to 20 times a second per variable.
|
||||
lst.makemarker = Create a new logic marker in the world.\nAn ID to identify this marker must be provided.\nMarkers currently limited to 20,000 per world.
|
||||
lst.setmarker = Set a property for a marker.\nThe ID used must be the same as in the Make Marker instruction.
|
||||
lst.setmarker = Set a property for a marker.\nThe ID used must be the same as in the Make Marker instruction.\n[accent]null []values are being ignored instead of converting to 0.
|
||||
|
||||
logic.nounitbuild = [red]Unit building logic is not allowed here.
|
||||
|
||||
@@ -2458,6 +2458,5 @@ lenum.within = Check if unit is near a position.
|
||||
lenum.boost = Start/stop boosting.
|
||||
|
||||
lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nSecond and third arguments are additional suffixes added using "-" separator.\nIf additional arguments are not strings, nothing is added to first string.
|
||||
lenum.texturewidth = Width of texture in tiles. Zero value scales marker width to original texture's size.
|
||||
lenum.textureheight = Height of texture in tiles. Zero value scales marker height to original texture's size.
|
||||
lenum.texturesize = Size of texture in tiles. Zero value scales marker width to original texture's size.
|
||||
lenum.autoscale = Whether to scale marker corresponding to player's zoom level.
|
||||
|
||||
@@ -630,8 +630,9 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
public void added(){}
|
||||
/** Remove any UI elements, if necessary. */
|
||||
public void removed(){}
|
||||
/** Control marker with world processor code*/
|
||||
/** Control marker with world processor code. Ignores NaN (null) values. */
|
||||
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||
if(Double.isNaN(p1)) return;
|
||||
switch(type){
|
||||
case visibility -> hidden = Mathf.equal((float)p1, 0f);
|
||||
case drawLayer -> drawLayer = (float)p1;
|
||||
@@ -757,24 +758,41 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
|
||||
@Override
|
||||
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||
if(!Double.isNaN(p1)){
|
||||
switch(type){
|
||||
case x -> pos.x = (float)p1 * tilesize;
|
||||
case y -> pos.y = (float)p1 * tilesize;
|
||||
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
|
||||
case pos -> pos.x = (float)p1 * tilesize;
|
||||
case fontSize -> fontSize = (float)p1;
|
||||
case textHeight -> textHeight = (float)p1;
|
||||
case labelFlags -> {
|
||||
flags = (!Mathf.equal((float)p1, 0f) ? WorldLabel.flagBackground : 0);
|
||||
if(!Mathf.equal((float)p2, 0f)) flags |= WorldLabel.flagOutline;
|
||||
if(!Mathf.equal((float)p1, 0f)){
|
||||
flags |= WorldLabel.flagBackground;
|
||||
}else{
|
||||
flags &= ~WorldLabel.flagBackground;
|
||||
}
|
||||
}
|
||||
case radius -> radius = (float)p1;
|
||||
case rotation -> rotation = (float)p1;
|
||||
case shapeSides -> sides = (int)p1;
|
||||
case color -> color.set(Tmp.c1.fromDouble(p1));
|
||||
case shape -> sides = (int)p1;
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
if(!Double.isNaN(p2)){
|
||||
switch(type){
|
||||
case pos -> pos.y = (float)p2 * tilesize;
|
||||
case labelFlags -> {
|
||||
if(!Mathf.equal((float)p2, 0f)){
|
||||
flags |= WorldLabel.flagOutline;
|
||||
}else{
|
||||
flags &= ~WorldLabel.flagOutline;
|
||||
}
|
||||
}
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text, boolean fetch){
|
||||
this.text = text;
|
||||
@@ -828,16 +846,24 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
|
||||
@Override
|
||||
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||
if(!Double.isNaN(p1)){
|
||||
switch(type){
|
||||
case x -> pos.x = (int)p1;
|
||||
case y -> pos.y = (int)p1;
|
||||
case pos -> pos.set((int)p1, (int)p2);
|
||||
case pos -> pos.x = (int)p1;
|
||||
case radius -> radius = (float)p1;
|
||||
case stroke -> stroke = (float)p1;
|
||||
case color -> color.set(Tmp.c1.fromDouble(p1));
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
if(!Double.isNaN(p2)){
|
||||
if(type == LMarkerControl.pos){
|
||||
pos.y = (int)p2;
|
||||
}else{
|
||||
super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Displays a shape with an outline and color. */
|
||||
@@ -916,25 +942,34 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
|
||||
@Override
|
||||
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||
if(!Double.isNaN(p1)){
|
||||
switch(type){
|
||||
case x -> pos.x = (float)p1 * tilesize;
|
||||
case y -> pos.y = (float)p1 * tilesize;
|
||||
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
|
||||
case pos -> pos.x = (float)p1 * tilesize;
|
||||
case radius -> radius = (float)p1;
|
||||
case rotation -> rotation = (float)p1;
|
||||
case stroke -> stroke = (float)p1;
|
||||
case shapeSides -> sides = (int)p1;
|
||||
case shapeFill -> fill = !Mathf.equal((float)p1, 0f);
|
||||
case shapeOutline -> outline = !Mathf.equal((float)p1, 0f);
|
||||
case shape -> {
|
||||
sides = (int)p1;
|
||||
fill = !Mathf.equal((float)p2, 0f);
|
||||
outline = !Mathf.equal((float)p3, 0f);
|
||||
}
|
||||
case rotation -> rotation = (float)p1;
|
||||
case color -> color.set(Tmp.c1.fromDouble(p1));
|
||||
case shape -> sides = (int)p1;
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
if(!Double.isNaN(p2)){
|
||||
switch(type){
|
||||
case pos -> pos.y = (float)p2 * tilesize;
|
||||
case shape -> fill = !Mathf.equal((float)p2, 0f);
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
if(!Double.isNaN(p3)){
|
||||
if(type == LMarkerControl.shape){
|
||||
outline = !Mathf.equal((float)p3, 0f);
|
||||
}else{
|
||||
super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Displays text at a location. */
|
||||
@@ -994,19 +1029,36 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
|
||||
@Override
|
||||
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||
if(!Double.isNaN(p1)){
|
||||
switch(type){
|
||||
case x -> pos.x = (float)p1 * tilesize;
|
||||
case y -> pos.y = (float)p1 * tilesize;
|
||||
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
|
||||
case pos -> pos.x = (float)p1 * tilesize;
|
||||
case fontSize -> fontSize = (float)p1;
|
||||
case labelFlags -> {
|
||||
flags = (!Mathf.equal((float)p1, 0f) ? WorldLabel.flagBackground : 0);
|
||||
if(!Mathf.equal((float)p2, 0f)) flags |= WorldLabel.flagOutline;
|
||||
if(!Mathf.equal((float)p1, 0f)){
|
||||
flags |= WorldLabel.flagBackground;
|
||||
}else{
|
||||
flags &= ~WorldLabel.flagBackground;
|
||||
}
|
||||
}
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
if(!Double.isNaN(p2)){
|
||||
switch(type){
|
||||
case pos -> pos.y = (float)p2 * tilesize;
|
||||
case labelFlags -> {
|
||||
if(!Mathf.equal((float)p2, 0f)){
|
||||
flags |= WorldLabel.flagOutline;
|
||||
}else{
|
||||
flags &= ~WorldLabel.flagOutline;
|
||||
}
|
||||
}
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text, boolean fetch){
|
||||
this.text = text;
|
||||
@@ -1073,19 +1125,24 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
|
||||
@Override
|
||||
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||
if(!Double.isNaN(p1)){
|
||||
switch(type){
|
||||
case x -> pos1.x = (float)p1 * tilesize;
|
||||
case y -> pos1.y = (float)p1 * tilesize;
|
||||
case pos -> pos1.set((float)p1 * tilesize, (float)p2 * tilesize);
|
||||
case endX -> pos2.x = (float)p1 * tilesize;
|
||||
case endY -> pos2.y = (float)p1 * tilesize;
|
||||
case endPos -> pos2.set((float)p1 * tilesize, (float)p2 * tilesize);
|
||||
case pos -> pos1.x = (float)p1 * tilesize;
|
||||
case endPos -> pos2.x = (float)p1 * tilesize;
|
||||
case stroke -> stroke = (float)p1;
|
||||
case shapeOutline -> outline = !Mathf.equal((float)p1, 0f);
|
||||
case color -> color.set(Tmp.c1.fromDouble(p1));
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
if(!Double.isNaN(p2)){
|
||||
switch(type){
|
||||
case pos -> pos1.y = (float)p2 * tilesize;
|
||||
case endPos -> pos2.y = (float)p2 * tilesize;
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Displays a texture with specified name. */
|
||||
@@ -1106,22 +1163,25 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
|
||||
@Override
|
||||
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||
if(!Double.isNaN(p1)){
|
||||
switch(type){
|
||||
case x -> pos.x = (float)p1 * tilesize;
|
||||
case y -> pos.y = (float)p1 * tilesize;
|
||||
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
|
||||
case pos -> pos.x = (float)p1 * tilesize;
|
||||
case rotation -> rotation = (float)p1;
|
||||
case textureWidth -> width = (float)p1 * tilesize;
|
||||
case textureHeight -> height = (float)p1 * tilesize;
|
||||
case textureSize -> {
|
||||
width = (float)p1 * tilesize;
|
||||
height = (float)p2 * tilesize;
|
||||
}
|
||||
case textureSize -> width = (float)p1 * tilesize;
|
||||
case color -> color.set(Tmp.c1.fromDouble(p1));
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
if(!Double.isNaN(p2)){
|
||||
switch(type){
|
||||
case pos -> pos.y = (float)p2 * tilesize;
|
||||
case textureSize -> height = (float)p2 * tilesize;
|
||||
default -> super.control(type, p1, p2, p3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
if(hidden || textureName.isEmpty() || minimap) return;
|
||||
|
||||
@@ -157,18 +157,29 @@ public class LExecutor{
|
||||
return v.isobj ? v.objval != null : Math.abs(v.numval) >= 0.00001;
|
||||
}
|
||||
|
||||
public double num(int index){
|
||||
@Nullable
|
||||
public double num(int index, boolean nullToNan){
|
||||
Var v = var(index);
|
||||
return v.isobj ? v.objval != null ? 1 : 0 : invalid(v.numval) ? 0 : v.numval;
|
||||
return v.isobj ? v.objval != null ? 1 : nullToNan ? Double.NaN : 0: invalid(v.numval) ? 0 : v.numval;
|
||||
}
|
||||
|
||||
public double num(int index){
|
||||
return num(index, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public float numf(int index, boolean nullToNan){
|
||||
Var v = var(index);
|
||||
return v.isobj ? v.objval != null ? 1 : nullToNan ? Float.NaN : 0: invalid(v.numval) ? 0 : (float)v.numval;
|
||||
}
|
||||
|
||||
public float numf(int index){
|
||||
Var v = var(index);
|
||||
return v.isobj ? v.objval != null ? 1 : 0 : invalid(v.numval) ? 0 : (float)v.numval;
|
||||
return numf(index, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public int numi(int index){
|
||||
return (int)num(index);
|
||||
return (int)num(index, true);
|
||||
}
|
||||
|
||||
public void setbool(int index, boolean value){
|
||||
@@ -584,7 +595,8 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
}
|
||||
default -> {}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -605,7 +617,8 @@ public class LExecutor{
|
||||
this.p4 = p4;
|
||||
}
|
||||
|
||||
ControlI(){}
|
||||
ControlI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
@@ -852,7 +865,8 @@ public class LExecutor{
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
SetI(){}
|
||||
SetI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
@@ -884,7 +898,8 @@ public class LExecutor{
|
||||
this.dest = dest;
|
||||
}
|
||||
|
||||
OpI(){}
|
||||
OpI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
@@ -919,7 +934,8 @@ public class LExecutor{
|
||||
|
||||
public static class NoopI implements LInstruction{
|
||||
@Override
|
||||
public void run(LExecutor exec){}
|
||||
public void run(LExecutor exec){
|
||||
}
|
||||
}
|
||||
|
||||
public static class DrawI implements LInstruction{
|
||||
@@ -1061,7 +1077,8 @@ public class LExecutor{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
PrintI(){}
|
||||
PrintI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
@@ -1904,7 +1921,7 @@ public class LExecutor{
|
||||
}
|
||||
|
||||
public static class SetMarkerI implements LInstruction{
|
||||
public LMarkerControl type = LMarkerControl.x;
|
||||
public LMarkerControl type = LMarkerControl.pos;
|
||||
public int id, p1, p2, p3;
|
||||
|
||||
public SetMarkerI(LMarkerControl type, int id, int p1, int p2, int p3){
|
||||
@@ -1939,7 +1956,7 @@ public class LExecutor{
|
||||
marker.setTexture(res.toString());
|
||||
}
|
||||
}else{
|
||||
marker.control(type, exec.num(p1), exec.num(p2), exec.num(p3));
|
||||
marker.control(type, exec.num(p1, true), exec.num(p2, true), exec.num(p3, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1971,7 +1988,7 @@ public class LExecutor{
|
||||
int mid = exec.numi(id);
|
||||
if(exec.bool(replace) || !state.markers.containsKey(mid)){
|
||||
var marker = cons.get();
|
||||
marker.control(LMarkerControl.pos, exec.num(x), exec.num(y), 0);
|
||||
marker.control(LMarkerControl.pos, exec.num(x, true), exec.num(y, true), 0);
|
||||
state.markers.put(mid, marker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,20 +5,13 @@ public enum LMarkerControl{
|
||||
visibility("true/false"),
|
||||
minimap("true/false"),
|
||||
autoscale("true/false"),
|
||||
x("x"),
|
||||
y("y"),
|
||||
pos("x", "y"),
|
||||
endX("x"),
|
||||
endY("y"),
|
||||
endPos("x", "y"),
|
||||
drawLayer("layer"),
|
||||
color("color"),
|
||||
radius("radius"),
|
||||
stroke("stroke"),
|
||||
rotation("rotation"),
|
||||
shapeSides("sides"),
|
||||
shapeFill("true/false"),
|
||||
shapeOutline("true/false"),
|
||||
shape("sides", "fill", "outline"),
|
||||
text("text"),
|
||||
flushText,
|
||||
@@ -26,8 +19,6 @@ public enum LMarkerControl{
|
||||
textHeight("height"),
|
||||
labelFlags("background", "outline"),
|
||||
texture("name", "-", "-"),
|
||||
textureWidth("width"),
|
||||
textureHeight("height"),
|
||||
textureSize("width", "height");
|
||||
|
||||
public final String[] params;
|
||||
|
||||
@@ -1945,7 +1945,7 @@ public class LStatements{
|
||||
|
||||
@RegisterStatement("setmarker")
|
||||
public static class SetMarkerStatement extends LStatement{
|
||||
public LMarkerControl type = LMarkerControl.x;
|
||||
public LMarkerControl type = LMarkerControl.pos;
|
||||
public String id = "0", p1 = "0", p2 = "0", p3 = "0";
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user