mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-04 06:31:42 +07:00
Logic-related color functions
This commit is contained in:
parent
04c2bbc24d
commit
a80e1d86a1
@ -1704,6 +1704,11 @@ lst.unitbind = Bind to the next unit of a type, and store it in [accent]@unit[].
|
|||||||
lst.unitcontrol = Control the currently bound unit.
|
lst.unitcontrol = Control the currently bound unit.
|
||||||
lst.unitradar = Locate units around the currently bound unit.
|
lst.unitradar = Locate units around the currently bound unit.
|
||||||
lst.unitlocate = Locate a specific type of position/building anywhere on the map.\nRequires a bound unit.
|
lst.unitlocate = Locate a specific type of position/building anywhere on the map.\nRequires a bound unit.
|
||||||
|
lst.getblock = Get tile data at any location.
|
||||||
|
lst.setblock = Set tile data at any location.
|
||||||
|
lst.spawnunit = Spawn unit at a location.
|
||||||
|
lst.packcolor = Pack [0, 1] RGBA components into a single number for drawing or rule-setting.
|
||||||
|
lst.setrule = Set a game rule.
|
||||||
|
|
||||||
logic.nounitbuild = [red]Unit building logic is not allowed here.
|
logic.nounitbuild = [red]Unit building logic is not allowed here.
|
||||||
|
|
||||||
@ -1723,6 +1728,7 @@ lacess.speed = Top speed of a unit, in tiles/sec.
|
|||||||
|
|
||||||
graphicstype.clear = Fill the display with a color.
|
graphicstype.clear = Fill the display with a color.
|
||||||
graphicstype.color = Set color for next drawing operations.
|
graphicstype.color = Set color for next drawing operations.
|
||||||
|
graphicstype.col = Equivalent to color, but packed.\nPacked colors are written as hex codes with a [accent]%[] prefix.\nExample: [accent]%ff0000[] would be red.
|
||||||
graphicstype.stroke = Set line width.
|
graphicstype.stroke = Set line width.
|
||||||
graphicstype.line = Draw line segment.
|
graphicstype.line = Draw line segment.
|
||||||
graphicstype.rect = Fill a rectangle.
|
graphicstype.rect = Fill a rectangle.
|
||||||
|
@ -52,7 +52,7 @@ public enum LAccess{
|
|||||||
shoot("x", "y", "shoot"),
|
shoot("x", "y", "shoot"),
|
||||||
shootp(true, "unit", "shoot"),
|
shootp(true, "unit", "shoot"),
|
||||||
config(true, "to"),
|
config(true, "to"),
|
||||||
color("r", "g", "b");
|
color("to");
|
||||||
|
|
||||||
public final String[] params;
|
public final String[] params;
|
||||||
public final boolean isObj;
|
public final boolean isObj;
|
||||||
|
@ -111,6 +111,7 @@ public class LAssembler{
|
|||||||
g = Strings.parseInt(symbol, 16, 0, 3, 5),
|
g = Strings.parseInt(symbol, 16, 0, 3, 5),
|
||||||
b = Strings.parseInt(symbol, 16, 0, 5, 7),
|
b = Strings.parseInt(symbol, 16, 0, 5, 7),
|
||||||
a = symbol.length() == 9 ? Strings.parseInt(symbol, 16, 0, 7, 9) : 255;
|
a = symbol.length() == 9 ? Strings.parseInt(symbol, 16, 0, 7, 9) : 255;
|
||||||
|
|
||||||
return Color.toDoubleBits(r, g, b, a);
|
return Color.toDoubleBits(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mindustry.logic;
|
package mindustry.logic;
|
||||||
|
|
||||||
|
import arc.graphics.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
@ -880,7 +881,7 @@ public class LExecutor{
|
|||||||
@Override
|
@Override
|
||||||
public void run(LExecutor exec){
|
public void run(LExecutor exec){
|
||||||
//graphics on headless servers are useless.
|
//graphics on headless servers are useless.
|
||||||
if(Vars.headless) return;
|
if(Vars.headless || exec.graphicsBuffer.size >= maxGraphicsBuffer) return;
|
||||||
|
|
||||||
int num1 = exec.numi(p1);
|
int num1 = exec.numi(p1);
|
||||||
|
|
||||||
@ -888,12 +889,27 @@ public class LExecutor{
|
|||||||
num1 = exec.obj(p1) instanceof UnlockableContent u ? u.iconId : 0;
|
num1 = exec.obj(p1) instanceof UnlockableContent u ? u.iconId : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//add graphics calls, cap graphics buffer size
|
//explicitly unpack colorPack, it's pre-processed here
|
||||||
if(exec.graphicsBuffer.size < maxGraphicsBuffer){
|
if(type == LogicDisplay.commandColorPack){
|
||||||
|
double packed = exec.num(x);
|
||||||
|
|
||||||
|
int value = (int)(Double.doubleToRawLongBits(packed)),
|
||||||
|
r = ((value & 0xff000000) >>> 24),
|
||||||
|
g = ((value & 0x00ff0000) >>> 16),
|
||||||
|
b = ((value & 0x0000ff00) >>> 8),
|
||||||
|
a = ((value & 0x000000ff));
|
||||||
|
|
||||||
|
exec.graphicsBuffer.add(DisplayCmd.get(LogicDisplay.commandColor, pack(r), pack(g), pack(b), pack(a), 0, 0));
|
||||||
|
}else{
|
||||||
|
//add graphics calls, cap graphics buffer size
|
||||||
exec.graphicsBuffer.add(DisplayCmd.get(type, packSign(exec.numi(x)), packSign(exec.numi(y)), packSign(num1), packSign(exec.numi(p2)), packSign(exec.numi(p3)), packSign(exec.numi(p4))));
|
exec.graphicsBuffer.add(DisplayCmd.get(type, packSign(exec.numi(x)), packSign(exec.numi(y)), packSign(num1), packSign(exec.numi(p2)), packSign(exec.numi(p3)), packSign(exec.numi(p4))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pack(int value){
|
||||||
|
return value & 0b0111111111;
|
||||||
|
}
|
||||||
|
|
||||||
static int packSign(int value){
|
static int packSign(int value){
|
||||||
return (Math.abs(value) & 0b0111111111) | (value < 0 ? 0b1000000000 : 0);
|
return (Math.abs(value) & 0b0111111111) | (value < 0 ? 0b1000000000 : 0);
|
||||||
}
|
}
|
||||||
@ -1061,7 +1077,7 @@ public class LExecutor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO lookup color instruction and inverse lookup
|
//TODO inverse lookup
|
||||||
public static class LookupI implements LInstruction{
|
public static class LookupI implements LInstruction{
|
||||||
public int dest;
|
public int dest;
|
||||||
public int from;
|
public int from;
|
||||||
@ -1082,6 +1098,26 @@ public class LExecutor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class PackColorI implements LInstruction{
|
||||||
|
public int result, r, g, b, a;
|
||||||
|
|
||||||
|
public PackColorI(int result, int r, int g, int b, int a){
|
||||||
|
this.result = result;
|
||||||
|
this.r = r;
|
||||||
|
this.g = g;
|
||||||
|
this.b = b;
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PackColorI(){
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(LExecutor exec){
|
||||||
|
exec.setnum(result, Color.toDoubleBits(Mathf.clamp(exec.numf(r)), Mathf.clamp(exec.numf(g)), Mathf.clamp(exec.numf(b)), Mathf.clamp(exec.numf(a))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
//region privileged / world instructions
|
//region privileged / world instructions
|
||||||
|
|
||||||
@ -1203,6 +1239,7 @@ public class LExecutor{
|
|||||||
public void run(LExecutor exec){
|
public void run(LExecutor exec){
|
||||||
switch(rule){
|
switch(rule){
|
||||||
case waveTimer -> state.rules.waveTimer = exec.bool(value);
|
case waveTimer -> state.rules.waveTimer = exec.bool(value);
|
||||||
|
case currentWaveTime -> state.wavetime = exec.numf(value) * 60f;
|
||||||
case waves -> state.rules.waves = exec.bool(value);
|
case waves -> state.rules.waves = exec.bool(value);
|
||||||
case attackMode -> state.rules.attackMode = exec.bool(value);
|
case attackMode -> state.rules.attackMode = exec.bool(value);
|
||||||
case waveSpacing -> state.rules.waveSpacing = exec.numf(value) * 60f;
|
case waveSpacing -> state.rules.waveSpacing = exec.numf(value) * 60f;
|
||||||
|
@ -180,6 +180,9 @@ public class LStatements{
|
|||||||
row(s);
|
row(s);
|
||||||
fields(s, "a", p2, v -> p2 = v);
|
fields(s, "a", p2, v -> p2 = v);
|
||||||
}
|
}
|
||||||
|
case col -> {
|
||||||
|
fields(s, "color", x, v -> x = v).width(144f);
|
||||||
|
}
|
||||||
case stroke -> {
|
case stroke -> {
|
||||||
s.add().width(4);
|
s.add().width(4);
|
||||||
fields(s, x, v -> x = v);
|
fields(s, x, v -> x = v);
|
||||||
@ -722,6 +725,35 @@ public class LStatements{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RegisterStatement("packcolor")
|
||||||
|
public static class PackColorStatement extends LStatement{
|
||||||
|
public String result = "result", r = "1", g = "0", b = "0", a = "1";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(Table table){
|
||||||
|
fields(table, result, str -> result = str);
|
||||||
|
|
||||||
|
table.add(" = pack ");
|
||||||
|
|
||||||
|
row(table);
|
||||||
|
|
||||||
|
fields(table, r, str -> r = str);
|
||||||
|
fields(table, g, str -> g = str);
|
||||||
|
fields(table, b, str -> b = str);
|
||||||
|
fields(table, a, str -> a = str);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Color color(){
|
||||||
|
return Pal.logicOperations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LInstruction build(LAssembler builder){
|
||||||
|
return new PackColorI(builder.var(result), builder.var(r), builder.var(g), builder.var(b), builder.var(a));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@RegisterStatement("end")
|
@RegisterStatement("end")
|
||||||
public static class EndStatement extends LStatement{
|
public static class EndStatement extends LStatement{
|
||||||
@Override
|
@Override
|
||||||
@ -1217,7 +1249,7 @@ public class LStatements{
|
|||||||
table.button(b -> {
|
table.button(b -> {
|
||||||
b.label(() -> rule.name()).growX().wrap().labelAlign(Align.center);
|
b.label(() -> rule.name()).growX().wrap().labelAlign(Align.center);
|
||||||
b.clicked(() -> showSelect(b, LogicRule.all, rule, o -> rule = o, 2, c -> c.width(150f)));
|
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);
|
}, Styles.logict, () -> {}).size(160f, 40f).pad(4f).color(table.color);
|
||||||
|
|
||||||
table.add(" = ");
|
table.add(" = ");
|
||||||
|
|
||||||
|
@ -166,8 +166,8 @@ public class LogicDialog extends BaseDialog{
|
|||||||
t.button(example.name(), style, () -> {
|
t.button(example.name(), style, () -> {
|
||||||
canvas.add(prov.get());
|
canvas.add(prov.get());
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
}).size(140f, 50f).self(c -> tooltip(c, "lst." + example.name()));
|
}).size(130f, 50f).self(c -> tooltip(c, "lst." + example.name()));
|
||||||
if(++i % 2 == 0) t.row();
|
if(++i % 3 == 0) t.row();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dialog.addCloseButton();
|
dialog.addCloseButton();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package mindustry.logic;
|
package mindustry.logic;
|
||||||
|
|
||||||
public enum LogicRule{
|
public enum LogicRule{
|
||||||
|
currentWaveTime,
|
||||||
waveTimer,
|
waveTimer,
|
||||||
waves,
|
waves,
|
||||||
waveSpacing,
|
waveSpacing,
|
||||||
|
@ -17,14 +17,16 @@ public class LogicDisplay extends Block{
|
|||||||
public static final byte
|
public static final byte
|
||||||
commandClear = 0,
|
commandClear = 0,
|
||||||
commandColor = 1,
|
commandColor = 1,
|
||||||
commandStroke = 2,
|
//virtual command, unpacked in instruction
|
||||||
commandLine = 3,
|
commandColorPack = 2,
|
||||||
commandRect = 4,
|
commandStroke = 3,
|
||||||
commandLineRect = 5,
|
commandLine = 4,
|
||||||
commandPoly = 6,
|
commandRect = 5,
|
||||||
commandLinePoly = 7,
|
commandLineRect = 6,
|
||||||
commandTriangle = 8,
|
commandPoly = 7,
|
||||||
commandImage = 9;
|
commandLinePoly = 8,
|
||||||
|
commandTriangle = 9,
|
||||||
|
commandImage = 10;
|
||||||
|
|
||||||
public int maxSides = 25;
|
public int maxSides = 25;
|
||||||
|
|
||||||
@ -125,6 +127,8 @@ public class LogicDisplay extends Block{
|
|||||||
public enum GraphicsType{
|
public enum GraphicsType{
|
||||||
clear,
|
clear,
|
||||||
color,
|
color,
|
||||||
|
//virtual
|
||||||
|
col,
|
||||||
stroke,
|
stroke,
|
||||||
line,
|
line,
|
||||||
rect,
|
rect,
|
||||||
@ -132,7 +136,7 @@ public class LogicDisplay extends Block{
|
|||||||
poly,
|
poly,
|
||||||
linePoly,
|
linePoly,
|
||||||
triangle,
|
triangle,
|
||||||
image;
|
image,;
|
||||||
|
|
||||||
public static final GraphicsType[] all = values();
|
public static final GraphicsType[] all = values();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public class LightBlock extends Block{
|
|||||||
@Override
|
@Override
|
||||||
public void control(LAccess type, double p1, double p2, double p3, double p4){
|
public void control(LAccess type, double p1, double p2, double p3, double p4){
|
||||||
if(type == LAccess.color){
|
if(type == LAccess.color){
|
||||||
color = Color.rgba8888(Mathf.clamp((float)p1), Mathf.clamp((float)p2), Mathf.clamp((float)p3), 1f);
|
color = Tmp.c1.fromDouble(p1).rgba8888();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.control(type, p1, p2, p3, p4);
|
super.control(type, p1, p2, p3, p4);
|
||||||
|
@ -24,4 +24,4 @@ android.useAndroidX=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
archash=a1e1841832
|
archash=f95111f269
|
||||||
|
Loading…
Reference in New Issue
Block a user