Logic rule instruction / Lock erekir proc sectors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package mindustry.logic;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
@@ -99,10 +100,20 @@ public class LAssembler{
|
||||
//parse hex/binary syntax
|
||||
if(symbol.startsWith("0b")) return Strings.parseLong(symbol, 2, 2, symbol.length(), invalidNum);
|
||||
if(symbol.startsWith("0x")) return Strings.parseLong(symbol, 16, 2, symbol.length(), invalidNum);
|
||||
if(symbol.startsWith("%") && (symbol.length() == 7 || symbol.length() == 9)) return parseColor(symbol);
|
||||
|
||||
return Strings.parseDouble(symbol, invalidNum);
|
||||
}
|
||||
|
||||
double parseColor(String symbol){
|
||||
int
|
||||
r = Strings.parseInt(symbol, 16, 0, 1, 3),
|
||||
g = Strings.parseInt(symbol, 16, 0, 3, 5),
|
||||
b = Strings.parseInt(symbol, 16, 0, 5, 7),
|
||||
a = symbol.length() == 9 ? Strings.parseInt(symbol, 16, 0, 7, 9) : 255;
|
||||
return Color.toDoubleBits(r, g, b, a);
|
||||
}
|
||||
|
||||
/** Adds a constant value by name. */
|
||||
public BVar putConst(String name, Object value){
|
||||
BVar var = putVar(name);
|
||||
|
||||
@@ -1187,5 +1187,33 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class SetRuleI implements LInstruction{
|
||||
public LogicRule rule = LogicRule.waveSpacing;
|
||||
public int value;
|
||||
|
||||
public SetRuleI(LogicRule rule, int value){
|
||||
this.rule = rule;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public SetRuleI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
switch(rule){
|
||||
case waveTimer -> state.rules.waveTimer = exec.bool(value);
|
||||
case waves -> state.rules.waves = exec.bool(value);
|
||||
case attackMode -> state.rules.attackMode = exec.bool(value);
|
||||
case waveSpacing -> state.rules.waveSpacing = exec.numf(value) * 60f;
|
||||
case enemyCoreBuildRadius -> state.rules.enemyCoreBuildRadius = exec.numf(value) * 8f;
|
||||
case dropZoneRadius -> state.rules.dropZoneRadius = exec.numf(value) * 8f;
|
||||
case unitCap -> state.rules.unitCap = exec.numi(value);
|
||||
case lighting -> state.rules.lighting = exec.bool(value);
|
||||
case ambientLight -> state.rules.ambientLight.fromDouble(exec.num(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.graphics.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.ctype.*;
|
||||
@@ -1205,4 +1206,37 @@ public class LStatements{
|
||||
return new SpawnUnitI(builder.var(type), builder.var(x), builder.var(y), builder.var(rotation), builder.var(team), effect, builder.var(result));
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("setrule")
|
||||
public static class SetRuleStatement extends LStatement{
|
||||
public LogicRule rule = LogicRule.waveSpacing;
|
||||
public String value = "100";
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
table.button(b -> {
|
||||
b.label(() -> rule.name()).growX().wrap().labelAlign(Align.center);
|
||||
b.clicked(() -> showSelect(b, LogicRule.all, rule, o -> rule = o, 2, c -> c.width(150f)));
|
||||
}, Styles.logict, () -> {}).size(150f, 40f).pad(4f).color(table.color);
|
||||
|
||||
table.add(" = ");
|
||||
|
||||
field(table, value, s -> value = s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean privileged(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color color(){
|
||||
return Pal.logicWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new SetRuleI(rule, builder.var(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
core/src/mindustry/logic/LogicRule.java
Normal file
15
core/src/mindustry/logic/LogicRule.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package mindustry.logic;
|
||||
|
||||
public enum LogicRule{
|
||||
waveTimer,
|
||||
waves,
|
||||
waveSpacing,
|
||||
attackMode,
|
||||
enemyCoreBuildRadius,
|
||||
dropZoneRadius,
|
||||
unitCap,
|
||||
lighting,
|
||||
ambientLight;
|
||||
|
||||
public static final LogicRule[] all = values();
|
||||
}
|
||||
Reference in New Issue
Block a user