diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 2f9f520307..a2098265a6 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2488,6 +2488,7 @@ lst.explosion = Create an explosion at a location. lst.setrate = Set processor execution speed in instructions/tick. lst.fetch = Lookup units, cores, players or buildings by index.\nIndices start at 0 and end at their returned count. lst.packcolor = Pack [0, 1] RGBA components into a single number for drawing or rule-setting. +lst.unpackcolor = Unpack RGBA components from a color that was packed using Pack Color. lst.setrule = Set a game rule. lst.flushmessage = Display a message on the screen from the text buffer.\nIf the success result variable is [accent]@wait[],\nwill wait until the previous message finishes.\nOtherwise, outputs whether displaying the message succeeded. lst.cutscene = Manipulate the player camera. diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 3b505c20f7..043dcc9f7c 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -1216,8 +1216,7 @@ public class LExecutor{ this.a = a; } - public PackColorI(){ - } + public PackColorI(){} @Override public void run(LExecutor exec){ @@ -1225,6 +1224,29 @@ public class LExecutor{ } } + public static class UnpackColorI implements LInstruction{ + public LVar r, g, b, a, value; + + public UnpackColorI(LVar r, LVar g, LVar b, LVar a, LVar value){ + this.r = r; + this.g = g; + this.b = b; + this.a = a; + this.value = value; + } + + public UnpackColorI(){} + + @Override + public void run(LExecutor exec){ + var color = Tmp.c1.fromDouble(value.num()); + r.setnum(color.r); + g.setnum(color.g); + b.setnum(color.b); + a.setnum(color.a); + } + } + public static class CutsceneI implements LInstruction{ public CutsceneAction action = CutsceneAction.stop; public LVar p1, p2, p3, p4; diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index 4a61bb70c0..827d561715 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -897,6 +897,35 @@ public class LStatements{ } } + @RegisterStatement("unpackcolor") + public static class UnpackColorStatement extends LStatement{ + public String r = "r", g = "g", b = "b", a = "a", value = "color"; + + @Override + public void build(Table 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); + + row(table); + + table.add(" = unpack "); + + fields(table, value, str -> value = str); + } + + @Override + public LInstruction build(LAssembler builder){ + return new UnpackColorI(builder.var(r), builder.var(g), builder.var(b), builder.var(a), builder.var(value)); + } + + @Override + public LCategory category(){ + return LCategory.operation; + } + } + @RegisterStatement("end") public static class EndStatement extends LStatement{ @Override