Partial 7.0 merge - API preview

This commit is contained in:
Anuken
2021-06-02 11:08:08 -04:00
parent ea75a357ca
commit 28b235ef07
531 changed files with 12356 additions and 6286 deletions

View File

@@ -21,6 +21,7 @@ public enum LAccess{
maxHealth,
heat,
efficiency,
progress,
timescale,
rotation,
x,
@@ -42,7 +43,6 @@ public enum LAccess{
controller,
commanded,
name,
config,
payloadCount,
payloadType,
@@ -50,7 +50,7 @@ public enum LAccess{
enabled("to"), //"to" is standard for single parameter access
shoot("x", "y", "shoot"),
shootp(true, "unit", "shoot"),
configure(true, "to"),
config(true, "to"),
color("r", "g", "b");
public final String[] params;

View File

@@ -541,7 +541,7 @@ public class LExecutor{
public void run(LExecutor exec){
Object obj = exec.obj(target);
if(obj instanceof Building b && b.team == exec.team && exec.linkIds.contains(b.id)){
if(type.isObj){
if(type.isObj && exec.var(p1).isobj){ //TODO may break logic?
b.control(type, exec.obj(p1), exec.num(p2), exec.num(p3), exec.num(p4));
}else{
b.control(type, exec.num(p1), exec.num(p2), exec.num(p3), exec.num(p4));
@@ -867,7 +867,7 @@ public class LExecutor{
}
static int packSign(int value){
return (Math.abs(value) & 0b011111111) | (value < 0 ? 0b1000000000 : 0);
return (Math.abs(value) & 0b0111111111) | (value < 0 ? 0b1000000000 : 0);
}
}

View File

@@ -43,7 +43,7 @@ public class LParser{
String string(){
int from = pos;
while(pos++ < chars.length){
while(++pos < chars.length){
var c = chars[pos];
if(c == '\n'){
error("Missing closing quote \" before end of line.");
@@ -52,7 +52,7 @@ public class LParser{
}
}
if(chars[pos] != '"') error("Missing closing quote \" before end of file.");
if(pos >= chars.length || chars[pos] != '"') error("Missing closing quote \" before end of file.");
return new String(chars, from, ++pos - from);
}
@@ -128,6 +128,11 @@ public class LParser{
tokens[1] = "-1";
}
for(int i = 1; i < tok; i++){
if(tokens[i].equals("@configure")) tokens[i] = "@config";
if(tokens[i].equals("configure")) tokens[i] = "config";
}
LStatement st;
try{
@@ -165,7 +170,7 @@ public class LParser{
while(pos < chars.length && line < LExecutor.maxInstructions){
switch(chars[pos]){
case '\n', ' ' -> pos ++; //skip newlines and spaces
case '\n', ';', ' ' -> pos ++; //skip newlines and spaces
case '\r' -> pos += 2; //skip the newline after the \r
default -> statement();
}

View File

@@ -45,8 +45,47 @@ public abstract class LStatement{
tooltip(label, text);
}
protected String sanitize(String value){
if(value.length() == 0){
return "";
}else if(value.length() == 1){
if(value.charAt(0) == '"' || value.charAt(0) == ';' || value.charAt(0) == ' '){
return "invalid";
}
}else{
StringBuilder res = new StringBuilder(value.length());
if(value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"'){
res.append('\"');
//strip out extra quotes
for(int i = 1; i < value.length() - 1; i++){
if(value.charAt(i) == '"'){
res.append('\'');
}else{
res.append(value.charAt(i));
}
}
res.append('\"');
}else{
//otherwise, strip out semicolons, spaces and quotes
for(int i = 0; i < value.length(); i++){
char c = value.charAt(i);
res.append(switch(c){
case ';' -> 's';
case '"' -> '\'';
case ' ' -> '_';
default -> c;
});
}
}
return res.toString();
}
return value;
}
protected Cell<TextField> field(Table table, String value, Cons<String> setter){
return table.field(value, Styles.nodeField, setter)
return table.field(value, Styles.nodeField, s -> setter.get(sanitize(s)))
.size(144f, 40f).pad(2f).color(table.color).maxTextLength(LAssembler.maxTokenLength).addInputDialog();
}
@@ -144,7 +183,7 @@ public abstract class LStatement{
public void afterRead(){}
public void write(StringBuilder builder){
LogicIO.write(this,builder);
LogicIO.write(this, builder);
}
public void setupUI(){

View File

@@ -15,6 +15,7 @@ import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
import static mindustry.logic.LCanvas.*;
import static mindustry.world.blocks.logic.LogicDisplay.*;
@@ -484,7 +485,7 @@ public class LStatements{
int c = 0;
for(Item item : Vars.content.items()){
if(!item.unlockedNow()) continue;
i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> {
i.button(new TextureRegionDrawable(item.uiIcon), Styles.cleari, iconSmall, () -> {
stype("@" + item.name);
hide.run();
}).size(40f);
@@ -498,7 +499,7 @@ public class LStatements{
int c = 0;
for(Liquid item : Vars.content.liquids()){
if(!item.unlockedNow()) continue;
i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> {
i.button(new TextureRegionDrawable(item.uiIcon), Styles.cleari, iconSmall, () -> {
stype("@" + item.name);
hide.run();
}).size(40f);
@@ -785,11 +786,11 @@ public class LStatements{
int c = 0;
for(UnitType item : Vars.content.units()){
if(!item.unlockedNow() || item.isHidden()) continue;
i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> {
i.button(new TextureRegionDrawable(item.uiIcon), Styles.cleari, iconSmall, () -> {
type = "@" + item.name;
field.setText(type);
hide.run();
}).size(40f).get().resizeImage(Cicon.small.size);
}).size(40f);
if(++c % 6 == 0) i.row();
}
@@ -948,11 +949,11 @@ public class LStatements{
int c = 0;
for(Item item : Vars.content.items()){
if(!item.unlockedNow()) continue;
i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> {
i.button(new TextureRegionDrawable(item.uiIcon), Styles.cleari, iconSmall, () -> {
ore = "@" + item.name;
rebuild(table);
hide.run();
}).size(40f).get().resizeImage(Cicon.small.size);
}).size(40f);
if(++c % 6 == 0) i.row();
}