Merge remote-tracking branch 'upstream/master'
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, varClient, varClientLocale, varClientUnit, varClientName, varClientTeam;
|
||||
private static int varTime, varTick, varSecond, varMinute, varWave, varWaveTime, varServer, varClient, varClientLocale, varClientUnit, varClientName, varClientTeam, varClientMobile;
|
||||
|
||||
private ObjectIntMap<String> namesToIds = new ObjectIntMap<>();
|
||||
private Seq<Var> vars = new Seq<>(Var.class);
|
||||
@@ -65,6 +65,7 @@ public class GlobalVars{
|
||||
varClientUnit = put("@clientUnit", null, true);
|
||||
varClientName = put("@clientName", null, true);
|
||||
varClientTeam = put("@clientTeam", 0, true);
|
||||
varClientMobile = put("@clientMobile", 0, true);
|
||||
|
||||
//special enums
|
||||
put("@ctrlProcessor", ctrlProcessor);
|
||||
@@ -168,6 +169,7 @@ public class GlobalVars{
|
||||
vars.items[varClientUnit].objval = player.unit();
|
||||
vars.items[varClientName].objval = player.name();
|
||||
vars.items[varClientTeam].numval = player.team().id;
|
||||
vars.items[varClientMobile].numval = mobile ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,14 +185,18 @@ public class GlobalVars{
|
||||
return arr != null && content.id >= 0 && content.id < arr.length ? arr[content.id] : -1;
|
||||
}
|
||||
|
||||
/** @return a constant ID > 0 if there is a constant with this name, otherwise -1.
|
||||
* Attempt to get privileged variable id from non-privileged logic executor returns null constant id. */
|
||||
/**
|
||||
* @return a constant ID > 0 if there is a constant with this name, otherwise -1.
|
||||
* Attempt to get privileged variable id from non-privileged logic executor returns null constant id.
|
||||
*/
|
||||
public int get(String name){
|
||||
return namesToIds.get(name, -1);
|
||||
}
|
||||
|
||||
/** @return a constant variable by ID. ID is not bound checked and must be positive.
|
||||
* Attempt to get privileged variable from non-privileged logic executor returns null constant */
|
||||
/**
|
||||
* @return a constant variable by ID. ID is not bound checked and must be positive.
|
||||
* Attempt to get privileged variable from non-privileged logic executor returns null constant
|
||||
*/
|
||||
public Var get(int id, boolean privileged){
|
||||
if(!privileged && privilegedIds.contains(id)) return vars.get(namesToIds.get("null"));
|
||||
return vars.items[id];
|
||||
|
||||
@@ -1116,6 +1116,55 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class FormatI implements LInstruction{
|
||||
public int value;
|
||||
|
||||
public FormatI(int value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
FormatI(){}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
|
||||
if(exec.textBuffer.length() >= maxTextBuffer) return;
|
||||
|
||||
int placeholderIndex = -1;
|
||||
int placeholderNumber = 10;
|
||||
|
||||
for(int i = 0; i < exec.textBuffer.length(); i++){
|
||||
if(exec.textBuffer.charAt(i) == '{' && exec.textBuffer.length() - i > 2){
|
||||
char numChar = exec.textBuffer.charAt(i + 1);
|
||||
|
||||
if(numChar >= '0' && numChar <= '9' && exec.textBuffer.charAt(i + 2) == '}'){
|
||||
if(numChar - '0' < placeholderNumber){
|
||||
placeholderNumber = numChar - '0';
|
||||
placeholderIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(placeholderIndex == -1) return;
|
||||
|
||||
//this should avoid any garbage allocation
|
||||
Var v = exec.var(value);
|
||||
if(v.isobj && value != 0){
|
||||
String strValue = PrintI.toString(v.objval);
|
||||
|
||||
exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, strValue);
|
||||
}else{
|
||||
//display integer version when possible
|
||||
if(Math.abs(v.numval - (long)v.numval) < 0.00001){
|
||||
exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, (long)v.numval + "");
|
||||
}else{
|
||||
exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, v.numval + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PrintFlushI implements LInstruction{
|
||||
public int target;
|
||||
|
||||
@@ -2028,5 +2077,39 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class LocalePrintI implements LInstruction{
|
||||
public int name;
|
||||
|
||||
public LocalePrintI(int name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public LocalePrintI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
if(exec.textBuffer.length() >= maxTextBuffer) return;
|
||||
|
||||
//this should avoid any garbage allocation
|
||||
Var v = exec.var(name);
|
||||
if(v.isobj){
|
||||
String name = PrintI.toString(v.objval);
|
||||
|
||||
String strValue;
|
||||
|
||||
if(mobile){
|
||||
strValue = state.mapLocales.containsProperty(name + ".mobile") ?
|
||||
state.mapLocales.getProperty(name + ".mobile") :
|
||||
state.mapLocales.getProperty(name);
|
||||
}else{
|
||||
strValue = state.mapLocales.getProperty(name);
|
||||
}
|
||||
|
||||
exec.textBuffer.append(strValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class LStatements{
|
||||
}
|
||||
|
||||
if(type == GraphicsType.print){
|
||||
p2 = "bottomLeft";
|
||||
p1 = "bottomLeft";
|
||||
}
|
||||
|
||||
rebuild(table);
|
||||
@@ -305,6 +305,27 @@ public class LStatements{
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("format")
|
||||
public static class FormatStatement extends LStatement{
|
||||
public String value = "\"frog\"";
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
field(table, value, str -> value = str).width(0f).growX().padRight(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new FormatI(builder.var(value));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LCategory category(){
|
||||
return LCategory.io;
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("drawflush")
|
||||
public static class DrawFlushStatement extends LStatement{
|
||||
public String target = "display1";
|
||||
@@ -2071,4 +2092,29 @@ public class LStatements{
|
||||
return LCategory.world;
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("localeprint")
|
||||
public static class LocalePrintStatement extends LStatement{
|
||||
public String value = "\"name\"";
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
field(table, value, str -> value = str).width(0f).growX().padRight(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean privileged(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new LocalePrintI(builder.var(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LCategory category(){
|
||||
return LCategory.world;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user