Skip to content

Commit d6eea07

Browse files
committed
Release 0.2.0
1 parent f3b054e commit d6eea07

File tree

7 files changed

+185
-159
lines changed

7 files changed

+185
-159
lines changed

mod.hjson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ main: "cardillan.mlogassertions.Main"
1616
description: "Provides custom mlog instructions for enhanced runtime checks in Mindustry Logic."
1717

1818
#the mod version
19-
version: 0.1
19+
version: 0.2.0
2020

2121
#the minimum game build required to run this mod
2222
minGameVersion: 146

src/cardillan/mlogassertions/logic/AssertLStatements.java

Lines changed: 0 additions & 125 deletions
This file was deleted.

src/cardillan/mlogassertions/logic/AssertLogic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public class AssertLogic {
1111
public static void init(){
1212
assertsCategory = new LCategory(AssertVars.assertionsCategory, Color.slate, Icon.warningSmall);
1313

14-
AssertLStatements.register();
14+
LogicStatements.register();
1515
}
1616
}

src/cardillan/mlogassertions/logic/TypeAssertion.java renamed to src/cardillan/mlogassertions/logic/AssertionType.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
package cardillan.mlogassertions.logic;
22

3-
import mindustry.logic.ConditionOp;
4-
53
import java.util.Objects;
64

7-
public enum TypeAssertion {
5+
public enum AssertionType {
86
any(num -> true, obj -> true),
97
notNull(num -> true, Objects::nonNull),
108
decimal(num -> true),
119
integer(num -> num == (long) num),
12-
even(num -> num == (long) num && num % 2 == 0),
13-
odd(num -> num == (long) num && num % 2 != 0),
10+
multiple(num -> num == (long) num),
1411
;
1512

16-
public static final TypeAssertion[] all = values();
13+
public static final AssertionType[] all = values();
1714
public final TypeAssertionObjLambda objFunction;
1815
public final TypeAssertionLambda function;
1916

20-
TypeAssertion(TypeAssertionLambda function) {
17+
AssertionType(TypeAssertionLambda function) {
2118
this(function, obj -> false);
2219
}
2320

24-
TypeAssertion(TypeAssertionLambda function, TypeAssertionObjLambda objFunction) {
21+
AssertionType(TypeAssertionLambda function, TypeAssertionObjLambda objFunction) {
2522
this.function = function;
2623
this.objFunction = objFunction;
2724
}

src/cardillan/mlogassertions/logic/AssertsLInstructions.java renamed to src/cardillan/mlogassertions/logic/LogicInstructions.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
import mindustry.logic.LExecutor.Var;
77
import mindustry.world.blocks.logic.LogicBlock;
88

9-
public class AssertsLInstructions {
9+
public class LogicInstructions {
1010

1111
public static class AssertI implements LExecutor.LInstruction {
12-
public TypeAssertion type = TypeAssertion.any;
12+
public AssertionType type = AssertionType.any;
13+
public int multiple = 1;
1314
public int min;
1415
public AssertOp opMin = AssertOp.lessThanEq;
1516
public int value;
1617
public AssertOp opMax = AssertOp.lessThanEq;
1718
public int max;
1819
public int message;
1920

20-
public AssertI(TypeAssertion type, int min, AssertOp opMin, int value, AssertOp opMax, int max, int message) {
21+
public AssertI(AssertionType type, int multiple, int min, AssertOp opMin, int value, AssertOp opMax, int max, int message) {
2122
this.type = type;
23+
this.multiple = multiple;
2224
this.min = min;
2325
this.opMin = opMin;
2426
this.value = value;
@@ -35,19 +37,18 @@ public final void run(LExecutor exec) {
3537
Building building = exec.building( LExecutor.varThis);
3638

3739
Var vaVal = var(exec, value);
38-
boolean typeAssert = vaVal.isobj ? type.objFunction.get(vaVal.objval) : type.function.get(vaVal.numval);
39-
boolean minAssert = opMin.function.get(num(exec,min), num(exec,value));
40-
boolean maxAssert = opMax.function.get(num(exec,value), num(exec,max));
41-
42-
if (!typeAssert || !minAssert || !maxAssert) {
40+
if ((vaVal.isobj ? type.objFunction.get(vaVal.objval) : type.function.get(vaVal.numval))
41+
&& (type != AssertionType.multiple || (vaVal.numval % var(exec, multiple).numval == 0))
42+
&& (opMin.function.get(num(exec,min), num(exec,value)))
43+
&& (opMax.function.get(num(exec,value), num(exec,max)))) {
44+
Assertions.remove((LogicBlock.LogicBuild) building);
45+
} else {
4346
Var message = var(exec, this.message);
4447
Assertions.add((LogicBlock.LogicBuild) building, LExecutor.PrintI.toString(message.objval));
4548

4649
//skip back to self.
4750
exec.counter.numval--;
4851
//exec.yield = true;
49-
} else {
50-
Assertions.remove((LogicBlock.LogicBuild) building);
5152
}
5253
}
5354

src/cardillan/mlogassertions/logic/AssertLStatementWriter.java renamed to src/cardillan/mlogassertions/logic/LogicStatementWriter.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cardillan.mlogassertions.logic;
22

3-
public class AssertLStatementWriter {
3+
public class LogicStatementWriter {
44
public static final String SEPARATOR = " ";
55

66
private StringBuilder builder;
@@ -14,66 +14,66 @@ public void end(){
1414
builder.deleteCharAt(builder.length() - 1);
1515
}
1616

17-
public AssertLStatementWriter write(Object obj) {
17+
public LogicStatementWriter write(Object obj) {
1818
return write(String.valueOf(obj)).write(SEPARATOR);
1919
}
2020

21-
public AssertLStatementWriter write(String str) {
21+
public LogicStatementWriter write(String str) {
2222
builder.append(str).append(SEPARATOR);
2323
return this;
2424
}
2525

26-
public AssertLStatementWriter write(StringBuffer sb) {
26+
public LogicStatementWriter write(StringBuffer sb) {
2727
builder.append(sb).append(SEPARATOR);
2828
return this;
2929
}
3030

31-
public AssertLStatementWriter write(CharSequence s) {
31+
public LogicStatementWriter write(CharSequence s) {
3232
builder.append(s).append(SEPARATOR);
3333
return this;
3434
}
3535

36-
public AssertLStatementWriter write(CharSequence s, int start, int end) {
36+
public LogicStatementWriter write(CharSequence s, int start, int end) {
3737
builder.append(s, start, end).append(SEPARATOR);
3838
return this;
3939
}
4040

41-
public AssertLStatementWriter write(char[] str) {
41+
public LogicStatementWriter write(char[] str) {
4242
builder.append(str).append(SEPARATOR);
4343
return this;
4444
}
4545

46-
public AssertLStatementWriter write(char[] str, int offset, int len) {
46+
public LogicStatementWriter write(char[] str, int offset, int len) {
4747
builder.append(str, offset, len).append(SEPARATOR);
4848
return this;
4949
}
5050

51-
public AssertLStatementWriter write(boolean b) {
51+
public LogicStatementWriter write(boolean b) {
5252
builder.append(b).append(SEPARATOR);
5353
return this;
5454
}
5555

56-
public AssertLStatementWriter write(char c) {
56+
public LogicStatementWriter write(char c) {
5757
builder.append(c).append(SEPARATOR);
5858
return this;
5959
}
6060

61-
public AssertLStatementWriter write(int i) {
61+
public LogicStatementWriter write(int i) {
6262
builder.append(i).append(SEPARATOR);
6363
return this;
6464
}
6565

66-
public AssertLStatementWriter write(long lng) {
66+
public LogicStatementWriter write(long lng) {
6767
builder.append(lng).append(SEPARATOR);
6868
return this;
6969
}
7070

71-
public AssertLStatementWriter write(float f) {
71+
public LogicStatementWriter write(float f) {
7272
builder.append(f).append(SEPARATOR);
7373
return this;
7474
}
7575

76-
public AssertLStatementWriter write(double d) {
76+
public LogicStatementWriter write(double d) {
7777
builder.append(d).append(SEPARATOR);
7878
return this;
7979
}

0 commit comments

Comments
 (0)